1010import pytest
1111from pytest import raises as assert_raises
1212from scipy ._lib ._array_api import (
13- xp_assert_close , xp_assert_equal , array_namespace ,
13+ xp_assert_equal , array_namespace ,
1414 assert_array_almost_equal , xp_size , xp_default_dtype , is_numpy ,
1515 make_xp_test_case , make_xp_pytest_param , is_cupy , is_torch , scipy_namespace_for ,
1616 _xp_copy_to_numpy , xp_assert_close_nulp
1717)
18+ from scipy ._lib ._array_api_no_0d import xp_assert_close
1819import scipy ._external .array_api_extra as xpx
1920
2021from numpy import array , spacing , sin , pi
@@ -268,7 +269,7 @@ def test_complexk(self, xp):
268269 b_np , a_np = map (_xp_copy_to_numpy , (b , a ))
269270 z_np , p_np , k_np = tf2zpk (b_np , a_np )
270271 z , p , k = map (xp .asarray , (z_np , p_np , k_np ))
271- xp_assert_close (k , xp .asarray (1j ), check_0d = False )
272+ xp_assert_close (k , xp .asarray (1j ), check_0d = True )
272273 bp , ap = zpk2tf (z , p , k )
273274 xp_assert_close (b , bp )
274275 xp_assert_close (a , ap )
@@ -1195,13 +1196,13 @@ def test_freqz_sos_design(self, xp):
11951196 w = w / xp .pi
11961197 xp_assert_close (20 * xp .log10 (h [w <= 0.1 ]),
11971198 zero , atol = 3.01 ,
1198- check_shape = False )
1199+ check_shape = False , check_0d = True )
11991200 xp_assert_close (20 * xp .log10 (h [w >= 0.6 ]),
12001201 zero , atol = 3.01 ,
1201- check_shape = False )
1202+ check_shape = False , check_0d = True )
12021203 xp_assert_close (h [(w >= 0.2 ) & (w <= 0.5 )],
12031204 zero , atol = 1e-3 ,
1204- check_shape = False ) # <= -60 dB
1205+ check_shape = False , check_0d = True ) # <= -60 dB
12051206
12061207 N , Wn = cheb2ord ([0.1 , 0.6 ], [0.2 , 0.5 ], 3 , 150 )
12071208 sos = cheby2 (N , 150 , Wn , 'stop' , output = 'sos' )
@@ -1210,8 +1211,8 @@ def test_freqz_sos_design(self, xp):
12101211 w , h = freqz_sos (sos )
12111212 dB = 20 * xp .log10 (xp .abs (h ))
12121213 w = w / xp .pi
1213- xp_assert_close (dB [w <= 0.1 ], zero , atol = 3.01 , check_shape = False )
1214- xp_assert_close (dB [w >= 0.6 ], zero , atol = 3.01 , check_shape = False )
1214+ xp_assert_close (dB [w <= 0.1 ], zero , atol = 3.01 , check_shape = False , check_0d = True )
1215+ xp_assert_close (dB [w >= 0.6 ], zero , atol = 3.01 , check_shape = False , check_0d = True )
12151216 assert xp .all (dB [(w >= 0.2 ) & (w <= 0.5 )] < - 149.9 )
12161217
12171218 # from cheb1ord
@@ -1223,9 +1224,9 @@ def test_freqz_sos_design(self, xp):
12231224 h = xp .abs (h )
12241225 w = w / xp .pi
12251226 xp_assert_close (20 * xp .log10 (h [w <= 0.2 ]), zero , atol = 3.01 ,
1226- check_shape = False )
1227+ check_shape = False , check_0d = True )
12271228 xp_assert_close (h [w >= 0.3 ], zero , atol = 1e-2 ,
1228- check_shape = False ) # <= -40 dB
1229+ check_shape = False , check_0d = True ) # <= -40 dB
12291230
12301231 N , Wn = cheb1ord (0.2 , 0.3 , 1 , 150 )
12311232 sos = cheby1 (N , 1 , Wn , 'low' , output = 'sos' )
@@ -1234,7 +1235,7 @@ def test_freqz_sos_design(self, xp):
12341235 w , h = freqz_sos (sos )
12351236 dB = 20 * xp .log10 (xp .abs (h ))
12361237 w /= np .pi
1237- xp_assert_close (dB [w <= 0.2 ], zero , atol = 1.01 , check_shape = False )
1238+ xp_assert_close (dB [w <= 0.2 ], zero , atol = 1.01 , check_shape = False , check_0d = True )
12381239 assert xp .all (dB [w >= 0.3 ] < - 149.9 )
12391240
12401241 # adapted from ellipord
@@ -1246,9 +1247,9 @@ def test_freqz_sos_design(self, xp):
12461247 h = xp .abs (h )
12471248 w = w / xp .pi
12481249 xp_assert_close (20 * xp .log10 (h [w >= 0.3 ]), zero , atol = 3.01 ,
1249- check_shape = False )
1250+ check_shape = False , check_0d = True )
12501251 xp_assert_close (h [w <= 0.1 ], zero , atol = 1.5e-3 ,
1251- check_shape = False ) # <= -60 dB (approx)
1252+ check_shape = False , check_0d = True ) # <= -60 dB (approx)
12521253
12531254 # adapted from buttord
12541255 N , Wn = buttord ([0.2 , 0.5 ], [0.14 , 0.6 ], 3 , 40 )
@@ -1260,11 +1261,11 @@ def test_freqz_sos_design(self, xp):
12601261 w = w / xp .pi
12611262
12621263 h014 = h [w <= 0.14 ]
1263- xp_assert_close (h014 , xp .zeros_like (h014 ), atol = 1e-2 ) # <= -40 dB
1264+ xp_assert_close (h014 , xp .zeros_like (h014 ), atol = 1e-2 , check_0d = True ) # <= -40 dB
12641265 h06 = h [w >= 0.6 ]
1265- xp_assert_close (h06 , xp .zeros_like (h06 ), atol = 1e-2 ) # <= -40 dB
1266+ xp_assert_close (h06 , xp .zeros_like (h06 ), atol = 1e-2 , check_0d = True ) # <= -40 dB
12661267 h0205 = 20 * xp .log10 (h [(w >= 0.2 ) & (w <= 0.5 )])
1267- xp_assert_close (h0205 , xp .zeros_like (h0205 ), atol = 3.01 )
1268+ xp_assert_close (h0205 , xp .zeros_like (h0205 ), atol = 3.01 , check_0d = True )
12681269
12691270 N , Wn = buttord ([0.2 , 0.5 ], [0.14 , 0.6 ], 3 , 100 )
12701271 sos = butter (N , Wn , 'band' , output = 'sos' )
@@ -1277,7 +1278,7 @@ def test_freqz_sos_design(self, xp):
12771278 assert xp .all (dB [(w > 0 ) & (w <= 0.14 )] < - 99.9 )
12781279 assert xp .all (dB [w >= 0.6 ] < - 99.9 )
12791280 db0205 = dB [(w >= 0.2 ) & (w <= 0.5 )]
1280- xp_assert_close (db0205 , xp .zeros_like (db0205 ), atol = 3.01 )
1281+ xp_assert_close (db0205 , xp .zeros_like (db0205 ), atol = 3.01 , check_0d = True )
12811282
12821283 def test_freqz_sos_design_ellip (self , xp ):
12831284 N , Wn = ellipord (0.3 , 0.1 , 3 , 60 )
@@ -5096,9 +5097,11 @@ def test_frequency_response(self, xp):
50965097
50975098 # Check that the peak magnitude is 1 and the frequency is 1000 Hz.
50985099 xp_assert_close (response_max ,
5099- xp .ones_like (response_max ), rtol = 1e-2 , check_0d = False )
5100- xp_assert_close (freq_hz ,
5101- 1000 * xp .ones_like (freq_hz ), rtol = 1e-2 , check_0d = False )
5100+ xp .ones_like (response_max ), rtol = 1e-2 , check_0d = True )
5101+ xp_assert_close (
5102+ freq_hz , xp .asarray (1000 * xp .ones_like (freq_hz )),
5103+ rtol = 1e-2 , check_0d = True
5104+ )
51025105
51035106 # All built-in IIR filters are real, so should have perfectly
51045107 # symmetrical poles and zeros. Then ba representation (using
0 commit comments