Skip to content

Commit b1dae92

Browse files
committed
ensures ma_entries_zero when scalar detected and the scalar is zero
1 parent 0fd5967 commit b1dae92

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/sage/matrix/args.pyx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ from cysignals.signals cimport sig_check
2121
MatrixSpace = None
2222

2323
from sage.rings.integer_ring import ZZ
24+
from sage.rings.integer cimport Integer
2425
from sage.structure.coerce cimport (coercion_model,
2526
is_numpy_type, py_scalar_parent)
2627
from sage.structure.element cimport Element, RingElement, Vector
@@ -925,9 +926,10 @@ cdef class MatrixArgs:
925926

926927
# Non-zero scalar matrices must be square
927928
if self.typ == MA_ENTRIES_SCALAR:
928-
if self.nrows != self.ncols:
929-
if self.entries:
929+
if self.entries:
930+
if self.nrows != self.ncols:
930931
raise TypeError("nonzero scalar matrix must be square")
932+
else:
931933
self.typ = MA_ENTRIES_ZERO
932934

933935
if self.sparse == -1:
@@ -1219,12 +1221,14 @@ cdef class MatrixArgs:
12191221
# hurt to do these first.
12201222
if self.entries is None:
12211223
return MA_ENTRIES_ZERO
1224+
if isinstance(self.entries, (int, float, complex, Integer)):
1225+
if self.entries:
1226+
return MA_ENTRIES_SCALAR
1227+
return MA_ENTRIES_ZERO
12221228
if isinstance(self.entries, (list, tuple)):
12231229
return self.sequence_type()
12241230
if isinstance(self.entries, dict):
12251231
return MA_ENTRIES_MAPPING
1226-
if isinstance(self.entries, (int, float, complex)):
1227-
return MA_ENTRIES_SCALAR
12281232

12291233
# Note: some objects are callable, iterable and act like a
12301234
# scalar, e.g. polynomials. So the order of these checks

0 commit comments

Comments
 (0)