Skip to content

Commit dd28416

Browse files
authored
Merge pull request #313 from isuruf/xreplace
Use xreplace from C++ instead of subs
2 parents 4abfe89 + a021d45 commit dd28416

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
@@ -911,7 +911,11 @@ cdef class Basic(object):
911911
cdef _DictBasic D = get_dict(*args)
912912
return c2py(symengine.ssubs(self.thisptr, D.c))
913913

914-
replace = xreplace = subs
914+
def xreplace(Basic self not None, *args):
915+
cdef _DictBasic D = get_dict(*args)
916+
return c2py(symengine.xreplace(self.thisptr, D.c))
917+
918+
replace = xreplace
915919

916920
def msubs(Basic self not None, *args):
917921
cdef _DictBasic D = get_dict(*args)
@@ -3531,7 +3535,11 @@ cdef class DenseMatrixBase(MatrixBase):
35313535
cdef _DictBasic D = get_dict(*args)
35323536
return self.applyfunc(lambda x: x.subs(D))
35333537

3534-
replace = xreplace = subs
3538+
def xreplace(self, *args):
3539+
cdef _DictBasic D = get_dict(*args)
3540+
return self.applyfunc(lambda x: x.xreplace(D))
3541+
3542+
replace = xreplace
35353543

35363544
@property
35373545
def free_symbols(self):

0 commit comments

Comments
 (0)