test_specfun.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """
  2. Various made-up tests to hit different branches of the code in specfun.c
  3. """
  4. import numpy as np
  5. from numpy.testing import assert_allclose
  6. from scipy import special
  7. def test_cva2_cv0_branches():
  8. res, resp = special.mathieu_cem([40, 129], [13, 14], [30, 45])
  9. assert_allclose(res, np.array([-0.3741211, 0.74441928]))
  10. assert_allclose(resp, np.array([-37.02872758, -86.13549877]))
  11. res, resp = special.mathieu_sem([40, 129], [13, 14], [30, 45])
  12. assert_allclose(res, np.array([0.92955551, 0.66771207]))
  13. assert_allclose(resp, np.array([-14.91073448, 96.02954185]))
  14. def test_chgm_branches():
  15. res = special.eval_genlaguerre(-3.2, 3, 2.5)
  16. assert_allclose(res, -0.7077721935779854)
  17. def test_hygfz_branches():
  18. """(z == 1.0) && (c-a-b > 0.0)"""
  19. res = special.hyp2f1(1.5, 2.5, 4.5, 1.+0.j)
  20. assert_allclose(res, 10.30835089459151+0j)
  21. """(cabs(z+1) < eps) && (fabs(c-a+b - 1.0) < eps)"""
  22. res = special.hyp2f1(5+5e-16, 2, 2, -1.0 + 5e-16j)
  23. assert_allclose(res, 0.031249999999999986+3.9062499999999994e-17j)
  24. def test_pro_rad1():
  25. # https://github.com/scipy/scipy/issues/21058
  26. # Reference values taken from WolframAlpha
  27. # SpheroidalS1(1, 1, 30, 1.1)
  28. # SpheroidalS1Prime(1, 1, 30, 1.1)
  29. res = special.pro_rad1(1, 1, 30, 1.1)
  30. assert_allclose(res, (0.009657872296166435, 3.253369651472877), rtol=2e-5)
  31. def test_pro_rad2():
  32. # https://github.com/scipy/scipy/issues/21461
  33. # Reference values taken from WolframAlpha
  34. # SpheroidalS2(0, 0, 3, 1.02)
  35. # SpheroidalS2Prime(0, 0, 3, 1.02)
  36. res = special.pro_rad2(0, 0, 3, 1.02)
  37. assert_allclose(res, (-0.35089596858528077, 13.652764213480872), rtol=10e-10)