Skip to content

Commit 1ab7e36

Browse files
committed
Use xreplace from C++ instead of subs
1 parent 9f48c43 commit 1ab7e36

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

symengine/lib/symengine.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ cdef extern from "<symengine/basic.h>" namespace "SymEngine":
322322
cdef extern from "<symengine/subs.h>" namespace "SymEngine":
323323
rcp_const_basic msubs (rcp_const_basic &x, const map_basic_basic &x) nogil
324324
rcp_const_basic ssubs (rcp_const_basic &x, const map_basic_basic &x) nogil
325+
rcp_const_basic xreplace (rcp_const_basic &x, const map_basic_basic &x) nogil
325326

326327
cdef extern from "<symengine/derivative.h>" namespace "SymEngine":
327328
rcp_const_basic diff "SymEngine::sdiff"(rcp_const_basic &arg, rcp_const_basic &x) nogil except +

symengine/lib/symengine_wrapper.pyx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,11 @@ cdef class Basic(object):
907907
cdef _DictBasic D = get_dict(*args)
908908
return c2py(symengine.ssubs(self.thisptr, D.c))
909909

910-
replace = xreplace = subs
910+
def xreplace(Basic self not None, *args):
911+
cdef _DictBasic D = get_dict(*args)
912+
return c2py(symengine.xreplace(self.thisptr, D.c))
913+
914+
replace = xreplace
911915

912916
def msubs(Basic self not None, *args):
913917
cdef _DictBasic D = get_dict(*args)
@@ -3509,7 +3513,11 @@ cdef class DenseMatrixBase(MatrixBase):
35093513
cdef _DictBasic D = get_dict(*args)
35103514
return self.applyfunc(lambda x: x.subs(D))
35113515

3512-
replace = xreplace = subs
3516+
def xreplace(self, *args):
3517+
cdef _DictBasic D = get_dict(*args)
3518+
return self.applyfunc(lambda x: x.xreplace(D))
3519+
3520+
replace = xreplace
35133521

35143522
@property
35153523
def free_symbols(self):

0 commit comments

Comments
 (0)