diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 739a432..a22211f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,10 @@ Version 3.0.2 (in development) ------------------------------ +* Support not just Fraction and int types as inputs for gmp values, + but every type with denominator and numerator attributes (such as numpy's + int32 and int64, and gmpy2's mpq). + Version 3.0.1 (22 November 2024) -------------------------------- diff --git a/pyproject.toml b/pyproject.toml index 677bc13..786d3c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,3 +53,7 @@ cdd = ["py.typed"] [tool.mypy] files = ["src/**/*.pyi", "test/**/*.py", "docs/**/*.py"] disallow_untyped_defs = true + +[[tool.mypy.overrides]] +module = "gmpy2" +ignore_missing_imports = true diff --git a/test/gmp/__init__.py b/test/gmp/__init__.py index 1360a0f..9db7ff0 100644 --- a/test/gmp/__init__.py +++ b/test/gmp/__init__.py @@ -1,8 +1,13 @@ from collections.abc import Iterable -from fractions import Fraction -from typing import Union +from typing import Any, Protocol -Rational = Union[int, Fraction] + +class Rational(Protocol): + @property + def numerator(self) -> int: ... + @property + def denominator(self) -> int: ... + def __eq__(self, other: Any) -> bool: ... def assert_exactly_equal(x: Rational, y: Rational) -> None: diff --git a/test/gmp/test_gmpy2.py b/test/gmp/test_gmpy2.py new file mode 100644 index 0000000..aae73b1 --- /dev/null +++ b/test/gmp/test_gmpy2.py @@ -0,0 +1,19 @@ +from collections.abc import Sequence +from test.gmp import assert_matrix_exactly_equal + +from gmpy2 import mpq + +import cdd +import cdd.gmp + + +def test_numpy() -> None: + q0 = mpq(0) + q1 = mpq(1) + arr: Sequence[Sequence[mpq]] = [[q1, q0, q0], [q1, q1, q0], [q1, q0, q1]] + ref_ineq: Sequence[Sequence[mpq]] = [[q1, -q1, -q1], [q0, q1, q0], [q0, q0, q1]] + mat = cdd.gmp.matrix_from_array(arr) + mat.rep_type = cdd.RepType.GENERATOR + cdd_poly = cdd.gmp.polyhedron_from_matrix(mat) + ineq = cdd.gmp.copy_inequalities(cdd_poly).array + assert_matrix_exactly_equal(ref_ineq, ineq)