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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4405 - (view) (download)

1 : jhr 4102 /*! \file heron.diderot
2 :     *
3 :     * \author John Reppy
4 :     * \author Gordon Kindlmann
5 :     *
6 :     * This example illustrates using Heron's method for computing square roots, originally
7 :     * created by Gordon Kindlmann for the VIS'12 submission. It serves as a test for
8 :     * loading dynamic data sequences.
9 :     */
10 :    
11 :     /*
12 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
13 :     *
14 :     * COPYRIGHT (c) 2015 The University of Chicago
15 :     * All rights reserved.
16 :     */
17 :    
18 :     input int{} args = load("../../data/numbers.nrrd");
19 :     int nArgs = length(args);
20 :     real eps = 0.00001;
21 :    
22 :     strand SqRoot (real arg)
23 :     {
24 : jhr 4405 real root = arg; // holds root approximation
25 :     int iter = 0;
26 :     output vec4 out = [0,0,0,0]; // value, root, iters, error
27 : jhr 4102
28 : jhr 4405 initially {
29 :     if (arg <= 0) {
30 :     stabilize;
31 :     }
32 :     }
33 :    
34 : jhr 4102 update {
35 : jhr 4405 iter += 1;
36 :     root = (root + arg/root) / 2.0;
37 :     if (|root^2 - arg| / arg < eps)
38 : jhr 4102 stabilize;
39 :     }
40 : jhr 4405
41 :     stabilize {
42 :     out = [arg, root, iter, sqrt(arg)-root];
43 :     }
44 :    
45 : jhr 4102 }
46 :    
47 :     collection { SqRoot(args{i}) | i in 0 .. nArgs-1 }

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