4
4
5
5
import pytest
6
6
from numpy .testing import (assert_equal , assert_almost_equal , assert_array_almost_equal ,
7
- assert_allclose )
7
+ assert_allclose , suppress_warnings )
8
8
9
9
from scipy import special
10
10
from scipy .special import (legendre_p , legendre_p_all , assoc_legendre_p ,
@@ -32,8 +32,11 @@ def test_legendre(self):
32
32
@pytest .mark .parametrize ('zi' , [9.766818 , 0.2999083 , 8.24726 , - 22.84843 ,
33
33
- 0.8792666 ])
34
34
def test_lpn_against_clpmn (self , n , zr , zi ):
35
- reslpn = special .lpn (n , zr + zi * 1j )
36
- resclpmn = special .clpmn (0 , n , zr + zi * 1j )
35
+ with suppress_warnings () as sup :
36
+ sup .filter (category = DeprecationWarning )
37
+ reslpn = special .lpn (n , zr + zi * 1j )
38
+ resclpmn = special .clpmn (0 , n , zr + zi * 1j )
39
+
37
40
assert_allclose (reslpn [0 ], resclpmn [0 ][0 ])
38
41
assert_allclose (reslpn [1 ], resclpmn [1 ][0 ])
39
42
@@ -73,7 +76,10 @@ def test_all_ode(self, n_max, x_shape):
73
76
np .testing .assert_allclose (err , 0 , atol = 1e-10 )
74
77
75
78
def test_legacy (self ):
76
- p , pd = special .lpn (2 , 0.5 )
79
+ with suppress_warnings () as sup :
80
+ sup .filter (category = DeprecationWarning )
81
+ p , pd = special .lpn (2 , 0.5 )
82
+
77
83
assert_array_almost_equal (p , [1.00000 , 0.50000 , - 0.12500 ], 4 )
78
84
assert_array_almost_equal (pd , [0.00000 , 1.00000 , 1.50000 ], 4 )
79
85
@@ -327,13 +333,16 @@ def test_legacy(self, m_max, n_max):
327
333
x = 0.5
328
334
p , p_jac = assoc_legendre_p_all (n_max , m_max , x , diff_n = 1 )
329
335
330
- p_legacy , p_jac_legacy = special .lpmn (m_max , n_max , x )
331
- for m in range (m_max + 1 ):
332
- np .testing .assert_allclose (p_legacy [m ], p [:, m ])
336
+ with suppress_warnings () as sup :
337
+ sup .filter (category = DeprecationWarning )
333
338
334
- p_legacy , p_jac_legacy = special .lpmn (- m_max , n_max , x )
335
- for m in range (m_max + 1 ):
336
- np .testing .assert_allclose (p_legacy [m ], p [:, - m ])
339
+ p_legacy , p_jac_legacy = special .lpmn (m_max , n_max , x )
340
+ for m in range (m_max + 1 ):
341
+ np .testing .assert_allclose (p_legacy [m ], p [:, m ])
342
+
343
+ p_legacy , p_jac_legacy = special .lpmn (- m_max , n_max , x )
344
+ for m in range (m_max + 1 ):
345
+ np .testing .assert_allclose (p_legacy [m ], p [:, - m ])
337
346
338
347
class TestMultiAssocLegendreP :
339
348
@pytest .mark .parametrize ("shape" , [(1000 ,), (4 , 9 ), (3 , 5 , 7 )])
@@ -388,7 +397,7 @@ def test_specific(self, shape, branch_cut, z_min, z_max, norm):
388
397
assoc_legendre_p_2_m2 (z , branch_cut = branch_cut , norm = norm ))
389
398
np .testing .assert_allclose (p [2 , - 1 ],
390
399
assoc_legendre_p_2_m1 (z , branch_cut = branch_cut , norm = norm ))
391
-
400
+
392
401
np .testing .assert_allclose (p [3 , 0 ],
393
402
assoc_legendre_p_3_0 (z , branch_cut = branch_cut , norm = norm ))
394
403
np .testing .assert_allclose (p [3 , 1 ],
@@ -678,7 +687,11 @@ def test_ode(self, shape):
678
687
class TestLegendreFunctions :
679
688
def test_clpmn (self ):
680
689
z = 0.5 + 0.3j
681
- clp = special .clpmn (2 , 2 , z , 3 )
690
+
691
+ with suppress_warnings () as sup :
692
+ sup .filter (category = DeprecationWarning )
693
+ clp = special .clpmn (2 , 2 , z , 3 )
694
+
682
695
assert_array_almost_equal (clp ,
683
696
(np .array ([[1.0000 , z , 0.5 * (3 * z * z - 1 )],
684
697
[0.0000 , np .sqrt (z * z - 1 ), 3 * z * np .sqrt (z * z - 1 )],
@@ -693,8 +706,12 @@ def test_clpmn_close_to_real_2(self):
693
706
m = 1
694
707
n = 3
695
708
x = 0.5
696
- clp_plus = special .clpmn (m , n , x + 1j * eps , 2 )[0 ][m , n ]
697
- clp_minus = special .clpmn (m , n , x - 1j * eps , 2 )[0 ][m , n ]
709
+
710
+ with suppress_warnings () as sup :
711
+ sup .filter (category = DeprecationWarning )
712
+ clp_plus = special .clpmn (m , n , x + 1j * eps , 2 )[0 ][m , n ]
713
+ clp_minus = special .clpmn (m , n , x - 1j * eps , 2 )[0 ][m , n ]
714
+
698
715
assert_array_almost_equal (np .array ([clp_plus , clp_minus ]),
699
716
np .array ([special .lpmv (m , n , x ),
700
717
special .lpmv (m , n , x )]),
@@ -705,8 +722,12 @@ def test_clpmn_close_to_real_3(self):
705
722
m = 1
706
723
n = 3
707
724
x = 0.5
708
- clp_plus = special .clpmn (m , n , x + 1j * eps , 3 )[0 ][m , n ]
709
- clp_minus = special .clpmn (m , n , x - 1j * eps , 3 )[0 ][m , n ]
725
+
726
+ with suppress_warnings () as sup :
727
+ sup .filter (category = DeprecationWarning )
728
+ clp_plus = special .clpmn (m , n , x + 1j * eps , 3 )[0 ][m , n ]
729
+ clp_minus = special .clpmn (m , n , x - 1j * eps , 3 )[0 ][m , n ]
730
+
710
731
assert_array_almost_equal (np .array ([clp_plus , clp_minus ]),
711
732
np .array ([special .lpmv (m , n , x )* np .exp (- 0.5j * m * np .pi ),
712
733
special .lpmv (m , n , x )* np .exp (0.5j * m * np .pi )]),
@@ -717,33 +738,41 @@ def test_clpmn_across_unit_circle(self):
717
738
m = 1
718
739
n = 1
719
740
x = 1j
720
- for type in [2 , 3 ]:
721
- assert_almost_equal (special .clpmn (m , n , x + 1j * eps , type )[0 ][m , n ],
722
- special .clpmn (m , n , x - 1j * eps , type )[0 ][m , n ], 6 )
741
+
742
+ with suppress_warnings () as sup :
743
+ sup .filter (category = DeprecationWarning )
744
+ for type in [2 , 3 ]:
745
+ assert_almost_equal (special .clpmn (m , n , x + 1j * eps , type )[0 ][m , n ],
746
+ special .clpmn (m , n , x - 1j * eps , type )[0 ][m , n ], 6 )
723
747
724
748
def test_inf (self ):
725
- for z in (1 , - 1 ):
726
- for n in range (4 ):
727
- for m in range (1 , n ):
728
- lp = special .clpmn (m , n , z )
729
- assert np .isinf (lp [1 ][1 ,1 :]).all ()
730
- lp = special .lpmn (m , n , z )
731
- assert np .isinf (lp [1 ][1 ,1 :]).all ()
749
+ with suppress_warnings () as sup :
750
+ sup .filter (category = DeprecationWarning )
751
+ for z in (1 , - 1 ):
752
+ for n in range (4 ):
753
+ for m in range (1 , n ):
754
+ lp = special .clpmn (m , n , z )
755
+ assert np .isinf (lp [1 ][1 ,1 :]).all ()
756
+ lp = special .lpmn (m , n , z )
757
+ assert np .isinf (lp [1 ][1 ,1 :]).all ()
732
758
733
759
def test_deriv_clpmn (self ):
734
760
# data inside and outside of the unit circle
735
761
zvals = [0.5 + 0.5j , - 0.5 + 0.5j , - 0.5 - 0.5j , 0.5 - 0.5j ,
736
762
1 + 1j , - 1 + 1j , - 1 - 1j , 1 - 1j ]
737
763
m = 2
738
764
n = 3
739
- for type in [2 , 3 ]:
740
- for z in zvals :
741
- for h in [1e-3 , 1e-3j ]:
742
- approx_derivative = (special .clpmn (m , n , z + 0.5 * h , type )[0 ]
743
- - special .clpmn (m , n , z - 0.5 * h , type )[0 ])/ h
744
- assert_allclose (special .clpmn (m , n , z , type )[1 ],
745
- approx_derivative ,
746
- rtol = 1e-4 )
765
+
766
+ with suppress_warnings () as sup :
767
+ sup .filter (category = DeprecationWarning )
768
+ for type in [2 , 3 ]:
769
+ for z in zvals :
770
+ for h in [1e-3 , 1e-3j ]:
771
+ approx_derivative = (special .clpmn (m , n , z + 0.5 * h , type )[0 ]
772
+ - special .clpmn (m , n , z - 0.5 * h , type )[0 ])/ h
773
+ assert_allclose (special .clpmn (m , n , z , type )[1 ],
774
+ approx_derivative ,
775
+ rtol = 1e-4 )
747
776
748
777
"""
749
778
@pytest.mark.parametrize("m_max", [3])
@@ -834,7 +863,9 @@ def test_array_inputs_lxn(self, function, n, z_complex, z_inexact, input_shape):
834
863
if z_complex :
835
864
z = 1j * z + 0.5j * z
836
865
837
- P_z , P_d_z = function (n , z )
866
+ with suppress_warnings () as sup :
867
+ sup .filter (category = DeprecationWarning )
868
+ P_z , P_d_z = function (n , z )
838
869
assert P_z .shape == (n + 1 , ) + input_shape
839
870
assert P_d_z .shape == (n + 1 , ) + input_shape
840
871
@@ -877,7 +908,10 @@ def test_array_inputs_clxmn(self, function, m, n, input_shape):
877
908
z = rng .uniform (- 1 , 1 , size = input_shape )
878
909
z = 1j * z + 0.5j * z
879
910
880
- P_z , P_d_z = function (m , n , z )
911
+ with suppress_warnings () as sup :
912
+ sup .filter (category = DeprecationWarning )
913
+ P_z , P_d_z = function (m , n , z )
914
+
881
915
assert P_z .shape == (m + 1 , n + 1 ) + input_shape
882
916
assert P_d_z .shape == (m + 1 , n + 1 ) + input_shape
883
917
0 commit comments