import pytest from scipy.special._testutils import MissingModule, check_version from scipy.special._mptestutils import mp_assert_allclose from scipy.special._precompute.utils import lagrange_inversion try: import sympy # type: ignore[import] except ImportError: sympy = MissingModule('sympy') try: import mpmath as mp except ImportError: mp = MissingModule('mpmath') @pytest.mark.slow @check_version(sympy, '0.7') @check_version(mp, '0.19') class TestInversion: @pytest.mark.xfail_on_32bit("rtol only 2e-9, see gh-6938") def test_log(self): with mp.workdps(30): logcoeffs = mp.taylor(lambda x: mp.log(1 + x), 0, 10) expcoeffs = mp.taylor(lambda x: mp.exp(x) - 1, 0, 10) invlogcoeffs = lagrange_inversion(logcoeffs) mp_assert_allclose(invlogcoeffs, expcoeffs) @pytest.mark.xfail_on_32bit("rtol only 1e-15, see gh-6938") def test_sin(self):
the implementation of mp_hyp2f1 below, which modifies mpmath's hyp2f1 to return the same branch as scipy's on the standard branch cut. """ import pytest import numpy as np from typing import NamedTuple from numpy.testing import assert_allclose from scipy.special import hyp2f1 from scipy.special._testutils import check_version, MissingModule try: import mpmath except ImportError: mpmath = MissingModule("mpmath") def mp_hyp2f1(a, b, c, z): """Return mpmath hyp2f1 calculated on same branch as scipy hyp2f1. For most values of a,b,c mpmath returns the x - 0j branch of hyp2f1 on the branch cut x=(1,inf) whereas scipy's hyp2f1 calculates the x + 0j branch. Thus, to generate the right comparison values on the branch cut, we evaluate mpmath.hyp2f1 at x + 1e-15*j. The exception to this occurs when c-a=-m in which case both mpmath and scipy calculate the x + 0j branch on the branch cut. When this happens mpmath.hyp2f1 will be evaluated at the original z point. """ on_branch_cut = z.real > 1.0 and abs(z.imag) < 1.0e-15
import itertools import numpy as np from numpy.testing import assert_equal import pytest import scipy.special as sp from scipy.special._testutils import ( MissingModule, check_version, FuncData) from scipy.special._mptestutils import ( Arg, IntArg, get_args, mpf2float, assert_mpmath_equal) try: import mpmath except ImportError: mpmath = MissingModule('mpmath') class ProbArg(object): """Generate a set of probabilities on [0, 1].""" def __init__(self): # Include the endpoints for compatibility with Arg et. al. self.a = 0 self.b = 1 def values(self, n): """Return an array containing approximatively n numbers.""" m = max(1, n//3) v1 = np.logspace(-30, np.log10(0.3), m) v2 = np.linspace(0.3, 0.7, m + 1, endpoint=False)[1:] v3 = 1 - np.logspace(np.log10(0.3), -15, m)
from __future__ import division, print_function, absolute_import from numpy.testing import assert_equal from scipy.special._testutils import check_version, MissingModule from scipy.special._precompute.expn_asy import generate_A try: import sympy from sympy import Poly except ImportError: sympy = MissingModule("sympy") @check_version(sympy, "1.0") def test_generate_A(): # Data from DLMF 8.20.5 x = sympy.symbols('x') Astd = [ Poly(1, x), Poly(1, x), Poly(1 - 2 * x), Poly(1 - 8 * x + 6 * x**2) ] Ares = generate_A(len(Astd)) for p, q in zip(Astd, Ares): assert_equal(p, q)