-
Notifications
You must be signed in to change notification settings - Fork 35
Use PEP 757 API for fmpz <-> int conversions #358
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
base: main
Are you sure you want to change the base?
Conversation
The way to do it is to move the conditional compilation to C e.g.: python-flint/src/flint/flintlib/types/fmpz_mod_mat_compat.pxd Lines 4 to 14 in b2b71f4
|
Is there anything that can improve this either in CPython or GMP? Or should we just conclude that for python-flint the approach in gh-324 is best? The approach in gh-324 seems simpler and works for all supported CPython versions without needing any conditional compilation. What are gmpy2 or python-gmp going to use? |
Yes, makes sense. I think it should be possible to expose simple wrappers like gmpy2's
I don't think that something can be impoved on CPython side, at least not for "big enough" integers. The PEP 757 API provides raw access to the "array of digits" view for CPython int's. Though, maybe mpz_import/export() could be improved.
Unfortunately, #324 approach can't be translated to C easily for all supported CPython versions. Probably, I'll keep the current solution, but will benchmark also new approach (PyLong_AsNativeBytes/PyLong_FromNativeBytes). |
Without having looked at the code my guess would be that because these functions are quite general they end up being less efficient than |
|
Okay thanks @skirpichev for the benchmarks here. This PR was useful but I think what it proves is that we should go with gh-324 instead. |
Actually perhaps it suggests that we should not use |
Closes #159
This lacks implementation for Python < 3.14. Not sure how to do this better, conditional compilation seems to be deprecated by Cython.
To my surprise, #324 approach seems to be better. Here my benchmarks.
Export
Import
Details