|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from flint import acb, acb_mat |
| 4 | +from flint.test.helpers import is_close_acb_mat as is_close, raises |
| 5 | + |
| 6 | + |
| 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 | + |
| 15 | +def test_acb_theta_basic() -> None: |
| 16 | + if not _acb_theta_importable(): |
| 17 | + return |
| 18 | + |
| 19 | + from flint.types.acb_theta import acb_theta |
| 20 | + |
| 21 | + z = acb(1 + 1j) |
| 22 | + tau = acb(1.25 + 3j) |
| 23 | + zmat = acb_mat([[z]]) |
| 24 | + taumat = acb_mat([[tau]]) |
| 25 | + |
| 26 | + direct = acb_theta(zmat, taumat) |
| 27 | + via_method = taumat.theta(zmat) |
| 28 | + assert is_close(direct, via_method, tol=1e-12, rel_tol=1e-12, max_width=1e-12) |
| 29 | + assert direct.nrows() == 1 |
| 30 | + assert direct.ncols() == 4 |
| 31 | + |
| 32 | + squared = acb_theta(zmat, taumat, square=True) |
| 33 | + assert squared.nrows() == 1 |
| 34 | + assert squared.ncols() == 4 |
| 35 | + |
| 36 | + |
| 37 | +def test_acb_theta_shape_assertions() -> None: |
| 38 | + if not _acb_theta_importable(): |
| 39 | + return |
| 40 | + |
| 41 | + from flint.types.acb_theta import acb_theta |
| 42 | + |
| 43 | + z = acb_mat([[0]]) |
| 44 | + tau_bad = acb_mat([[1j, 0]]) |
| 45 | + assert raises(lambda: acb_theta(z, tau_bad), AssertionError) |
| 46 | + |
| 47 | + tau = acb_mat([[1j]]) |
| 48 | + z_bad_rows = acb_mat([[0], [0]]) |
| 49 | + assert raises(lambda: acb_theta(z_bad_rows, tau), AssertionError) |
| 50 | + |
| 51 | + z_bad_cols = acb_mat([[0, 0]]) |
| 52 | + assert raises(lambda: acb_theta(z_bad_cols, tau), AssertionError) |
| 53 | + |
| 54 | + assert raises(lambda: acb_theta(object(), tau), TypeError) # type: ignore[arg-type] |
| 55 | + assert raises(lambda: acb_theta(z, object()), TypeError) # type: ignore[arg-type] |
0 commit comments