Skip to content

Commit 9550a2b

Browse files
rikardnisuruf
authored andcommitted
Better compatibility with sympy ImmutableMatrix (fixes #363)
simplify Immutable to new Immutable sympy.sympify matrices to Immutable
1 parent 0ca50eb commit 9550a2b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

symengine/lib/symengine_wrapper.pyx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3895,7 +3895,7 @@ cdef class DenseMatrixBase(MatrixBase):
38953895
l.append(c2py(A.get(i, j))._sympy_())
38963896
s.append(l)
38973897
import sympy
3898-
return sympy.Matrix(s)
3898+
return sympy.ImmutableMatrix(s)
38993899

39003900
def _sage_(self):
39013901
s = []
@@ -3906,7 +3906,7 @@ cdef class DenseMatrixBase(MatrixBase):
39063906
l.append(c2py(A.get(i, j))._sage_())
39073907
s.append(l)
39083908
import sage.all as sage
3909-
return sage.Matrix(s)
3909+
return sage.ImmutableMatrix(s)
39103910

39113911
def dump_real(self, double[::1] out):
39123912
cdef size_t ri, ci, nr, nc
@@ -4046,6 +4046,16 @@ cdef class ImmutableDenseMatrix(DenseMatrixBase):
40464046
def __setitem__(self, key, value):
40474047
raise TypeError("Cannot set values of {}".format(self.__class__))
40484048

4049+
def _applyfunc(self, f):
4050+
cdef int nr = self.nrows()
4051+
cdef int nc = self.ncols()
4052+
temp = DenseMatrix(self)
4053+
for i in range(nr):
4054+
for j in range(nc):
4055+
temp._set(i, j, f(temp._get(i, j)))
4056+
return ImmutableDenseMatrix(temp)
4057+
4058+
40494059
ImmutableMatrix = ImmutableDenseMatrix
40504060

40514061

symengine/tests/test_matrices.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,3 +741,8 @@ def test_repr_latex():
741741
latex_string = testmat._repr_latex_()
742742
assert isinstance(latex_string, str)
743743
init_printing(False)
744+
745+
746+
def test_simplify():
747+
A = ImmutableMatrix([1])
748+
assert type(A.simplify()) == type(A)

0 commit comments

Comments
 (0)