Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symengine .subs is calling back to Python #410

Open
peendebak opened this issue Jun 29, 2022 · 3 comments
Open

Symengine .subs is calling back to Python #410

peendebak opened this issue Jun 29, 2022 · 3 comments

Comments

@peendebak
Copy link

When executing the symengine subs on just basic types a callback to the python interpreter is make. A minimal example:

import symengine
x,y=symengine.symbols('x, y')
f=x*x+y*y/2
f.subs({x: 1.0, y: x}) # this triggers __instancecheck__ from abc.py

When profiling the expression (with cProfile + snakeviz) we get:

image
(the magenta block is the call back to python)

If the call back to the python interpreter can be avoided, the code is more efficient.

@lucienwang1009
Copy link

lucienwang1009 commented Jul 19, 2022

Meet the same issue. Hope it would be fixed.


PyObject_TypeCheck might be an alternative?

@rikardn
Copy link
Contributor

rikardn commented Aug 4, 2022

Thanks for reporting this.

A quick glance at the source makes me guess it is DictBasic that inherits from abc.MutableMapping. Do we have to do this?

There is also the BasicMeta, but it doesn't seem to be used anywhere. Can this be removed?

@isuruf
Copy link
Member

isuruf commented Mar 20, 2023

This is because we have to check the type of the keys and values of the dictionary and convert all of them to Basic types. If you are re-using the dictionary, then you can create a DictBasic dictionary so that the type checks are not done repeatedly. If you are using the dictionary once, there's very little we can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants