Skip to content

Commit

Permalink
Add test for gmpy2, add changelog.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmtroffaes committed Dec 16, 2024
1 parent e5d3ebb commit 0746674
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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)
--------------------------------

Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 8 additions & 3 deletions test/gmp/__init__.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
19 changes: 19 additions & 0 deletions test/gmp/test_gmpy2.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0746674

Please sign in to comment.