beetlebug▾
/

ztcl::tensor expand

Repeats a tensor to a shape by the broadcast rule.

ztcl::tensor expand TENSOR SHAPE

Description

Gives a tensor of SHAPE with the elements of TENSOR repeated along each dimension of size 1.

Returns

A tensor.

Examples

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

% ztcl::tensor expand [ztcl::tensor of {1 2 3}] {2 3}
tensor f32 {2 3} {1.0 2.0 3.0 1.0 2.0 3.0}

Errors

% ztcl::tensor expand [ztcl::tensor of {1 2 3}] {2 2}
tensor expand: {3} does not broadcast 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.