From ef7597994ddb289e7b1a0003a3cad8836b8cc998 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 3 Feb 2019 18:14:48 +0300 Subject: [PATCH] Return passed in function in defun* decorators This turn on more doctests, e.g.: $ py.test mpmath/functions/qfunctions.py ============================= test session starts ============================== platform linux -- Python 3.7.1, pytest-4.2.0, py-1.7.0, pluggy-0.8.1 hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/home/sk/src/mpmath/.hypothesis/examples') rootdir: /home/sk/src/mpmath, inifile: setup.cfg plugins: xdist-1.26.1, timeout-1.3.3, forked-1.0.1, cov-2.6.1, hypothesis-4.4.3 collected 4 items mpmath/functions/qfunctions.py .... [100%] =========================== 4 passed in 0.49 seconds =========================== Some doctests were adapted. --- mpmath/function_docs.py | 8 ++++---- mpmath/functions/functions.py | 3 +++ mpmath/functions/zeta.py | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/mpmath/function_docs.py b/mpmath/function_docs.py index 1d18ccc5..6f5ad759 100644 --- a/mpmath/function_docs.py +++ b/mpmath/function_docs.py @@ -9770,8 +9770,8 @@ on the unit sphere:: >>> Y1 = lambda t,p: fp.spherharm(l1,m1,t,p) >>> Y2 = lambda t,p: fp.conj(fp.spherharm(l2,m2,t,p)) >>> l1 = l2 = 3; m1 = m2 = 2 - >>> print(fp.quad(lambda t,p: Y1(t,p)*Y2(t,p)*dS(t,p), *sphere)) - (1+0j) + >>> fp.chop(fp.quad(lambda t,p: Y1(t,p)*Y2(t,p)*dS(t,p), *sphere)) + 1.0000000000000007 >>> m2 = 1 # m1 != m2 >>> print(fp.chop(fp.quad(lambda t,p: Y1(t,p)*Y2(t,p)*dS(t,p), *sphere))) 0.0 @@ -10011,7 +10011,7 @@ Pass ``exact=True`` to obtain exact values of Stirling numbers as integers:: >>> stirling1(42, 5) -2.864498971768501633736628e+50 - >>> print stirling1(42, 5, exact=True) + >>> print(stirling1(42, 5, exact=True)) -286449897176850163373662803014001546235808317440000 """ @@ -10045,7 +10045,7 @@ Pass ``exact=True`` to obtain exact values of Stirling numbers as integers:: >>> stirling2(52, 10) 2.641822121003543906807485e+45 - >>> print stirling2(52, 10, exact=True) + >>> print(stirling2(52, 10, exact=True)) 2641822121003543906807485307053638921722527655 diff --git a/mpmath/functions/functions.py b/mpmath/functions/functions.py index f03c5974..4cdf5dd9 100644 --- a/mpmath/functions/functions.py +++ b/mpmath/functions/functions.py @@ -80,12 +80,15 @@ class SpecialFunctions(object): def defun_wrapped(f): SpecialFunctions.defined_functions[f.__name__] = f, True + return f def defun(f): SpecialFunctions.defined_functions[f.__name__] = f, False + return f def defun_static(f): setattr(SpecialFunctions, f.__name__, f) + return f @defun_wrapped def cot(ctx, z): return ctx.one / ctx.tan(z) diff --git a/mpmath/functions/zeta.py b/mpmath/functions/zeta.py index a21dc99a..a81041b2 100644 --- a/mpmath/functions/zeta.py +++ b/mpmath/functions/zeta.py @@ -938,8 +938,8 @@ def secondzeta(ctx, s, a = 0.015, **kwargs): 0.023104993115419 >>> xi = lambda s: 0.5*s*(s-1)*pi**(-0.5*s)*gamma(0.5*s)*zeta(s) >>> Xi = lambda t: xi(0.5+t*j) - >>> -0.5*diff(Xi,0,n=2)/Xi(0) - (0.023104993115419 + 0.0j) + >>> chop(-0.5*diff(Xi,0,n=2)/Xi(0)) + 0.023104993115419 We may ask for an approximate error value::