Skip to content

Commit 1619758

Browse files
committed
compat for Abs
1 parent 16c9422 commit 1619758

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

symengine/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
asin, acos, atan, acot, acsc, asec,
33
sinh, cosh, tanh, coth, sech, csch,
44
asinh, acosh, atanh, acoth, asech, acsch,
5-
gamma, log, atan2, sqrt, exp)
5+
gamma, log, atan2, sqrt, exp, Abs)

symengine/lib/symengine_wrapper.pyx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,10 @@ mul = Mul
14761476

14771477
class Abs(OneArgFunction):
14781478

1479+
def __new__(cls, x):
1480+
cdef Basic X = _sympify(x)
1481+
return c2py(symengine.abs(X.thisptr))
1482+
14791483
def _sympy_(Basic self):
14801484
cdef RCP[const symengine.Abs] X = symengine.rcp_static_cast_Abs(self.thisptr)
14811485
arg = c2py(deref(X).get_arg())._sympy_()

symengine/tests/test_sympy_compat.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from symengine.sympy_compat import (Integer, Rational, S, Basic, Add, Mul,
22
Pow, symbols, Symbol, log, sin, cos, sech, csch, zeros, atan2, Number, Float,
3-
Min, Max, RealDouble, have_mpfr)
3+
Min, Max, RealDouble, have_mpfr, Abs)
44
from symengine.utilities import raises
55

66

@@ -185,3 +185,7 @@ def __init__(self, name, extra_attribute):
185185
two_x = 2 * x
186186
# Check that after arithmetic, same subclass is returned
187187
assert two_x.args[1] is x
188+
189+
def test_Abs():
190+
x = symbols("x")
191+
assert Abs(x) == Abs(-x)

0 commit comments

Comments
 (0)