test_exponential_integrals.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import pytest
  2. import numpy as np
  3. from numpy.testing import assert_allclose
  4. import scipy.special as sc
  5. class TestExp1:
  6. def test_branch_cut(self):
  7. assert np.isnan(sc.exp1(-1))
  8. assert sc.exp1(complex(-1, 0)).imag == (
  9. -sc.exp1(complex(-1, -0.0)).imag
  10. )
  11. assert_allclose(
  12. sc.exp1(complex(-1, 0)),
  13. sc.exp1(-1 + 1e-20j),
  14. atol=0,
  15. rtol=1e-15
  16. )
  17. assert_allclose(
  18. sc.exp1(complex(-1, -0.0)),
  19. sc.exp1(-1 - 1e-20j),
  20. atol=0,
  21. rtol=1e-15
  22. )
  23. def test_834(self):
  24. # Regression test for #834
  25. a = sc.exp1(-complex(19.9999990))
  26. b = sc.exp1(-complex(19.9999991))
  27. assert_allclose(a.imag, b.imag, atol=0, rtol=1e-15)
  28. class TestExpi:
  29. @pytest.mark.parametrize('result', [
  30. sc.expi(complex(-1, 0)),
  31. sc.expi(complex(-1, -0.0)),
  32. sc.expi(-1)
  33. ])
  34. def test_branch_cut(self, result):
  35. desired = -0.21938393439552027368 # Computed using Mpmath
  36. assert_allclose(result, desired, atol=0, rtol=1e-14)
  37. def test_near_branch_cut(self):
  38. lim_from_above = sc.expi(-1 + 1e-20j)
  39. lim_from_below = sc.expi(-1 - 1e-20j)
  40. assert_allclose(
  41. lim_from_above.real,
  42. lim_from_below.real,
  43. atol=0,
  44. rtol=1e-15
  45. )
  46. assert_allclose(
  47. lim_from_above.imag,
  48. -lim_from_below.imag,
  49. atol=0,
  50. rtol=1e-15
  51. )
  52. def test_continuity_on_positive_real_axis(self):
  53. assert_allclose(
  54. sc.expi(complex(1, 0)),
  55. sc.expi(complex(1, -0.0)),
  56. atol=0,
  57. rtol=1e-15
  58. )
  59. class TestExpn:
  60. def test_out_of_domain(self):
  61. assert all(np.isnan([sc.expn(-1, 1.0), sc.expn(1, -1.0)]))