Cleanup jtheta()
* normalize result * use extraprec context manager * add error message
This commit is contained in:
@@ -856,9 +856,7 @@ def jtheta(ctx, n, z, q, derivative=0):
|
|||||||
extra += 2*abs(M)
|
extra += 2*abs(M)
|
||||||
cz = 0.5
|
cz = 0.5
|
||||||
extra2 = 50
|
extra2 = 50
|
||||||
prec0 = ctx.prec
|
with ctx.extraprec(extra):
|
||||||
try:
|
|
||||||
ctx.prec += extra
|
|
||||||
if n in [1, 2]:
|
if n in [1, 2]:
|
||||||
z_inner = z - ctx.pi/2 if n == 1 else z
|
z_inner = z - ctx.pi/2 if n == 1 else z
|
||||||
if z.imag:
|
if z.imag:
|
||||||
@@ -882,7 +880,5 @@ def jtheta(ctx, n, z, q, derivative=0):
|
|||||||
else:
|
else:
|
||||||
res = ctx._djacobi_theta3(z, q_inner, nd)
|
res = ctx._djacobi_theta3(z, q_inner, nd)
|
||||||
else:
|
else:
|
||||||
raise ValueError
|
raise ValueError("First argument expected to be 1, 2, 3 or 4")
|
||||||
finally:
|
return +res
|
||||||
ctx.prec = prec0
|
|
||||||
return res
|
|
||||||
|
|||||||
@@ -213,6 +213,12 @@ def test_jtheta_issue_79():
|
|||||||
r = jtheta(3, 4.5, 0.25, 50)
|
r = jtheta(3, 4.5, 0.25, 50)
|
||||||
assert r.ae('-6148327726309051673317975084654262.4119215720343656')
|
assert r.ae('-6148327726309051673317975084654262.4119215720343656')
|
||||||
|
|
||||||
|
def test_jtheta_invalid_n():
|
||||||
|
pytest.raises(ValueError, jtheta, 5, 0.5, 0.3)
|
||||||
|
pytest.raises(ValueError, jtheta, 0, 0.5, 0.3)
|
||||||
|
pytest.raises(ValueError, jtheta, 5, 0.5, 0.3)
|
||||||
|
pytest.raises(ValueError, jtheta, 0, 0.5, 0.3)
|
||||||
|
|
||||||
def test_jtheta_identities():
|
def test_jtheta_identities():
|
||||||
"""
|
"""
|
||||||
Tests the some of the jacobi identidies found in Abramowitz,
|
Tests the some of the jacobi identidies found in Abramowitz,
|
||||||
|
|||||||
Reference in New Issue
Block a user