Skip to content

Commit 22b4e5a

Browse files
committed
Add tests and docstring
1 parent cd11057 commit 22b4e5a

3 files changed

Lines changed: 52 additions & 56 deletions

File tree

src/flint/test/test_acb_theta.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,22 @@ def test_acb_theta_shape_assertions() -> None:
4545

4646
assert raises(lambda: acb_theta(object(), tau), TypeError) # type: ignore[arg-type]
4747
assert raises(lambda: acb_theta(z, object()), TypeError) # type: ignore[arg-type]
48+
49+
def test_acb_theta_jets_basic() -> None:
50+
if not _has_acb_theta():
51+
return
52+
53+
from flint.types.acb_theta import acb_theta_jets
54+
55+
z = acb(1 + 1j)
56+
tau = acb(1.25 + 3j)
57+
zmat = acb_mat([[z]])
58+
taumat = acb_mat([[tau]])
59+
ord = 2
60+
61+
direct = acb_theta_jets(zmat, taumat, ord)
62+
via_method = taumat.theta_jets(zmat, ord)
63+
assert is_close(direct, via_method, tol=1e-12, rel_tol=1e-12, max_width=1e-12)
64+
assert direct.nrows() == 4
65+
assert direct.ncols() == 3
66+

src/flint/types/acb_mat.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ cdef class acb_mat(flint_mat):
840840
raise NotImplementedError("acb_mat.theta needs Flint >= 3.1.0")
841841
return acb_theta(z, tau, square=square)
842842

