beetlebug▾
/

ztcl::tensor frombytes

Makes a tensor of unsigned bytes times a scale.

ztcl::tensor frombytes BYTES SHAPE ?SCALE? ?DTYPE?

Description

Makes a tensor of SHAPE where each element is one byte of BYTES, from 0 to 255, times SCALE (default 1.0). BYTES needs one byte for each element. The default dtype is f32. The MNIST files of the IDX format have this form.

Returns

A tensor.

Examples

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

% ztcl::tensor frombytes [binary format c3 {0 -1 2}] 3 0.5
tensor f32 3 {0.0 127.5 1.0}

Errors

% ztcl::tensor frombytes abc 4
tensor frombytes: the shape {4} needs 4 bytes
-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.