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: src/functions-reference/higher-order_functions.Rmd
+27-26Lines changed: 27 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -385,47 +385,48 @@ The gradients of the integral are computed in accordance with the Leibniz integr
385
385
386
386
## Reduce-Sum Function {#functions-reduce}
387
387
388
-
Stan provides a higher-order `reduce_sum` function for parallelizing operations that can be represented as a sum of a function, `g: U -> real`, evaluated at each element of a list of type `U[]`, `{ x1, x2, ... }`. That is:
388
+
Stan provides a higher-order `reduce_sum` function which maps
389
+
evaluation of a function `g: U -> real` to a list of type `U[]`, `{
390
+
x1, x2, ... }`, and performs as reduction operation a sum over the
391
+
results. That is:
389
392
390
393
```g(x1) + g(x2) + ...```
391
394
392
-
`reduce_sum` doesn't work on `g` itself, but takes a partial sum function, `f: U[] -> real`, where:
395
+
`reduce_sum` doesn't work with the element-wise evaluated
396
+
function `g` itself, but instead works through evaluating partial
397
+
sums, `f: U[] -> real`, where:
393
398
394
-
```f({ x1 }) = g(x1)```
395
-
```f({ x1, x2 }) = g(x1) + g(x2)```
396
-
```f({ x1, x2, ... }) = g(x1) + g(x2) + ...```
399
+
```
400
+
f({ x1 }) = g(x1)
401
+
f({ x1, x2 }) = g(x1) + g(x2)
402
+
f({ x1, x2, ... }) = g(x1) + g(x2) + ...
403
+
```
397
404
398
-
### The Reduce-sum Function
405
+
### Specifying the Reduce-sum Function
399
406
400
-
The `reduce_sum` function takes a partial sum function, an array argument x
401
-
(with one for each term in the sum), a recommended grainsize, and a set of shared arguments and
402
-
parallelizes the resultant sum.
407
+
The `reduce_sum` function takes a partial sum function `f`, an array argument `x`
408
+
(with one array element for each term in the sum), a recommended
409
+
`grainsize`, and a set of shared arguments. This representation allows
0 commit comments