beetlebug▾
/

ztcl::tensor sumto

Sums a tensor down to a shape that broadcasts to it.

ztcl::tensor sumto TENSOR SHAPE

Description

Gives the sum of TENSOR over the dimensions that SHAPE has as 1 or does not have. It is the adjoint of a broadcast to the shape of TENSOR.

Returns

A tensor.

Examples

Each example of this page runs after package require ztcl::tensor.

% set a [ztcl::tensor of {{1 2 3} {4 5 6}}]; ztcl::tensor sumto $a {1 3}
tensor f32 {1 3} {5.0 7.0 9.0}

% set a [ztcl::tensor of {{1 2 3} {4 5 6}}]; ztcl::tensor sumto $a 3
tensor f32 3 {5.0 7.0 9.0}

Errors

% set a [ztcl::tensor of {{1 2 3} {4 5 6}}]; ztcl::tensor sumto $a {2 2}
tensor sumto: {2 3} does not reduce to {2 2}
-errorcode ZTCL TENSOR

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.4
Compute cost
A cost for each element operation by its kind (a copy, an add, a division, a math function, a multiply-add of a matmul), set so that one compute unit takes about the time of one unit of plain Tcl. docs/modules/tensor.md has the table.