Skip to content

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)

Return value

Type Description
a The same table that was passed in, now holding the product (returned for convenience).

Notes:

  • b must be a square matrix (rank-2 tensor) whose size matches a's last axis, otherwise an error is raised.
  • a and b must be different tables.
  • nil holes in a are filled with 0.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 vector v with v^T . B (for pymath, row and column vectors are identical)
  • pymath.dot_inplace(M, B) overwrites M with the product M · B, i.e. transforms every row of M by B

Example:

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}}

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.dot

Clone this wiki locally