Skip to content

Commit 7d142ae

Browse files
committed
Minor Improvement to Sympification of Tuples and Lists
1 parent d94fdc0 commit 7d142ae

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

symengine/lib/symengine_wrapper.pyx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,16 @@ def sympify(a):
460460
"""
461461
if isinstance(a, str):
462462
return c2py(symengine.parse(a.encode("utf-8")))
463+
elif isinstance(a, tuple):
464+
v = []
465+
for e in a:
466+
v.append(sympify(e))
467+
return tuple(v)
468+
elif isinstance(a, list):
469+
v = []
470+
for e in a:
471+
v.append(sympify(e))
472+
return v
463473
return _sympify(a, True)
464474

465475

@@ -494,16 +504,6 @@ def _sympify(a, raise_error=True):
494504
return RealDouble(a)
495505
elif isinstance(a, complex):
496506
return ComplexDouble(a)
497-
elif isinstance(a, tuple):
498-
v = []
499-
for e in a:
500-
v.append(_sympify(e, True))
501-
return tuple(v)
502-
elif isinstance(a, list):
503-
v = []
504-
for e in a:
505-
v.append(_sympify(e, True))
506-
return v
507507
elif hasattr(a, '_symengine_'):
508508
return _sympify(a._symengine_(), raise_error)
509509
elif hasattr(a, '_sympy_'):

symengine/tests/test_sympify.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def test_sympify1():
99
assert sympify(2) != Integer(1)
1010
assert sympify(-5) == Integer(-5)
1111
assert sympify(Integer(3)) == Integer(3)
12+
assert sympify(('0', '0')) == (0, 0)
13+
assert sympify(['0', '0']) == [0, 0]
1214
assert sympify("3+5") == Integer(8)
1315
assert true == sympify(True)
1416
assert false == sympify(False)

0 commit comments

Comments
 (0)