843-
def theta_jets(tau, z, ord, square=False):
843+
def theta_jets(tau, z, ord):
844844
r"""
845845
Computes Taylor approximation for the vector-valued Riemann theta function
846846
`(\theta_{a,b}(z, \tau) : a, b \in \{0,1\}^{g})` or its squares,
@@ -857,4 +857,4 @@ cdef class acb_mat(flint_mat):
857857
from .acb_theta import acb_theta_jets
858858
except ImportError:
859859
raise NotImplementedError("acb_mat.theta needs Flint >= 3.1.0")
860-
return acb_theta_jets(z, tau, ord, square=square)
860+
return acb_theta_jets(z, tau, ord)

src/flint/types/acb_theta.pyx

Lines changed: 31 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,48 @@ def acb_theta(acb_mat z, acb_mat tau, ulong square=False):
9797
return acb_mat([res])
9898

9999

100-
def acb_theta_jets(acb_mat z, acb_mat tau, slong ord, ulong square=False):
100+
def acb_theta_jets(acb_mat z, acb_mat tau, slong ord):
101101
r"""
102-
Corrected wrapper for acb_theta_jet to handle multivariate Taylor expansions.
102+
Computes the coefficients of the Taylor expansion of the vector valued Riemann
103+
theta function `(\theta_{a,b}(z, \tau) : a, b \in \{0,1\}^{g})` or its squares.
104+
105+
This is a wrapper for the C-function
106+
`acb_theta_jet <https://flintlib.org/doc/acb_theta.html#c.acb_theta_jet>`_
107+
and it follows the same conventions for the ordering of the theta characteristics.
108+
109+
This should be used via the method :meth:`.acb_mat.theta_jets`, explicitly ``tau.theta_jets(z, ord)``.
110+
111+
>>> from flint import acb, acb_mat, showgood, ctx
112+
>>> z = acb(1+1j); tau = acb(1.25+3j)
113+
>>> acb_mat([[tau]]).theta_jets(acb_mat([[z]]),2) # doctest: +SKIP
114+
[[0.969443038779670 +/- 5.67e-16] + [-0.0305569612081680 +/- 5.13e-17]j,
115+
[-0.191993710594950 +/- 4.89e-16] + [0.191993710747776 +/- 7.42e-16]j,
116+
[0.60317023860834 +/- 2.93e-15] + [0.60317023764810 +/- 4.86e-15]j]
117+
[[1.03055696119601 +/- 3.89e-15] + [0.0305569612081680 +/- 5.13e-17]j,
118+
[0.191993710594950 +/- 4.89e-16] + [-0.191993710442123 +/- 4.62e-16]j,
119+
[-0.60317023668787 +/- 5.90e-15] + [-0.60317023764810 +/- 4.86e-15]j]
120+
[[-1.22079026757697 +/- 4.36e-15] + [-1.82705551679115 +/- 5.17e-15]j,
121+
[-5.71849316258739 +/- 7.02e-15] + [3.82088827346268 +/- 5.75e-15]j,
122+
[6.0241074288587 +/- 3.88e-14] + [9.0163253443780 +/- 2.05e-14]j]
123+
[[-1.82023591012499 +/- 2.67e-15] + [1.21625195015448 +/- 4.14e-15]j,
124+
[3.8353056542516 +/- 4.99e-14] + [5.73981078971270 +/- 6.74e-15]j,
125+
[8.9823364151977 +/- 2.44e-14] + [-6.0022138700195 +/- 3.72e-14]j]
103126
"""
104127
g = tau.nrows()
105128
if g == 0:
106129
return []
107130

108-
# 1. Calculate the length of the jet for one characteristic
131+
# Calculate the length of the jet for one characteristic
109132
# This is the number of multi-indices (alpha) such that |alpha| < ord
110133
cdef slong nj = acb_theta_jet_nb(g, ord)
111134

112-
# 2. Total number of characteristics
135+
# Total number of characteristics
113136
cdef slong nb = 1 << (2 * g)
114137

115-
# 3. Total number of acb elements to allocate
138+
# Total number of acb elements to allocate
116139
# FLINT stores nj coefficients for each of the nb characteristics
117140
cdef slong total_size = nb * nj
118141

119-
# Convert input z to acb_ptr
120142
cdef acb_ptr zvec = _acb_vec_init(g)
121143
cdef slong i, j
122144
for i in range(g):
@@ -126,6 +148,7 @@ def acb_theta_jets(acb_mat z, acb_mat tau, slong ord, ulong square=False):
126148
cdef slong nb_in = 1 # Number of input z vectors
127149
cdef ulong ab = 0 # Base characteristic
128150
cdef ulong all = True # Compute all 2^2g characteristics
151+
cdef ulong square = False # Don't compute the squares of the thetas.
129152

130153
# Initialize the output buffer
131154
cdef acb_ptr theta = _acb_vec_init(total_size)
@@ -134,7 +157,7 @@ def acb_theta_jets(acb_mat z, acb_mat tau, slong ord, ulong square=False):
134157
# Note: Computes all partial derivatives up to total order 'ord'
135158
acb_theta_jet(theta, zvec, nb_in, tau.val, ord, ab, all, square, getprec())
136159

137-
# 4. Copy the output into a structured format
160+
# Copy the output into a structured format
138161
# We return a list of lists: res[char_idx] = [coeff_0, coeff_1, ...]
139162
res = []
140163
cdef acb r
@@ -151,50 +174,4 @@ def acb_theta_jets(acb_mat z, acb_mat tau, slong ord, ulong square=False):
151174
_acb_vec_clear(zvec, g)
152175
_acb_vec_clear(theta, total_size)
153176

154-
return res
155-
156-
157-
#def acb_theta_jet(acb_mat z, acb_mat tau, slong ord, ulong square=False):
158-
# r"""
159-
# Computes derivatives of the vector valued Riemann theta function
160-
# `(\theta_{a,b}(z, \tau) : a, b \in \{0,1\}^{g})` or its squares.
161-
#
162-
# This is a wrapper for the C-function
163-
# `acb_theta_jet <https://flintlib.org/doc/acb_theta.html#c.acb_theta_jet>`_
164-
# and it follows the same conventions for the ordering of the theta characteristics.
165-
#
166-
# This should be used via the method :meth:`.acb_mat.theta`, explicitly ``tau.theta(z)``.
167-
# """
168-
# g = tau.nrows()
169-
# assert tau.ncols() == g
170-
# assert z.nrows() == g
171-
# assert z.ncols() == 1
172-
#
173-
# # convert input
174-
# cdef acb_ptr zvec
175-
# zvec = _acb_vec_init(g)
176-
# cdef long i
177-
# for i in range(g):
178-
# acb_set(zvec + i, acb_mat_entry(z.val, i, 0))
179-
# cdef slong nb_in = 1
180-
# cdef ulong ab = 0
181-
# cdef ulong all = True
182-
#
183-
# # initialize the output
184-
# cdef slong nb = 1 << (2 * g)
185-
# # 1. Calculate the length of the jet for one characteristic
186-
# # This is the number of multi-indices (alpha) such that |alpha| < ord
187-
# cdef slong nj = acb_theta_jet_len(g, ord)
188-
# cdef acb_ptr theta = _acb_vec_init(nb)
189-
#
190-
# acb_theta_jet(theta, zvec, nb_in, tau.val, ord, ab, all, square, getprec())
191-
# _acb_vec_clear(zvec, g)
192-
# # copy the output
193-
# res = []
194-
# cdef acb r
195-
# for i in range(nb):
196-
# r = acb.__new__(acb)
197-
# acb_set(r.val, theta + i)
198-
# res.append(r)
199-
# _acb_vec_clear(theta, nb)
200-
# return acb_mat([res])
177+
return acb_mat(res)

0 commit comments

Comments
 (0)