Skip to content

Commit 3646c8a

Browse files
committed
Wrapped as_real_imag
1 parent 16280ce commit 3646c8a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

symengine/lib/symengine.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ cdef extern from "<symengine/basic.h>" namespace "SymEngine":
315315
bool is_a_Xor "SymEngine::is_a<SymEngine::Xor>"(const Basic &b) nogil
316316
rcp_const_basic expand(rcp_const_basic &o, bool deep) nogil except +
317317
void as_numer_denom(rcp_const_basic &x, const Ptr[RCP[Basic]] &numer, const Ptr[RCP[Basic]] &denom) nogil
318+
void as_real_imag(rcp_const_basic &x, const Ptr[RCP[Basic]] &real, const Ptr[RCP[Basic]] &imag) nogil
318319
void cse(vec_pair &replacements, vec_basic &reduced_exprs, const vec_basic &exprs) nogil except +
319320

320321
cdef extern from "<symengine/subs.h>" namespace "SymEngine":

symengine/lib/symengine_wrapper.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,11 @@ cdef class Basic(object):
900900
symengine.as_numer_denom(self.thisptr, symengine.outArg(_num), symengine.outArg(_den))
901901
return c2py(<rcp_const_basic>_num), c2py(<rcp_const_basic>_den)
902902

903+
def as_real_imag(Basic self not None):
904+
cdef rcp_const_basic _real, _imag
905+
symengine.as_real_imag(self.thisptr, symengine.outArg(_real), symengine.outArg(_imag))
906+
return c2py(<rcp_const_basic>_real), c2py(<rcp_const_basic>_imag)
907+
903908
def n(self, prec = 53, real = False):
904909
if real:
905910
return eval_real(self, prec)

symengine/tests/test_arit.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from symengine.utilities import raises
22

33
from symengine import Symbol, Integer, Add, Mul, Pow, Rational, sqrt
4-
from symengine.lib.symengine_wrapper import Zero, One, NegativeOne, Half
4+
from symengine.lib.symengine_wrapper import Zero, One, NegativeOne, Half, I
55

66

77
def test_arit1():
@@ -165,6 +165,11 @@ def test_as_numer_denom():
165165
assert x == Integer(-5)
166166
assert y == Integer(1)
167167

168+
def test_as_real_imag():
169+
x, y = (5 + 6 * I).as_real_imag()
170+
171+
assert x == 5
172+
assert y == 6
168173

169174
def test_from_args():
170175
x = Symbol("x")

0 commit comments

Comments
 (0)