CVS difference for ai12s/ai12-0312-1.txt

Differences between 1.4 and version 1.5
Log of other versions for file ai12s/ai12-0312-1.txt

--- ai12s/ai12-0312-1.txt	2019/03/08 00:22:31	1.4
+++ ai12s/ai12-0312-1.txt	2019/04/02 00:38:36	1.5
@@ -1,4 +1,4 @@
-!standard 5.5.2(2/3)                                  19-03-07  AI12-0312-1/02
+!standard 5.5.2(2/3)                                  19-03-22  AI12-0312-1/03
 !class presentation 19-02-07
 !status work item 19-02-07
 !status received 19-02-07
@@ -77,7 +77,30 @@
          when 'D' => 500,
          when 'M' => 1000);
 
+Append after 4.5.10 (53/5):
 
+     A parallel reduction expression that outputs the mean of the
+     elements with even values for an array:
+
+     type Accumulator is record
+        Sum : Integer; Addends : Natural;
+     end;=
+
+     function Combine (L, R : Accumulator) return Accumulator is
+        (Sum => L.Sum + R.Sum, Addends => L.Addends + R.Addends);
+
+     function Reduce (A : Accumulator; Addend : Integer) is
+        (Sum => A.Sum + Addend, Addends => A.Addends + 1);
+
+     function Mean (A : Accumulator) return Integer is (A.Sum / A.Addends);
+
+     Put_Line("The mean of the even values of A is" &
+              Mean ([for Val of A when (A mod 2) = 0 => Val]
+                      'Parallel_Reduce(Reduce,
+                                       (Sum => 0, Addends => 0),
+                                       Combine)));
+
+
 Modify 5.5(22/5):
 "Example{s} of [a] parallel loop{s}: "
 
@@ -459,5 +482,70 @@
 submission.
 
 [This is version /02 of the AI - Editor.]
+
+****************************************************************
+
+From: Brad Moore
+Sent: Friday, March 22, 2019  2:32 PM
+
+Here is a minor update to AI12-0312-1
+
+[This is version /03 of the AI - Editor.]
+
+Steve Baird had commented that it would be good to have an example of a parallel
+reduction expression with a combiner.
+
+Thanks also to Steve for suggesting an example, which I incorporated.
+
+I extended the example to use an iterator filter, which makes the example more
+practical, as otherwise one could just do an integer reduction / A'Length to get
+a mean.
+
+The example is:
+
+Append after 4.5.10 (53/5)
+
+     A parallel reduction expression that outputs the mean of the
+     elements with even values for an array:
+
+     type Accumulator is record
+        Sum : Integer; Addends : Natural;
+     end;=
+
+     function Combine (L, R : Accumulator) return Accumulator is
+        (Sum => L.Sum + R.Sum, Addends => L.Addends + R.Addends);
+
+     function Reduce (A : Accumulator; Addend : Integer) is
+        (Sum => A.Sum + Addend, Addends => A.Addends + 1);
+
+     function Mean (A : Accumulator) return Integer is (A.Sum / A.Addends);
+
+     Put_Line("The mean of the even values of A is" &
+              Mean ([for Val of A when (A mod 2) = 0 => Val]
+                      'Parallel_Reduce(Reduce,
+                                       (Sum => 0, Addends => 0),
+                                       Combine)));
+
+****************************************************************
+
+From: Jean-Pierre Rosen
+Sent: Saturday, March 23, 2019  6:49 PM
+
+There are several glitches in the example that caused me quite a hard time
+understanding it...
+
+1)
+                Mean ([for Val of A when (A mod 2) = 0 => Val]
+
+   "A mod 2" should be "Val mod 2", right?
+
+2)
+In the above, A is some array whose declaration is not shown, while everywhere
+else, A is the accumulator. Please use a different name (and possibly show the
+declaration).
+
+3)
+It took me quite a time to spot the difference between "addend" and "addends".
+Using "count" instead of "addends" would help a lot...
 
 ****************************************************************

Questions? Ask the ACAA Technical Agent