beetlebug▾
/

ztcl::tensor above

Gives the first index of an element above a number.

ztcl::tensor above TENSOR X

Description

Gives the first index i of a tensor of rank 1 with an element above X, or the size of TENSOR when no element is above X. The compare is in f64. For a tensor in rising order, such as the result of cumsum, it is the place of X in the tensor, so it picks an index of a distribution with a given uniform number.

Returns

An integer.

Examples

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

% ztcl::tensor above [ztcl::tensor cumsum [ztcl::tensor of {0.25 0.5 0.25}]] 0.6
1

% ztcl::tensor above [ztcl::tensor of {1 2}] 5
2

Errors

% ztcl::tensor above [ztcl::tensor of {1 2}] x
tensor: expected a number but got "x"
-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.