Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac 15104: Faster creation of transposed matrix' parent
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-king-jena committed Feb 6, 2014
1 parent a908e28 commit 5487c67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/sage/matrix/matrix1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2206,8 +2206,11 @@ cdef class Matrix(matrix0.Matrix):
Full MatrixSpace of 2 by 3 dense matrices over Real Field with 53 bits of precision
"""
if self._nrows == nrows and self._ncols == ncols and (sparse is None or self.is_sparse() == sparse):
return self._parent(entries=entries, coerce=coerce, copy=copy)
if (sparse is None or self.is_sparse() == sparse):
if self._nrows == nrows and self._ncols == ncols:
return self._parent(entries=entries, coerce=coerce, copy=copy)
elif self._nrows == ncols and self._ncols == nrows:
return self._parent.transposed(entries=entries, coerce=coerce, copy=copy)
return self.matrix_space(nrows, ncols, sparse=sparse)(entries=entries,
coerce=coerce, copy=copy)
def block_sum(self, Matrix other):
Expand Down
9 changes: 9 additions & 0 deletions src/sage/matrix/matrix_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,15 @@ def full_category_initialisation(self):
self._category_is_initialised = True
sage.structure.parent.Parent.__init__(self, category=category)

@lazy_attribute
def transposed(self):
"""
The transposed matrix space, having the same base ring and sparseness,
but number of columns and rows is swapped.
"""
return MatrixSpace(self._base, self.__ncols, self.__nrows, self.__is_sparse)

@lazy_attribute
def _copy_zero(self):
"""
Expand Down

0 comments on commit 5487c67

Please sign in to comment.