From 9c7fc4d836d337fcba8846ee4538bb0571c60f08 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 9 Mar 2021 14:59:20 -0500 Subject: [PATCH] eja: fix representation of "zero" in MatrixAlgebra. --- mjo/eja/eja_algebra.py | 20 ++++++++++++++++---- mjo/matrix_algebra.py | 12 +++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) 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): -- 2.43.2