Actions used by the coercion model for matrix and vector multiplications

Warning

The class MatrixMulAction and its descendants extends the class Action. As a consequence objects from these classes only keep weak references to the underlying sets which are acted upon. This decision was made in trac ticket #715 in order to allow garbage collection within the coercion framework, where actions are mainly used, and avoid memory leaks.

To ensure that the underlying set of such an object does not get garbage collected, it is sufficient to explicitly create a strong reference to it before creating the action.

sage: MSQ = MatrixSpace(QQ, 2)
sage: MSZ = MatrixSpace(ZZ['x'], 2)
sage: A = MSQ.get_action(MSZ)
sage: A
Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field on Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring
sage: import gc
sage: _ = gc.collect()
sage: A
Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field on Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring

Note

The MatrixSpace() function caches the objects it creates. Therefore, the underlying set MSZ in the above example will not be garbage collected, even if it is not strongly ref’ed. Nonetheless, there is no guarantee that the set that is acted upon will always be cached in such a way, so that following the above example is good practice.

EXAMPLES:

An action requires a common parent for the base rings, so the following doesn’t work (see trac ticket #17859):

sage: vector(QQ, [1]) * matrix(Zmod(2), [[1]])
Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for *: 'Vector space of
dimension 1 over Rational Field' and 'Full MatrixSpace of 1 by 1
dense matrices over Ring of integers modulo 2'

AUTHOR:

  • Robert Bradshaw (2007-09): Initial version.

class sage.matrix.action.MatrixMatrixAction

Bases: sage.matrix.action.MatrixMulAction

Action of a matrix on another matrix.

This is always implemented as a left action.

EXAMPLES:

By trac ticket #715, there only is a weak reference on the underlying set, so that it can be garbage collected if only the action itself is explicitly referred to. Hence, we first assign the involved matrix spaces to a variable:

sage: R.<x> = ZZ[]
sage: MSR = MatrixSpace(R, 3, 3)
sage: MSQ = MatrixSpace(QQ, 3, 2)
sage: from sage.matrix.action import MatrixMatrixAction
sage: A = MatrixMatrixAction(MSR, MSQ); A
Left action by Full MatrixSpace of 3 by 3 dense matrices over Univariate Polynomial Ring in x over Integer Ring on Full MatrixSpace of 3 by 2 dense matrices over Rational Field
sage: A.codomain()
Full MatrixSpace of 3 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field
sage: A(matrix(R, 3, 3, x), matrix(QQ, 3, 2, range(6)))
[  0   x]
[2*x 3*x]
[4*x 5*x]

Note

The MatrixSpace() function caches the object it creates. Therefore, the underlying set MSZ in the above example will not be garbage collected, even if it is not strongly ref’ed. Nonetheless, there is no guarantee that the set that is acted upon will always be cached in such a way, so that following the above example is good practice.

class sage.matrix.action.MatrixMulAction

Bases: sage.categories.action.Action

Abstract base class for a matrix space acting on something.

EXAMPLES:

sage: MSQ = MatrixSpace(QQ, 2)
sage: MSZ = MatrixSpace(ZZ['x'], 2)
sage: A = MSQ.get_action(MSZ); A
Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field on Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring
sage: A.actor()
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
sage: A.domain()
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring
sage: A.codomain()
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field
codomain()
class sage.matrix.action.MatrixPolymapAction

Bases: sage.matrix.action.MatrixMulAction

Left action of a matrix on a scheme polynomial morphism

class sage.matrix.action.MatrixSchemePointAction

Bases: sage.matrix.action.MatrixMulAction

Action class for left multiplication of schemes points by matrices.

class sage.matrix.action.MatrixVectorAction

Bases: sage.matrix.action.MatrixMulAction

Left action of a matrix on a vector

class sage.matrix.action.PolymapMatrixAction

Bases: sage.matrix.action.MatrixMulAction

Right action of a matrix on a scheme polynomial morphism

class sage.matrix.action.VectorMatrixAction

Bases: sage.matrix.action.MatrixMulAction

Right action of a matrix on a vector