Home My Page Projects Code Snippets Project Openings diderot

# SCM Repository

[diderot] Diff of /branches/lamont/test/reduction/reduction-test.diderot
 [diderot] / branches / lamont / test / reduction / reduction-test.diderot

# Diff of /branches/lamont/test/reduction/reduction-test.diderot

revision 2288, Tue Mar 12 23:58:04 2013 UTC revision 2289, Wed Mar 13 00:37:12 2013 UTC
# Line 2  Line 2
2   *   *
3   * \author Lamont Samuels   * \author Lamont Samuels
4   *   *
5   * This example tests the global reductions operations.   * This example tests the global reductions.
6   */   */
7
8  /*  /*
9   * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
11   */   */
12  real{} numbers = load("numbers.nrrd");  int nNumbers = 10;
int nNumbers = length(numbers);
13  real gMean = 0;  real gMean = 0;
14  real gVar = 0;  real gVar = 0;
15  real steps = 1;  real steps = 1;
real gStdev = 0;
16  bool gAll = true;  bool gAll = true;
17  bool gExists = false;  bool gExists = false;
18  real gMin = ∞;  real gMin = ∞;
# Line 25  Line 23
23
24  strand Reduction (int i, real number) {  strand Reduction (int i, real number) {
25      real num = number;      real num = number;
26      output real out = 23.23;      output real out = 0.0;
27      int id = i;      int id = i;
28
29      update {      update {
out = gStdev;
30
31          if(id == 0 && steps == 34)          if(id == 1 && steps == 34)
32              new Reduction(nNumbers,25);              new Reduction(nNumbers,25);
33          if(id == 0 && steps == 15)          if(id == 1 && steps == 15)
34              new Reduction(nNumbers + 1, 34);              new Reduction(nNumbers + 1, 34);
35
36            if((id == 1 || id == 2) && steps == 15)
37                stabilize;
38
39          if(steps >= 50) {          if(steps >= 50) {
40              if(id == 2) {              //Lamont Note: Strands 1 & 2 have already stabilized so the gMean & gAll should be based only on strand's 1 && 2 values
41                  print("gMean = ", gMean, "\ngVar = ", gVar, "\ngStdev = ", gStdev,              if(id == 3) {
42                    print("gMean = ", gMean, "\ngVar = ", gVar,
43                        "\ngAll = ", gAll, "\ngExists =", gExists, "\ngProduct = ", gProduct,                        "\ngAll = ", gAll, "\ngExists =", gExists, "\ngProduct = ", gProduct,
44                        "\ngSum = ", gSum, "\ngMin = ", gMin, "\ngMax = ", gMax, "\n");                        "\ngSum = ", gSum, "\ngMin = ", gMin, "\ngMax = ", gMax, "\n");
45              }              }
# Line 49  Line 49
49  }  }
50
51  global {  global {
gMin = minr {S.num | S in Reduction.all};
gMax = maxr {S.num | S in Reduction.all};
52     gProduct = product{S.num | S in Reduction.all};     gProduct = product{S.num | S in Reduction.all};
53     gSum = sum{S.num | S in Reduction.all};     gSum = sum{S.num | S in Reduction.all};
54     gExists = exists{S.num > 400 | S in Reduction.all};     gMin = minr {S.num | S in Reduction.all};
55     gAll = all{S.num > 100 | S in Reduction.all};     gMax = maxr {S.num | S in Reduction.all};
56     gMean = mean{S.num | S in Reduction.all};     gExists = exists{S.num > 5 | S in Reduction.all};
57       gAll = all{S.num > 100 | S in Reduction.stable};
58       gMean = mean{S.num | S in Reduction.stable};
59     gVar = variance{ S.num | S in Reduction.all};     gVar = variance{ S.num | S in Reduction.all};
gStdev = sqrt(gVar);
60     steps = steps + 1;     steps = steps + 1;
61  }  }
62
63  initially [ Reduction(vi,numbers{vi}) | vi in 0..(nNumbers-1)];  initially [ Reduction(vi,vi) | vi in 1..nNumbers];

Legend:
 Removed from v.2288 changed lines Added in v.2289