beetlebug▾
/

ztcl::tensor raw

Makes a tensor of the little-endian bytes of its elements.

ztcl::tensor raw DTYPE SHAPE BYTES

Description

Makes a tensor of SHAPE from BYTES: the elements of DTYPE in row-major order, little-endian. It is the form of a safetensors file. BYTES needs the exact count of bytes.

Returns

A tensor.

Examples

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

% ztcl::tensor raw i32 2 [binary format i2 {7 8}]
tensor i32 2 {7 8}

Errors

% ztcl::tensor raw f32 2 abc
tensor raw: the shape {2} of f32 needs 8 bytes, and the value has 3
-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.