Python Wrapper for GMP
This is another Python wrapper for GMP.
This wrapper is powered by cppyy, i.e., it wraps libgmpxx
, the C++ interface of GMP.
Comparison to Existing Wrappers
There might be others out there but we are aware of these Python wrappers for GMP.
This wrapper was born out of the necessity for a wrapper for the C++ interface of GMP for pyexactreal so the semantics are exactly the same as in the C++ interface and the Python code involved is quite minimal. It does not actually aim to compete with any of the existing wrappers, we just needed one that went through cppyy and broke it out of pyexactreal eventually. We have not done much benchmarking yet, however, there is certainly a lot of room for improvement1.
>>> import gmpxxyy, gmpy2
>>> a = gmpxxyy.mpz(1)
>>> %timeit a + a
1.34 µs ± 5.16 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
>>> a = gmpy2.mpz(1)
>>> %timeit a + a
57.3 ns ± 0.28 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
As another downside we have cppyy as a dependency which at the time of this writing is a very heavy one indeed.
Install with Conda
You can install this package with conda. Download and install Mambaforge, then run
mamba create -n gmpxxyy gmpxxyy
conda activate gmpxxyy
This installs the latest released version from conda-forge. Alternatively, you can also install the latest version from the flatsurf
channel by adding -c flatsurf
to the first command.
Run with binder in the Cloud
You can try out this project in a very limited environment online by clicking this link:
Build from the Source Code Repository
We are following an autoconf setup, i.e., you can install src/gmpxxyy
with
the following:
git clone --recurse-submodules https://github.com/flatsurf/gmpxxyy.git
cd gmpxxyy
./bootstrap
./configure
make
make check # to run our test suite
make install # to install into /usr/local
Maintainers
1 These benchmarks are not tuned in any way. I just typed them into a Python REPL on my Laptop with conda's IPython. This is not meant to be exact in any way, just to give you a very rough sense of what to expect. If I should really be benchmarking something else instead, please let me know :)