sum

Computes a sum reduction along the specified axes.

sum
(
,
size_t[] axes = []
,
string mod = __MODULE__
,
size_t line = __LINE__
)

Parameters

op
Type: Operation

The input to the reduction.

axes
Type: size_t[]

The axes the reduction should be performed along.

Return Value

Type: Operation

The resulting operation.

Examples

1 import dopt.core : evaluate;
2 
3 auto s1 = float32([2], [0.5, 1.5]).sum();
4 auto s2 = float32([2, 2], [0, 1, 0, 5]).sum();
5 auto s3 = float32([2, 2], [0, 1, 0, 5]).sum([0]);
6 auto s4 = float32([2, 2], [0, 1, 0, 5]).sum([1]);
7 
8 assert(s1.evaluate().as!float == [2.0f]);
9 assert(s2.evaluate().as!float == [6.0f]);
10 assert(s3.evaluate().as!float == [0.0f, 6.0f]);
11 assert(s4.evaluate().as!float == [1.0f, 5.0f]);

Meta