Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-15-intel, macos-15,
windows-2022]
os: [ubuntu-24.04, ubuntu-24.04-arm, macos-26-intel, macos-26,
windows-2025]
msystem: [ucrt64]
menv: [ucrt-x86_64]
include:
Expand All @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: msys2/setup-msys2@v2.30.0
- uses: msys2/setup-msys2@v2.31.0
name: Setup msys2
with:
install: >-
Expand Down
1 change: 1 addition & 0 deletions bench/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ It's possible to run them also with gmpy2's and flint's integer types:
.. code:: sh

( export T="gmpy2.mpz"; \
export PYTHONPATH=. ; \
python bench/mul.py -q --copy-env --rigorous -o $T.json )

Beware, that the gmp prefers clang over gcc and extensions might
Expand Down
13 changes: 2 additions & 11 deletions bench/collatz.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
# collatz.py

import os
# bench/collatz.py

import pyperf

if os.getenv("T") == "gmpy2.mpz":
from gmpy2 import mpz
elif os.getenv("T") == "flint.fmpz":
from flint import fmpz as mpz
elif os.getenv("T") == "int":
mpz = int
else:
from gmp import mpz
from bench.utils import mpz

zero = mpz(0)
one = mpz(1)
Expand Down
12 changes: 12 additions & 0 deletions bench/harmonic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# bench/harmonic.py

from fractions import Fraction

import pyperf

from bench.utils import mpz, mysum

runner = pyperf.Runner()
for n in [100, 1000]:
xs = [Fraction(mpz(1), mpz(i)) for i in range(1, n + 1)]
runner.bench_func(f"H({n})", mysum, xs)
12 changes: 2 additions & 10 deletions bench/mul.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
# mul.py
# bench/mul.py

import os
from operator import mul

import pyperf

if os.getenv("T") == "gmpy2.mpz":
from gmpy2 import mpz
elif os.getenv("T") == "flint.fmpz":
from flint import fmpz as mpz
elif os.getenv("T") == "int":
mpz = int
else:
from gmp import mpz
from bench.utils import mpz

values = ["1<<7", "1<<38", "1<<300", "1<<3000"]

Expand Down
10 changes: 10 additions & 0 deletions bench/sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# bench/sum.py

import pyperf

from bench.utils import mpz, mysum

runner = pyperf.Runner()
for n in [100, 1000]:
xs = [mpz(i) for i in range(1, n + 1)]
runner.bench_func(f"sum({n})", mysum, xs)
17 changes: 17 additions & 0 deletions bench/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

if os.getenv("T") == "gmpy2.mpz":
from gmpy2 import mpz
elif os.getenv("T") == "flint.fmpz":
from flint import fmpz as mpz
elif os.getenv("T") == "int":
mpz = int
else:
pass


def mysum(xs):
total = xs[0]
for t in xs[1:]:
total += t
return t
95 changes: 43 additions & 52 deletions gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,22 +729,21 @@ str(PyObject *self)

#define Number_Check(op) (PyFloat_Check((op)) || PyComplex_Check((op)))

#define CHECK_OP(u, a) \
if (MPZ_Check(a)) { \
u = (MPZ_Object *)a; \
Py_INCREF(a); \
} \
else if (PyLong_Check(a)) { \
u = MPZ_from_int(a); \
if (!u) { \
goto end; \
} \
} \
else if (Number_Check(a)) { \
goto numbers; \
} \
else { \
goto fallback; \
#define CHECK_OP(u, a) \
if (MPZ_Check(a)) { \
u = (MPZ_Object *)Py_NewRef(a); \
} \
else if (PyLong_Check(a)) { \
u = MPZ_from_int(a); \
if (!u) { \
goto end; \
} \
} \
else if (Number_Check(a)) { \
goto numbers; \
} \
else { \
goto fallback; \
}

PyObject *
Expand Down Expand Up @@ -916,19 +915,18 @@ to_bool(PyObject *self)
return !zz_iszero(&((MPZ_Object *)self)->z);
}

#define CHECK_OPv2(u, a) \
if (MPZ_Check(a)) { \
u = (MPZ_Object *)a; \
Py_INCREF(a); \
} \
else if (PyLong_Check(a)) { \
; \
} \
else if (Number_Check(a)) { \
goto numbers; \
} \
else { \
goto fallback; \
#define CHECK_OPv2(u, a) \
if (MPZ_Check(a)) { \
u = (MPZ_Object *)Py_NewRef(a); \
} \
else if (PyLong_Check(a)) { \
; \
} \
else if (Number_Check(a)) { \
goto numbers; \
} \
else { \
goto fallback; \
}

#define BINOP(suff, slot) \
Expand Down Expand Up @@ -1004,8 +1002,7 @@ done: \
PyObject *uf, *vf, *rf; \
\
if (Number_Check(self)) { \
uf = self; \
Py_INCREF(uf); \
uf = Py_NewRef(self); \
} \
else { \
uf = to_float(self); \
Expand All @@ -1014,8 +1011,7 @@ done: \
} \
} \
if (Number_Check(other)) { \
vf = other; \
Py_INCREF(vf); \
vf = Py_NewRef(other); \
} \
else { \
vf = to_float(other); \
Expand Down Expand Up @@ -1309,8 +1305,7 @@ nb_truediv(PyObject *self, PyObject *other)
PyObject *uf, *vf;

if (Number_Check(self)) {
uf = self;
Py_INCREF(uf);
uf = Py_NewRef(self);
}
else {
uf = to_float(self);
Expand All @@ -1319,8 +1314,7 @@ nb_truediv(PyObject *self, PyObject *other)
}
}
if (Number_Check(other)) {
vf = other;
Py_INCREF(vf);
vf = Py_NewRef(other);
}
else {
vf = to_float(other);
Expand All @@ -1337,17 +1331,16 @@ nb_truediv(PyObject *self, PyObject *other)
return res;
}

#define CHECK_OP_INT(u, a) \
if (MPZ_Check(a)) { \
u = (MPZ_Object *)a; \
Py_INCREF(a); \
} \
else { \
u = MPZ_from_int(a); \
if (!u) { \
goto end; \
} \
} \
#define CHECK_OP_INT(u, a) \
if (MPZ_Check(a)) { \
u = (MPZ_Object *)Py_NewRef(a); \
} \
else { \
u = MPZ_from_int(a); \
if (!u) { \
goto end; \
} \
} \

#define BINOP_INT(suff) \
static PyObject * \
Expand Down Expand Up @@ -1527,8 +1520,7 @@ power(PyObject *self, PyObject *other, PyObject *module)
PyObject *uf, *vf;

if (Number_Check(self)) {
uf = self;
Py_INCREF(uf);
uf = Py_NewRef(self);
}
else {
uf = to_float(self);
Expand All @@ -1537,8 +1529,7 @@ power(PyObject *self, PyObject *other, PyObject *module)
}
}
if (Number_Check(other)) {
vf = other;
Py_INCREF(vf);
vf = Py_NewRef(other);
}
else {
vf = to_float(other);
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def pytest_report_header(config):
print(f"""
Using the ZZ library v{gmp._zz_version}

Bits per digit : {gmp.mpz_info.bits_per_digit}
sizeof(zz_digit_t): {gmp.mpz_info.sizeof_digit}
Maximal bit count : {gmp.mpz_info.bitcnt_max}
Bits per digit : {gmp.mpz_info.bits_per_digit}
sizeof(digit) : {gmp.mpz_info.sizeof_digit}
Maximal bit count: {gmp.mpz_info.bitcnt_max}

The gmp module v{gmp.__version__}
""")
Expand Down
Loading