-
Notifications
You must be signed in to change notification settings - Fork 18
pymath.dot_inplace
Daniel Flassig edited this page Jun 24, 2026
·
1 revision
In-place vector product / matrix multiplication: like pymath.dot, but stores the product back into a instead of allocating a new table, and returns a.
a = pymath.dot_inplace(a, b [, b_axis])Since the product must fit back into a, the contracted index of a is always its last axis, and b must be a square n × n matrix. Only b_axis is therefore configurable.
| Parameter | Type | Description |
|---|---|---|
a |
tensor | Left vector, matrix or tensor; receives the product. Its last axis has size n. |
b |
tensor | Square n × n matrix. |
b_axis |
integer |
1-based position of the index of b that is contracted (summed over). Default: normal matrix multiplication (first axis) |
| Type | Description |
|---|---|
a |
The same table that was passed in, now holding the product (returned for convenience). |
-
bmust be a square matrix (rank-2 tensor) whose size matchesa's last axis, otherwise an error is raised. -
aandbmust be different tables. -
nilholes inaare filled with0.0, so the result is fully dense.
For a square matrix B and a list of row vectors M (a matrix whose rows are transformed):
-
pymath.dot_inplace(v, B)overwrites the vectorvwithv^T . B(for pymath, row and column vectors are identical) -
pymath.dot_inplace(M, B)overwritesMwith the productM · B, i.e. transforms every row ofMbyB
local points = {{1, 0},
{0, 1},
{2, 3}}
local rot90 = {{ 0, 1},
{-1, 0}} -- maps (x, y) -> (-y, x)
-- transform every row of points by rot90, in place
pymath.dot_inplace(points, rot90)
-- points == {{0, 1}, {-1, 0}, {-3, 2}}
Minimum PYTHA Version: V27