From: Michael Orlitzky Date: Tue, 9 Mar 2021 19:59:20 +0000 (-0500) Subject: eja: fix representation of "zero" in MatrixAlgebra. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=sage.d.git;a=commitdiff_plain;h=9c7fc4d836d337fcba8846ee4538bb0571c60f08;hp=77d2d169ac8a3e46030ee98e6bdb45df418a59c2 eja: fix representation of "zero" in MatrixAlgebra. --- diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 7255533..c6de223 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -1972,7 +1972,10 @@ class RealSymmetricEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA): # because the MatrixEJA is not presently a subclass of the # FDEJA class that defines rank() and one(). self.rank.set_cache(n) - self.one.set_cache(self(A.one())) + if n == 0: + self.one.set_cache( self.zero() ) + else: + self.one.set_cache(self(A.one())) @@ -2050,7 +2053,10 @@ class ComplexHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA): # because the MatrixEJA is not presently a subclass of the # FDEJA class that defines rank() and one(). self.rank.set_cache(n) - self.one.set_cache(self(A.one())) + if n == 0: + self.one.set_cache( self.zero() ) + else: + self.one.set_cache(self(A.one())) @staticmethod def _max_random_instance_size(): @@ -2139,7 +2145,10 @@ class QuaternionHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA): # because the MatrixEJA is not presently a subclass of the # FDEJA class that defines rank() and one(). self.rank.set_cache(n) - self.one.set_cache(self(A.one())) + if n == 0: + self.one.set_cache( self.zero() ) + else: + self.one.set_cache(self(A.one())) @staticmethod @@ -2280,7 +2289,10 @@ class OctonionHermitianEJA(RationalBasisEJA, ConcreteEJA, MatrixEJA): # because the MatrixEJA is not presently a subclass of the # FDEJA class that defines rank() and one(). self.rank.set_cache(n) - self.one.set_cache(self(A.one())) + if n == 0: + self.one.set_cache( self.zero() ) + else: + self.one.set_cache(self(A.one())) class AlbertEJA(OctonionHermitianEJA): diff --git a/mjo/matrix_algebra.py b/mjo/matrix_algebra.py index bd173ea..29a37d1 100644 --- a/mjo/matrix_algebra.py +++ b/mjo/matrix_algebra.py @@ -57,8 +57,18 @@ class MatrixAlgebraElement(IndexedFreeModuleElement): | 0 | 0 | +---+---+ + TESTS:: + + sage: MatrixAlgebra(0,ZZ,ZZ).zero() + 0 + """ - return table(self.rows(), frame=True)._repr_() + if self.nrows() == 0 or self.ncols() == 0: + # Otherwise we get a crash or a blank space, depending + # on how hard we work for it. + return self.parent().entry_algebra().zero().__repr__() + + return table(rs, frame=True)._repr_() def list(self):