test_zeta.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import scipy.special as sc
  2. import numpy as np
  3. from numpy.testing import assert_equal, assert_allclose
  4. def test_zeta():
  5. assert_allclose(sc.zeta(2,2), np.pi**2/6 - 1, rtol=1e-12)
  6. def test_zetac():
  7. # Expected values in the following were computed using Wolfram
  8. # Alpha's `Zeta[x] - 1`
  9. x = [-2.1, 0.8, 0.9999, 9, 50, 75]
  10. desired = [
  11. -0.9972705002153750,
  12. -5.437538415895550,
  13. -10000.42279161673,
  14. 0.002008392826082214,
  15. 8.881784210930816e-16,
  16. 2.646977960169853e-23,
  17. ]
  18. assert_allclose(sc.zetac(x), desired, rtol=1e-12)
  19. def test_zetac_special_cases():
  20. assert sc.zetac(np.inf) == 0
  21. assert np.isnan(sc.zetac(-np.inf))
  22. assert sc.zetac(0) == -1.5
  23. assert sc.zetac(1.0) == np.inf
  24. assert_equal(sc.zetac([-2, -50, -100]), -1)
  25. def test_riemann_zeta_special_cases():
  26. assert np.isnan(sc.zeta(np.nan))
  27. assert sc.zeta(np.inf) == 1
  28. assert sc.zeta(0) == -0.5
  29. # Riemann zeta is zero add negative even integers.
  30. assert_equal(sc.zeta([-2, -4, -6, -8, -10]), 0)
  31. assert_allclose(sc.zeta(2), np.pi**2/6, rtol=1e-12)
  32. assert_allclose(sc.zeta(4), np.pi**4/90, rtol=1e-12)
  33. def test_riemann_zeta_avoid_overflow():
  34. s = -260.00000000001
  35. desired = -5.6966307844402683127e+297 # Computed with Mpmath
  36. assert_allclose(sc.zeta(s), desired, atol=0, rtol=5e-14)