symengine.py
symengine.py copied to clipboard
creating a Function results in a segfault
I am currently trying to implement a custom function creation that works with both sympy and symengine as a backend. For this I looked at the example at https://docs.sympy.org/latest/modules/functions/index.html, but for the equivalent implementation in symengine I get a segmentation fault!
>>> import sympy, symengine
>>> for backend in sympy, symengine:
... print(backend.__name__, backend.__version__)
...
... class my_func(backend.Function):
... @classmethod
... def eval(cls, x):
... if x.is_Number:
... if x.is_zero:
... return backend.S.One
... elif x is backend.S.Infinity:
... return backend.S.Zero
... def _eval_is_real(self):
... return self.args[0].is_real
... print(my_func(0))
...
sympy 1.6.2
1
symengine 0.6.1
Segmentation fault: 11
If instead I change from the class definition to a call to backend.Function and subsequently add the corresponding methods to the new type I don't get the segfault but simplification doesn't work for symengine.
>>> import sympy, symengine
>>> for backend in sympy, symengine:
... print(backend.__name__, backend.__version__)
...
... # class my_func(backend.Function):
... @classmethod
... def eval(cls, x):
... if x.is_Number:
... if x.is_zero:
... return backend.S.One
... elif x is backend.S.Infinity:
... return backend.S.Zero
... def _eval_is_real(self):
... return self.args[0].is_real
... my_func = backend.Function('my_func')
... my_func.eval = eval
... my_func._eval_is_real = _eval_is_real
... print(my_func(0))
...
sympy 1.6.2
1
symengine 0.6.1
my_func(0)
The _eval_is_real and eval are currently not supported by symengine.