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

Commit

Permalink
Matrix, MatrixSpace: Add coercion to polymake interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Mar 26, 2017
1 parent ef23af4 commit 205879f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/sage/matrix/matrix1.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,25 @@ cdef class Matrix(matrix0.Matrix):
s = str(self.rows()).replace('(','[').replace(')',']')
return "Matrix(%s,%s,%s)"%(self.nrows(), self.ncols(), s)

def _polymake_(self, polymake=None):
"""
Tries to coerce this matrix to a polymake matrix.
EXAMPLES::
sage: M = matrix(ZZ,2,range(4))
sage: polymake(M) # optional - polymake
0 1
2 3
sage: K.<sqrt5> = QuadraticField(5)
sage: M = matrix(K, [[1, 2], [sqrt5, 3]])
sage: polymake(M) # optional - polymake
1 2
0+1r5 3
"""
P = polymake(self.parent())
return polymake.new_object(P, [ list(r) for r in self.rows(copy=False) ])

def _singular_(self, singular=None):
"""
Tries to coerce this matrix to a singular matrix.
Expand Down
15 changes: 15 additions & 0 deletions src/sage/matrix/matrix_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,21 @@ def _magma_init_(self, magma):
s = 'RMatrixSpace(%s,%s,%s)'%(K.name(), self.__nrows, self.__ncols)
return s

def _polymake_init_(self):
r"""
Return the polymake representation of the matrix space.
EXAMPLES::
sage: polymake(MatrixSpace(QQ,3)) # optional - polymake
Matrix<Rational>
sage: polymake(MatrixSpace(QuadraticField(5),3)) # optional - polymake
Matrix<QuadraticExtension>
"""
from sage.interfaces.polymake import polymake
K = polymake(self.base_ring())
return '"Matrix<{}>"'.format(K)

def dict_to_list(entries, nrows, ncols):
"""
Given a dictionary of coordinate tuples, return the list given by
Expand Down

0 comments on commit 205879f

Please sign in to comment.