Skip to content

Commit cf2d330

Browse files
committed
Add _has_acb_theta function
1 parent 8b4c20d commit cf2d330

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

src/flint/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@
5050

5151
__version__ = "0.8.0"
5252

53+
54+
def _flint_version_at_least(major: int, minor: int) -> bool:
55+
version_parts = __FLINT_VERSION__.split(".")
56+
if len(version_parts) < 2:
57+
return False
58+
try:
59+
current_major = int(version_parts[0])
60+
current_minor = int(version_parts[1])
61+
except ValueError:
62+
return False
63+
return (current_major, current_minor) >= (major, minor)
64+
65+
66+
def _has_acb_theta() -> bool:
67+
return _flint_version_at_least(3, 1)
68+
69+
5370
__all__ = [
5471
"ctx",
5572
"fmpz",

src/flint/test/test_acb_mat.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
from unittest.mock import patch
55

6-
from flint import acb, acb_mat, arb_mat, ctx, fmpq_mat, fmpz_mat
6+
from flint import _has_acb_theta, acb, acb_mat, arb_mat, ctx, fmpq_mat, fmpz_mat
77
from flint.test.helpers import is_close_acb, is_close_acb_mat as is_close, is_close_arb_mat, raises
88

99

@@ -304,10 +304,13 @@ def test_acb_mat_eig_theta_and_helper() -> None:
304304
assert acb_mat(0, 0).eig() == []
305305

306306
tau = acb_mat([[1j]])
307-
theta_vals = acb_mat.theta(tau, acb_mat([[0]]))
308-
assert isinstance(theta_vals, acb_mat)
309-
assert theta_vals.nrows() == 1
310-
assert theta_vals.ncols() == 4
307+
if _has_acb_theta():
308+
theta_vals = acb_mat.theta(tau, acb_mat([[0]]))
309+
assert isinstance(theta_vals, acb_mat)
310+
assert theta_vals.nrows() == 1
311+
assert theta_vals.ncols() == 4
312+
else:
313+
assert raises(lambda: acb_mat.theta(tau, acb_mat([[0]])), NotImplementedError)
311314

312315
with patch.dict(sys.modules, {"flint.types.acb_theta": None}):
313316
assert raises(lambda: acb_mat.theta(tau, acb_mat([[0]])), NotImplementedError)

src/flint/test/test_acb_theta.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
from __future__ import annotations
22

3-
from flint import acb, acb_mat
3+
from flint import _has_acb_theta, acb, acb_mat
44
from flint.test.helpers import is_close_acb_mat as is_close, raises
55

66

7-
def _acb_theta_importable() -> bool:
8-
try:
9-
from flint.types.acb_theta import acb_theta as _ # noqa: F401
10-
return True
11-
except ImportError:
12-
return False
13-
14-
157
def test_acb_theta_basic() -> None:
16-
if not _acb_theta_importable():
8+
if not _has_acb_theta():
179
return
1810

1911
from flint.types.acb_theta import acb_theta
@@ -35,7 +27,7 @@ def test_acb_theta_basic() -> None:
3527

3628

3729
def test_acb_theta_shape_assertions() -> None:
38-
if not _acb_theta_importable():
30+
if not _has_acb_theta():
3931
return
4032

4133
from flint.types.acb_theta import acb_theta

0 commit comments

Comments
 (0)