You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: designs/0017-reduce_sum.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,13 +74,13 @@ real reduce_sum(F func, T[] x, int grainsize, T1 s1, T2 s2, ...)
74
74
The user-defined partial sum functions have the signature:
75
75
76
76
```
77
-
real func(int start, int end, T[] x_subset, T1 arg1, T2 arg2, ...)
77
+
real func(T[] x_subset, int start, int end, T1 arg1, T2 arg2, ...)
78
78
```
79
79
80
80
and take the arguments:
81
-
1.```start``` - An integer specifying the first term in the partial sum
82
-
2.```end``` - An integer specifying the last term in the partial sum (inclusive)
83
-
3.```x_subset``` - The subset of ```x``` (from ```reduce_sum```) for which this partial sum is responsible (```x[start:end]```)
81
+
1.```x_subset``` - The subset of ```x``` (from ```reduce_sum```) for which this partial sum is responsible (```x[start:end]```)
82
+
2.```start``` - An integer specifying the first term in the partial sum
83
+
3.```end``` - An integer specifying the last term in the partial sum (inclusive)
84
84
4-. ```arg1, arg2, ...``` Arguments shared in every term (passed on without modification from the reduce_sum call)
85
85
86
86
The user-provided function ```func``` is expect to compute the ```start``` through ```end``` terms of the overall sum, accumulate them, and return that value. The user function is passed the subset ```x[start:end]``` as ```x_subset```. ```start``` and ```end``` are passed so that ```func``` can index any of the tailing ```sM``` arguments as necessary. The trailing ```sM``` arguments are passed without modification to every call of ```func```.
@@ -94,15 +94,15 @@ real sum = reduce_sum(func, x, grainsize, s1, s2, ...)
94
94
can be replaced by either:
95
95
96
96
```
97
-
real sum = func(1, size(x), x, s1, s2, ...)
97
+
real sum = func(x, 1, size(x), s1, s2, ...)
98
98
```
99
99
100
100
or the code:
101
101
102
102
```
103
103
real sum = 0.0;
104
104
for(i in 1:size(x)) {
105
-
sum = sum + func(i, i, { x[i] }, s1, s2, ...);
105
+
sum = sum + func({ x[i] }, i, i, s1, s2, ...);
106
106
}
107
107
```
108
108
@@ -144,10 +144,10 @@ updating the model block to use ```reduce_sum``` gives:
0 commit comments