Skip to content

Commit

Permalink
Try to add work-around for sympy/sympy#26645
Browse files Browse the repository at this point in the history
  • Loading branch information
bjodah committed May 31, 2024
1 parent dd3dc6e commit 4204b2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions symengine/lib/symengine_wrapper.in.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ try:
except ImportError:
have_numpy = False

try:
import flint as _flint
have_flint_py = True
except ImportError:
_flint = None
have_flint_py = False


class SympifyError(Exception):
pass
Expand Down Expand Up @@ -499,6 +506,17 @@ def sympy2symengine(a, raise_error=False):
elif isinstance(a, sympy.ConditionSet):
return conditionset(*(a.args))

if have_flint_py:
if isinstance(a, _flint.types.nmod.nmod):
# Work around for sympy/sympy#26645
class _modular_integer(sympy.polys.domains.modularinteger.ModularInteger):
mod = int(a.modulus())
dom = sympy.polys.domains.ZZ
sym = True

b = _modular_integer(int(a))
return PyNumber(b, sympy_module)

if raise_error:
raise SympifyError(("sympy2symengine: Cannot convert '%r' (of type %s)"
" to a symengine type.") % (a, type(a)))
Expand Down
1 change: 1 addition & 0 deletions symengine/tests/test_sympy_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ def test_pynumber():
assert isinstance(b, PyNumber)
assert b == a # Check equality via SymEngine
assert a == b # Check equality via SymPy
assert (b-a).simplify() == 0
assert str(a) == str(b)

a = 1 - a
Expand Down

0 comments on commit 4204b2d

Please sign in to comment.