You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Title: Conversion from Sage matrix to sympy matrix fails for matrices with rows full of zeros
Description: If a matrix created with the sage package features a row with only zeros, the constructor of ImmutableMatrix produces a matrix without those rows.
The problem:
After investigating, the rows method of sage returns a list of sage.modules.vector_integer_dense.Vector_integer_dense. The vector_integer_dense class evaluates to false if all its elements are zero, while the python list type does so only if it is empty.
Possible fix:
The function _handle_creation_inputs of the class MatrixBase in the file sympy/sympy/matrices/matrixbase.py includes logic which discard rows that evaluate to false. Commenting out lines 3854-3855 fixes the issue.
classMatrixBase(Printable):
...
def_handle_creation_inputs(cls, *args, **kwargs):
...
ifnotis_sequence(row) and \
notgetattr(row, 'is_Matrix', False):
raiseValueError('expecting list of lists')
ifhasattr(row, '__array__'):
if0inrow.shape:
continue#elif not row:# continue
Workaround:
Converting the Vector_integer_dense as shown: rows_A = [list(x) for x in rows_A].
Tested Versions:
OS: Ubuntu 24.04 x86_64
python: Python 3.11.9 | packaged by conda-forge | (main, Apr 19 2024, 18:36:13) [GCC 12.3.0] on linux
sympy: 1.12
sage: 10.2
The text was updated successfully, but these errors were encountered:
Title: Conversion from Sage matrix to sympy matrix fails for matrices with rows full of zeros
Description: If a matrix created with the sage package features a row with only zeros, the constructor of ImmutableMatrix produces a matrix without those rows.
Steps to reproduce:
Run this code (needs sage):
The problem:
After investigating, the
rows
method of sage returns alist
ofsage.modules.vector_integer_dense.Vector_integer_dense
. Thevector_integer_dense
class evaluates to false if all its elements are zero, while the pythonlist
type does so only if it is empty.Possible fix:
The function
_handle_creation_inputs
of the classMatrixBase
in the filesympy/sympy/matrices/matrixbase.py
includes logic which discard rows that evaluate to false. Commenting out lines 3854-3855 fixes the issue.Workaround:
Converting the
Vector_integer_dense
as shown:rows_A = [list(x) for x in rows_A]
.Tested Versions:
The text was updated successfully, but these errors were encountered: