Skip to content

Commit

Permalink
Wrapped as_real_imag
Browse files Browse the repository at this point in the history
  • Loading branch information
npochhi committed Feb 10, 2018
1 parent 16280ce commit 3646c8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions symengine/lib/symengine.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ cdef extern from "<symengine/basic.h>" namespace "SymEngine":
bool is_a_Xor "SymEngine::is_a<SymEngine::Xor>"(const Basic &b) nogil
rcp_const_basic expand(rcp_const_basic &o, bool deep) nogil except +
void as_numer_denom(rcp_const_basic &x, const Ptr[RCP[Basic]] &numer, const Ptr[RCP[Basic]] &denom) nogil
void as_real_imag(rcp_const_basic &x, const Ptr[RCP[Basic]] &real, const Ptr[RCP[Basic]] &imag) nogil
void cse(vec_pair &replacements, vec_basic &reduced_exprs, const vec_basic &exprs) nogil except +

cdef extern from "<symengine/subs.h>" namespace "SymEngine":
Expand Down
5 changes: 5 additions & 0 deletions symengine/lib/symengine_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,11 @@ cdef class Basic(object):
symengine.as_numer_denom(self.thisptr, symengine.outArg(_num), symengine.outArg(_den))
return c2py(<rcp_const_basic>_num), c2py(<rcp_const_basic>_den)

def as_real_imag(Basic self not None):
cdef rcp_const_basic _real, _imag
symengine.as_real_imag(self.thisptr, symengine.outArg(_real), symengine.outArg(_imag))
return c2py(<rcp_const_basic>_real), c2py(<rcp_const_basic>_imag)

def n(self, prec = 53, real = False):
if real:
return eval_real(self, prec)
Expand Down
7 changes: 6 additions & 1 deletion symengine/tests/test_arit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from symengine.utilities import raises

from symengine import Symbol, Integer, Add, Mul, Pow, Rational, sqrt
from symengine.lib.symengine_wrapper import Zero, One, NegativeOne, Half
from symengine.lib.symengine_wrapper import Zero, One, NegativeOne, Half, I


def test_arit1():
Expand Down Expand Up @@ -165,6 +165,11 @@ def test_as_numer_denom():
assert x == Integer(-5)
assert y == Integer(1)

def test_as_real_imag():
x, y = (5 + 6 * I).as_real_imag()

assert x == 5
assert y == 6

def test_from_args():
x = Symbol("x")
Expand Down

0 comments on commit 3646c8a

Please sign in to comment.