Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/vis15/src/tests/rtest/tests/heron/heron.diderot
ViewVC logotype

View of /branches/vis15/src/tests/rtest/tests/heron/heron.diderot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4497 - (download) (annotate)
Sat Sep 3 14:12:36 2016 UTC (2 years, 8 months ago) by jhr
File size: 1036 byte(s)
  working on merge: updating tests with new version 2 syntax
#version 2.0

/*! \file heron.diderot
 *
 * \author John Reppy
 * \author Gordon Kindlmann
 *
 * This example illustrates using Heron's method for computing square roots, originally
 * created by Gordon Kindlmann for the VIS'12 submission.  It serves as a test for
 * loading dynamic data sequences.
 */

/*
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2015 The University of Chicago
 * All rights reserved.
 */

input int{} args = load_sequence ("../../data/numbers.nrrd");
int nArgs = length(args);
real eps = 0.00001;

strand SqRoot (real arg)
{
    real root = arg;  // holds root approximation
    int iter = 0;
    output vec4 out = [0,0,0,0];	// value, root, iters, error

    start {
	if (arg <= 0) {
	    stabilize;
	}
    }

    update {
	iter += 1;
	root = (root + arg/root) / 2.0;
	if (|root^2 - arg| / arg < eps)
	    stabilize;
    }

    stabilize {
	out = [arg, root, iter, sqrt(arg)-root];
    }

}

create_collection { SqRoot(args{i}) | i in 0 .. nArgs-1 }

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0