Skip to content

Commit fa9d699

Browse files
authored
Merge pull request #487 from isuruf/subs-except
Mark subs as throwing exceptions
2 parents 9ce6c5a + 8f6f7a3 commit fa9d699

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

symengine/lib/symengine.pxd

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ cdef extern from "<symengine/basic.h>" namespace "SymEngine":
168168
void cse(vec_pair &replacements, vec_basic &reduced_exprs, const vec_basic &exprs) except+ nogil
169169

170170
cdef extern from "<symengine/subs.h>" namespace "SymEngine":
171-
rcp_const_basic msubs (rcp_const_basic &x, const map_basic_basic &x) nogil
172-
rcp_const_basic ssubs (rcp_const_basic &x, const map_basic_basic &x) nogil
173-
rcp_const_basic xreplace (rcp_const_basic &x, const map_basic_basic &x) nogil
171+
rcp_const_basic msubs (rcp_const_basic &x, const map_basic_basic &x) except+ nogil
172+
rcp_const_basic ssubs (rcp_const_basic &x, const map_basic_basic &x) except+ nogil
173+
rcp_const_basic xreplace (rcp_const_basic &x, const map_basic_basic &x) except+ nogil
174174

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

symengine/tests/test_subs.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22

33
from symengine.test_utilities import raises
4-
from symengine import Symbol, sin, cos, sqrt, Add, function_symbol, have_numpy
4+
from symengine import Symbol, sin, cos, sqrt, Add, function_symbol, have_numpy, log
55

66

77
def test_basic():
@@ -24,6 +24,12 @@ def test_sin():
2424
assert e.subs(x, 0) == 1
2525

2626

27+
def test_subs_exception():
28+
x = Symbol("x")
29+
expr = sin(log(x))
30+
raises(RuntimeError, lambda: expr.subs({x: 0}))
31+
32+
2733
def test_args():
2834
x = Symbol("x")
2935
e = cos(x)

0 commit comments

Comments
 (0)