Ticket #11555: trac_11555-free-module-morphism-printing.patch

File trac_11555-free-module-morphism-printing.patch, 4.4 KB (added by rbeezer, 10 years ago)
  • sage/modules/free_module_morphism.py

    # HG changeset patch
    # User Rob Beezer <beezer@ups.edu>
    # Date 1309326724 25200
    # Node ID c28e4a2e5d303218d0b4637b9c7ee0785666ceab
    # Parent  4ad86990d7215498658440de04560aa028dcdeeb
    11555: expand print representation of free module morphisms
    
    diff -r 4ad86990d721 -r c28e4a2e5d30 sage/modules/free_module_morphism.py
    a b  
    143143        return matrix_morphism.MatrixMorphism.__call__(self, x)
    144144       
    145145    def _repr_(self):
    146         """
     146        r"""
    147147        Return string representation of this morphism of free modules.
    148        
     148
    149149        EXAMPLES::
    150        
     150
    151151            sage: V = QQ^3; W = span([[1,2,3],[-1,2,5/3]], QQ)
    152152            sage: phi = V.hom(matrix(QQ,3,[1..9]))
    153             sage: phi._repr_()       
     153            sage: phi._repr_()
    154154            'Free module morphism defined by the matrix\n[1 2 3]\n[4 5 6]\n[7 8 9]\nDomain: Vector space of dimension 3 over Rational Field\nCodomain: Vector space of dimension 3 over Rational Field'
     155
     156            sage: V = ZZ^6
     157            sage: W = ZZ^4
     158            sage: m = matrix(QQ, [[1, 0, 0 ,0], [0]*4, [0]*4, [0]*4, [0]*4, [0]*4])
     159            sage: phi = V.hom(m, W)
     160            sage: rho = phi.restrict_codomain(W.span([W.0]))
     161            sage: rho
     162            Free module morphism defined by the matrix
     163            [1]
     164            [0]
     165            [0]
     166            [0]
     167            [0]
     168            [0]
     169            Domain: Ambient free module of rank 6 over the principal ideal domain Integer Ring
     170            Codomain: Free module of degree 4 and rank 1 over Integer Ring
     171            Echelon basis matrix:
     172            [1 0 0 0]
     173
     174            sage: V = QQ^40
     175            sage: m = matrix(QQ, 40, 40, 1600)
     176            sage: phi = V.hom(m, V)
     177            sage: phi
     178            Free module morphism defined by the matrix
     179            40 x 40 dense matrix over Rational Field
     180            Domain: Vector space of dimension 40 over Rational Field
     181            Codomain: Vector space of dimension 40 over Rational Field
    155182        """
    156         if max(self.matrix().nrows(),self.matrix().ncols()) > 5:
    157             mat = "(not printing %s x %s matrix)"%(self.matrix().nrows(), self.matrix().ncols())
    158         else:
    159             mat = str(self.matrix())
    160         return "Free module morphism defined by the matrix\n%s\nDomain: %s\nCodomain: %s"%(\
    161             mat, misc.strunc(self.domain()), misc.strunc(self.codomain()))
     183        r = "Free module morphism defined by the matrix\n{0}\nDomain: {1}\nCodomain: {2}"
     184        return r.format(self.matrix(), self.domain(), self.codomain())
    162185
    163186    def change_ring(self, R):
    164187        """
  • sage/modules/matrix_morphism.py

    diff -r 4ad86990d721 -r c28e4a2e5d30 sage/modules/matrix_morphism.py
    a b  
    841841        return self._matrix.rank() == self.codomain().dimension()
    842842
    843843    def _repr_(self):
    844         """
    845         Return string representation of this morphism (this gets overloaded in the derived class).
     844        r"""
     845        Return string representation of this matrix morphism.
     846
     847        This will typically be overloaded in a derived class.
    846848
    847849        EXAMPLES::
    848850
    849851            sage: V = ZZ^2; phi = V.hom([3*V.0, 2*V.1])
    850             sage: phi._repr_()
    851             'Free module morphism defined by the matrix\n[3 0]\n[0 2]\nDomain: Ambient free module of rank 2 over the principal ideal domain ...\nCodomain: Ambient free module of rank 2 over the principal ideal domain ...'
    852852            sage: sage.modules.matrix_morphism.MatrixMorphism._repr_(phi)
    853853            'Morphism defined by the matrix\n[3 0]\n[0 2]'
     854
     855            sage: phi._repr_()
     856            'Free module morphism defined by the matrix\n[3 0]\n[0 2]\nDomain: Ambient free module of rank 2 over the principal ideal domain Integer Ring\nCodomain: Ambient free module of rank 2 over the principal ideal domain Integer Ring'
    854857        """
    855         if max(self.matrix().nrows(),self.matrix().ncols()) > 5:
    856             mat = "(not printing %s x %s matrix)"%(self.matrix().nrows(),
    857                                                    self.matrix().ncols())
    858         else:
    859             mat = str(self.matrix())
    860         return "Morphism defined by the matrix\n%s"%mat
     858        return "Morphism defined by the matrix\n{0}".format(self.matrix())