beetlebug▾
/

ztcl::tensor reshape

Gives the elements of a tensor with another shape.

ztcl::tensor reshape TENSOR SHAPE

Description

Gives a tensor with the elements of TENSOR in the same order and the shape SHAPE. One size of SHAPE can be -1: it is the size that keeps the count of elements. The new tensor shares the elements with TENSOR, because no command changes them.

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 reshape $a {3 -1}
tensor f32 {3 2} {1.0 2.0 3.0 4.0 5.0 6.0}

Errors

% set a [ztcl::tensor of {{1 2 3} {4 5 6}}]; ztcl::tensor reshape $a {4 2}
tensor reshape: {2 3} has 6 elements, and {4 2} has 8
-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.