beetlebug▾
/

ztcl::tensor div

Divides two tensors, element by element.

ztcl::tensor div A B

Description

Divides the elements of A and B. The shapes broadcast: they align at the right, and a dimension of size 1 repeats. A plain number for one operand is a scalar of the dtype of the other operand, and the operands need one dtype. An i32 division goes toward zero, and a division by zero gives 0.

Returns

A tensor.

Examples

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

% ztcl::tensor div [ztcl::tensor of {7 -7 5} -dtype i32] [ztcl::tensor of {2 2 0} -dtype i32]
tensor i32 3 {3 -3 0}

Errors

% ztcl::tensor div [ztcl::tensor of {1 2 3}] [ztcl::tensor of {1 2}]
tensor: the shapes {3} and {2} do not broadcast
-errorcode ZTCL TENSOR

% ztcl::tensor div 1 2
tensor div: one operand must be a tensor
-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.