Skip to content

Commit 3950f40

Browse files
committed
replace wrongly placed sig_on/off pair with sig_check
fixes the bug noted in mpmath/mpmath#723 sage: from mpmath import * sage: mp.dps=16 sage: zeta(-0.01 + 1000j) --------------------------------------------------------------------------- SystemError Traceback (most recent call last) Cell In [3], line 1 ----> 1 zeta(-RealNumber('0.01') + ComplexNumber(0, '1000')) File /usr/lib/python3.11/site-packages/mpmath/functions/zeta.py:580, in zeta(ctx, s, a, derivative, method, **kwargs) 578 if ctx.re(s) > 2*ctx.prec and a == 1 and not derivative: 579 return ctx.one + ctx.power(2, -s) --> 580 return +ctx._hurwitz(s, a, d, **kwargs) File /usr/lib/python3.11/site-packages/mpmath/functions/zeta.py:595, in _hurwitz(ctx, s, a, d, **kwargs) 593 print("zeta: Attempting reflection formula") 594 try: --> 595 return _hurwitz_reflection(ctx, s, a, d, atype) 596 except NotImplementedError: 597 pass File /usr/lib/python3.11/site-packages/mpmath/functions/zeta.py:654, in _hurwitz_reflection(ctx, s, a, d, atype) 652 p += shift*q 653 assert 1 <= p <= q --> 654 g = ctx.fsum(ctx.cospi(t/2-2*k*b)*ctx._hurwitz(t,(k,q)) \ 655 for k in range(1,q+1)) 656 g *= 2*ctx.gamma(t)/(2*ctx.pi*q)**t 657 v += g File /mnt/opt/Sage/sage-dev/src/sage/libs/mpmath/ext_main.pyx:767, in sage.libs.mpmath.ext_main.Context.fsum() 765 workopts.rounding = ROUND_D 766 unknown = global_context.zero --> 767 sig_on() 768 try: # Way down, there is a ``finally`` with sig_off() 769 MPF_init(&sre) SystemError: calling remove_from_pari_stack() inside sig_on()
1 parent 2f1a76d commit 3950f40

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/sage/libs/mpmath/ext_main.pyx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ from cpython.float cimport *
1919
from cpython.complex cimport *
2020
from cpython.number cimport *
2121

22-
from cysignals.signals cimport sig_on, sig_off
22+
from cysignals.signals cimport sig_check
2323

2424
from sage.ext.stdsage cimport PY_NEW
2525

@@ -707,7 +707,6 @@ cdef class Context:
707707
False
708708
sage: isint(3+2j, gaussian=True)
709709
True
710-
711710
"""
712711
cdef MPF v
713712
cdef MPF w
@@ -745,15 +744,23 @@ cdef class Context:
745744
faster and produces more accurate results than the builtin
746745
Python function :func:`sum`.
747746
747+
With squared=True each term is squared, and with absolute=True
748+
the absolute value of each term is used.
749+
748750
TESTS ::
749751
750752
sage: from mpmath import mp, fsum
751753
sage: mp.dps = 15; mp.pretty = False
752754
sage: fsum([1, 2, 0.5, 7])
753755
mpf('10.5')
754756
755-
With squared=True each term is squared, and with absolute=True
756-
the absolute value of each term is used.
757+
Check that the regression from `mpmath/issues/723 <https://github.com/mpmath/mpmath/issues/723>`__
758+
has been fixed::
759+
760+
sage: from mpmath import *
761+
sage: mp.dps=16
762+
sage: zeta(-0.01 + 1000j)
763+
mpc(real='-8.9714595...', imag='8.7321793...')
757764
"""
758765
cdef MPF sre, sim, tre, tim, tmp
759766
cdef mpf rr
@@ -764,8 +771,8 @@ cdef class Context:
764771
workopts.prec = workopts.prec * 2 + 50
765772
workopts.rounding = ROUND_D
766773
unknown = global_context.zero
767-
sig_on()
768-
try: # Way down, there is a ``finally`` with sig_off()
774+
try:
775+
sig_check()
769776
MPF_init(&sre)
770777
MPF_init(&sim)
771778
MPF_init(&tre)
@@ -848,8 +855,8 @@ cdef class Context:
848855
MPF_clear(&sre)
849856
MPF_clear(&sim)
850857
return +unknown
851-
finally:
852-
sig_off()
858+
except KeyboardInterrupt:
859+
raise KeyboardInterrupt('Ctlr-C has been pressed')
853860

854861
def fdot(ctx, A, B=None, bint conjugate=False):
855862
r"""

0 commit comments

Comments
 (0)