ztcl::tensor linear
Gives the product of a matrix and the transpose of another.
ztcl::tensor linear X W
Description
Gives X (n by m) times the transpose of W (k by m), of one dtype. W has one row for each output, the layout of the weight matrices of most model files, so the product needs no transposed copy of W. Each output element adds its m products in rising order, with a multiply and then an add, so the result has the bits of matmul X [transpose W] in each build.
The command splits the output columns between at most the count of threads that the embedder sets (--tensor-threads of the runner). Each element is computed on one thread in the same order, so the bits and the compute units do not depend on the count of threads. The cost is n * m * k operations, as for matmul.
Returns
A tensor of n by k.
Examples
Each example of this page runs after package require ztcl::tensor.
% ztcl::tensor linear [ztcl::tensor of {{1 1}}] [ztcl::tensor of {{1 2} {3 4} {5 6}}]
tensor f32 {1 3} {3.0 7.0 11.0}
Errors
% ztcl::tensor linear [ztcl::tensor of {{1 1}}] [ztcl::tensor of {{1 2 3}}]
tensor linear: the shapes {1 2} and {1 3} do not match
-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.