beetlebug▾
/

ztcl::tensor rand

Makes a tensor of uniform random numbers from a seed.

ztcl::tensor rand SHAPE ?-seed N? ?-dtype DTYPE? ?-lo A? ?-hi B?

Description

Makes a tensor of SHAPE with numbers from A (default 0) to below B (default 1). The generator is splitmix64 with the seed N (default 0), so one seed gives the same bits in each run and each build. For i32, each number goes down to an integer. -mean is a second name of -lo, and -std of -hi.

Returns

A tensor.

Examples

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

% ztcl::tensor rand 3 -seed 1
tensor f32 3 {0.5665616 0.7457818 0.97100276}

% ztcl::tensor equal [ztcl::tensor rand {4 4} -seed 7] [ztcl::tensor rand {4 4} -seed 7]
1

% ztcl::tensor rand 5 -seed 2 -dtype i32 -lo 0 -hi 10
tensor i32 5 {5 7 5 7 3}

Errors

% ztcl::tensor rand 3 -bogus 1
tensor rand: unknown option "-bogus"
-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.