| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
The function ulong_from_little_endian is endian-agnostic and was tested by forcing is_big_endian=1 on a little-endian system. |
Sorry, something went wrong.
|
Since this PR seems to give performance on par with gmpy2 it is unclear whether PEP 757 will be even necessary. I have not been able to build #64 for comparison Also, it should work with older Python versions. |
Sorry, something went wrong.
|
The PEP 757 interface is provided as CPython's best effort to give something efficient for this using public API in Python 3.14 onwards. I think that should be the baseline before trying any other approach. |
Sorry, something went wrong.
|
Interesting, conversion to int seems asymptotically faster with this approach (c.f. using mpz_export). Perhaps, it could be a little better with new PyLong_*Bytes*() C-API. Below my benchmarks. I would appreciate if someone could repeat this on less noisy system.
No, gmpy2 uses PEP 757 API (using pythoncapi-compat for <3.14). Import (int -> mpz)
Export (mpz -> int)
Could someone trigger CI tests in this pr (build logs are expired)? benchmark scripts# bench-import.py
import os
import pyperf
_T = os.getenv('_T')
if _T == "gmpy2.mpz":
from gmpy2 import mpz
elif _T == "gmp.mpz":
from gmp import mpz
else:
from flint import fmpz as mpz
cases = ['1<<7', '1<<38', '1<<300', '1<<3000', '1<<10000']
runner = pyperf.Runner()
for c in cases:
i = eval(c)
runner.bench_func(c, mpz, i)# bench-export.py
import os
import pyperf
_T = os.getenv('_T')
if _T == "gmpy2.mpz":
from gmpy2 import mpz
elif _T == "gmp.mpz":
from gmp import mpz
else:
from flint import fmpz as mpz
cases = ['1<<7', '1<<38', '1<<300', '1<<3000', '1<<10000']
runner = pyperf.Runner()
for c in cases:
i = eval(c)
m = mpz(i)
runner.bench_func(c, int, m) |
Sorry, something went wrong.
I think that python-flint should do the same. |
Sorry, something went wrong.
|
After timings above and in gh-358 I think it turns out that the approach in this PR is the best one for python-flint. For now it seems that PEP 757 along with GMP's import/export functions is slower than using to_bytes and from_bytes. |
Sorry, something went wrong.
|
CI checks here should pass after gh-359 |
Sorry, something went wrong.
|
Okay, looks good. Well get this in for now and can consider later if any other approach seems to time faster. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This is a proposal to handle issue #159 for Python versions below 3.14 (for example Ubuntu 24.04 LTS uses Python 3.12).
The idea is to use standard int methods (from_bytes, to_bytes) to obtain a binary serialization, then cast the byte array to ulong.
Special care is needed for big-endian platforms, however I am unable to test whether the patch proposal is correct for big-endian platforms. Let me know what would be the preferred approach.
Benchmarks done using %timeit in iPython with Python 3.13
AFAIK gmpy2 uses private Python stuff already so it might be difficult to do better.
(edited for changes in commit f349183 for negative numbers)