pytaco.sum

pytaco.sum(var, e)

Sums a dimension of an index expression.

Sums all elements in the dimension of the index expression specified by var.

Parameters
var: index_var

An index var corresponding to the dimension to sum across in the input index expression e.

e: index_expression

The index expression to sum.

Returns
reduced: index_expression

An index_expression with the dimension specified by var summed out.

Notes

This is different from the function tensor_sum() since this function can only sum one index variable at a time. The different expressions can be chained together to get behavior similar to tensor_sum().

Examples

We can use this to compute the magnitute of a vector without needed to specify a tensor to imply the reduction.

>>> import pytaco as pt
>>> t = pt.as_tensor([2.0, 3, 4, 5, 11])
>>> i = pt.index_var()
>>> res = pt.tensor()
>>> res[None] = pt.sqrt(pt.sum(i, pt.square(t[i])))
>>> res[0]
13.22875690460205