From 8f6f7a371e8cf915d4f6f779bff16b8a73415090 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 25 Jul 2024 10:30:10 -0500 Subject: [PATCH] Mark subs as throwing exceptions --- symengine/lib/symengine.pxd | 6 +++--- symengine/tests/test_subs.py | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/symengine/lib/symengine.pxd b/symengine/lib/symengine.pxd index ee96731b..3e2b5d08 100644 --- a/symengine/lib/symengine.pxd +++ b/symengine/lib/symengine.pxd @@ -168,9 +168,9 @@ cdef extern from "" namespace "SymEngine": void cse(vec_pair &replacements, vec_basic &reduced_exprs, const vec_basic &exprs) except+ nogil cdef extern from "" namespace "SymEngine": - rcp_const_basic msubs (rcp_const_basic &x, const map_basic_basic &x) nogil - rcp_const_basic ssubs (rcp_const_basic &x, const map_basic_basic &x) nogil - rcp_const_basic xreplace (rcp_const_basic &x, const map_basic_basic &x) nogil + rcp_const_basic msubs (rcp_const_basic &x, const map_basic_basic &x) except+ nogil + rcp_const_basic ssubs (rcp_const_basic &x, const map_basic_basic &x) except+ nogil + rcp_const_basic xreplace (rcp_const_basic &x, const map_basic_basic &x) except+ nogil cdef extern from "" namespace "SymEngine": rcp_const_basic diff "SymEngine::sdiff"(rcp_const_basic &arg, rcp_const_basic &x) except+ nogil diff --git a/symengine/tests/test_subs.py b/symengine/tests/test_subs.py index 4d8c6f0a..b346659b 100644 --- a/symengine/tests/test_subs.py +++ b/symengine/tests/test_subs.py @@ -1,7 +1,7 @@ import unittest from symengine.test_utilities import raises -from symengine import Symbol, sin, cos, sqrt, Add, function_symbol, have_numpy +from symengine import Symbol, sin, cos, sqrt, Add, function_symbol, have_numpy, log def test_basic(): @@ -24,6 +24,12 @@ def test_sin(): assert e.subs(x, 0) == 1 +def test_subs_exception(): + x = Symbol("x") + expr = sin(log(x)) + raises(RuntimeError, lambda: expr.subs({x: 0})) + + def test_args(): x = Symbol("x") e = cos(x)