]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: fix representation of "zero" in MatrixAlgebra.
authorMichael Orlitzky <michael@orlitzky.com>
Tue, 9 Mar 2021 19:59:20 +0000 (14:59 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Tue, 9 Mar 2021 19:59:20 +0000 (14:59 -0500)
mjo/eja/eja_algebra.py
mjo/matrix_algebra.py

index 7255533072acda6e0a92664b2d2439004a0beb95..c6de22399133794ae2485df41114dcbe90e55094 100644 (file)
@@ -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):
index bd173eaba835b8b82632587e62fcf6a8e7ec4e44..29a37d1e7c9bdee3dee6b36960126d5f545753fe 100644 (file)
@@ -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):