symforce-org / symforce

Fast symbolic computation, code generation, and nonlinear optimization for robotics
https://symforce.org
Apache License 2.0
1.41k stars 145 forks source link

Using custom functions with symengine #192

Open gcross-zipline opened 2 years ago

gcross-zipline commented 2 years ago

Not so much a feature request or issue as a general question about the implementation:

I'm wondering if it is possible to use custom functions w/ symengine. W/ SymPy itself you can inherit from sympy.Function to create one, and do the necessary customization on the code-printer during code-generation.

With symengine I'm not sure how one would achieve this. In my simple test, inheriting from sympy.Function resulted in a segfault somewhere (haven't traced this yet, but naive guess would be in symengine). symengine also doesn't understand sympy.UndefinedFunction either.

Do you know of a method for handling custom functions, other than falling back to plain sympy?

gcross-zipline commented 2 years ago

I stand corrected - it is possible actually. There was a missing import from symengine in symbolic.py (for UndefinedFunction). Will open a pull request.