def __init__(self, parent, A, copy_matrix=True): """ Initialize ``self``. EXAMPLES:: sage: from sage.modules.matrix_morphism import MatrixMorphism sage: T = End(ZZ^3) sage: M = MatrixSpace(ZZ,3) sage: I = M.identity_matrix() sage: A = MatrixMorphism(T, I) sage: loads(A.dumps()) == A True """ if parent is None: raise ValueError("no parent given when creating this matrix morphism") if isinstance(A, MatrixMorphism_abstract): A = A.matrix() R = A.base_ring() if A.nrows() != parent.domain().rank(): raise ArithmeticError("number of rows of matrix (={}) must equal rank of domain (={})".format(A.nrows(), parent.domain().rank())) if A.ncols() != parent.codomain().rank(): raise ArithmeticError("number of columns of matrix (={}) must equal rank of codomain (={})".format(A.ncols(), parent.codomain().rank())) if A.is_mutable(): if copy_matrix: from copy import copy A = copy(A) A.set_immutable() self._matrix = A MatrixMorphism_abstract.__init__(self, parent)
def __init__(self, parent, A, copy_matrix=True): """ Initialize ``self``. EXAMPLES:: sage: from sage.modules.matrix_morphism import MatrixMorphism sage: T = End(ZZ^3) sage: M = MatrixSpace(ZZ,3) sage: I = M.identity_matrix() sage: A = MatrixMorphism(T, I) sage: loads(A.dumps()) == A True """ if parent is None: raise ValueError("no parent given when creating this matrix morphism") if isinstance(A, MatrixMorphism_abstract): A = A.matrix() if A.nrows() != parent.domain().rank(): raise ArithmeticError("number of rows of matrix (={}) must equal rank of domain (={})".format(A.nrows(), parent.domain().rank())) if A.ncols() != parent.codomain().rank(): raise ArithmeticError("number of columns of matrix (={}) must equal rank of codomain (={})".format(A.ncols(), parent.codomain().rank())) if A.is_mutable(): if copy_matrix: from copy import copy A = copy(A) A.set_immutable() self._matrix = A MatrixMorphism_abstract.__init__(self, parent)