4141lazy_xp_function (sinc , jax_jit = False , static_argnames = "xp" )
4242
4343
44- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
44+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
4545class TestAtLeastND :
4646 def test_0D (self , xp : ModuleType ):
4747 x = xp .asarray (1.0 )
@@ -108,12 +108,12 @@ def test_device(self, xp: ModuleType, device: Device):
108108 assert get_device (atleast_nd (x , ndim = 2 )) == device
109109
110110 def test_xp (self , xp : ModuleType ):
111- x = xp .asarray (1 )
112- y = atleast_nd (x , ndim = 0 , xp = xp )
113- xp_assert_equal (y , x )
111+ x = xp .asarray (1.0 )
112+ y = atleast_nd (x , ndim = 1 , xp = xp )
113+ xp_assert_equal (y , xp . ones (( 1 ,)) )
114114
115115
116- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no isdtype" )
116+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no isdtype" )
117117class TestCov :
118118 def test_basic (self , xp : ModuleType ):
119119 xp_assert_close (
@@ -152,16 +152,16 @@ def test_device(self, xp: ModuleType, device: Device):
152152 x = xp .asarray ([1 , 2 , 3 ], device = device )
153153 assert get_device (cov (x )) == device
154154
155- @pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "explicit xp" )
155+ @pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "xp= xp" )
156156 def test_xp (self , xp : ModuleType ):
157157 xp_assert_close (
158158 cov (xp .asarray ([[0.0 , 2.0 ], [1.0 , 1.0 ], [2.0 , 0.0 ]]).T , xp = xp ),
159159 xp .asarray ([[1.0 , - 1.0 ], [- 1.0 , 1.0 ]], dtype = xp .float64 ),
160160 )
161161
162162
163- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no device" )
164163class TestCreateDiagonal :
164+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
165165 def test_1d (self , xp : ModuleType ):
166166 # from np.diag tests
167167 vals = 100 * xp .arange (5 , dtype = xp .float64 )
@@ -177,6 +177,7 @@ def test_1d(self, xp: ModuleType):
177177 xp_assert_equal (create_diagonal (vals , offset = 2 ), b )
178178 xp_assert_equal (create_diagonal (vals , offset = - 2 ), c )
179179
180+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
180181 @pytest .mark .parametrize ("n" , range (1 , 10 ))
181182 @pytest .mark .parametrize ("offset" , range (1 , 10 ))
182183 def test_create_diagonal (self , xp : ModuleType , n : int , offset : int ):
@@ -196,20 +197,22 @@ def test_2d(self, xp: ModuleType):
196197 with pytest .raises (ValueError , match = "1-dimensional" ):
197198 create_diagonal (xp .asarray ([[1 ]]))
198199
200+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
199201 def test_device (self , xp : ModuleType , device : Device ):
200202 x = xp .asarray ([1 , 2 , 3 ], device = device )
201203 assert get_device (create_diagonal (x )) == device
202204
205+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
203206 def test_xp (self , xp : ModuleType ):
204207 x = xp .asarray ([1 , 2 ])
205208 y = create_diagonal (x , xp = xp )
206209 xp_assert_equal (y , xp .asarray ([[1 , 0 ], [0 , 2 ]]))
207210
208211
209- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
210212class TestExpandDims :
211- @pytest .mark .skip_xp_backend (Backend .DASK , reason = "tuple index out of range" )
212- @pytest .mark .skip_xp_backend (Backend .TORCH , reason = "tuple index out of range" )
213+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
214+ @pytest .mark .xfail_xp_backend (Backend .DASK , reason = "tuple index out of range" )
215+ @pytest .mark .xfail_xp_backend (Backend .TORCH , reason = "tuple index out of range" )
213216 def test_functionality (self , xp : ModuleType ):
214217 def _squeeze_all (b : Array ) -> Array :
215218 """Mimics `np.squeeze(b)`. `xpx.squeeze`?"""
@@ -225,6 +228,7 @@ def _squeeze_all(b: Array) -> Array:
225228 assert b .shape [axis ] == 1
226229 assert _squeeze_all (b ).shape == s
227230
231+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
228232 def test_axis_tuple (self , xp : ModuleType ):
229233 a = xp .empty ((3 , 3 , 3 ))
230234 assert expand_dims (a , axis = (0 , 1 , 2 )).shape == (1 , 1 , 1 , 3 , 3 , 3 )
@@ -257,17 +261,19 @@ def test_positive_negative_repeated(self, xp: ModuleType):
257261 with pytest .raises (ValueError , match = "Duplicate dimensions" ):
258262 expand_dims (a , axis = (3 , - 3 ))
259263
264+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
260265 def test_device (self , xp : ModuleType , device : Device ):
261266 x = xp .asarray ([1 , 2 , 3 ], device = device )
262267 assert get_device (expand_dims (x , axis = 0 )) == device
263268
269+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
264270 def test_xp (self , xp : ModuleType ):
265271 x = xp .asarray ([1 , 2 , 3 ])
266272 y = expand_dims (x , axis = (0 , 1 , 2 ), xp = xp )
267273 assert y .shape == (1 , 1 , 1 , 3 )
268274
269275
270- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no isdtype" )
276+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no isdtype" )
271277class TestIsClose :
272278 # FIXME use lazywhere to avoid warnings on inf
273279 @pytest .mark .filterwarnings ("ignore:invalid value encountered" )
@@ -402,7 +408,7 @@ def test_none_shape_bool(self, xp: ModuleType):
402408 xp_assert_equal (isclose (a , b ), xp .asarray ([True , False ]))
403409
404410 @pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "xp=xp" )
405- @pytest .mark .skip_xp_backend (Backend .TORCH , reason = "Array API 2024.12 support" )
411+ @pytest .mark .xfail_xp_backend (Backend .TORCH , reason = "Array API 2024.12 support" )
406412 def test_python_scalar (self , xp : ModuleType ):
407413 a = xp .asarray ([0.0 , 0.1 ], dtype = xp .float32 )
408414 xp_assert_equal (isclose (a , 0.0 ), xp .asarray ([True , False ]))
@@ -425,7 +431,7 @@ def test_xp(self, xp: ModuleType):
425431 xp_assert_equal (isclose (a , b , xp = xp ), xp .asarray ([True , False ]))
426432
427433
428- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
434+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
429435class TestKron :
430436 def test_basic (self , xp : ModuleType ):
431437 # Using 0-dimensional array
@@ -526,7 +532,7 @@ def test_xp(self, xp: ModuleType):
526532 xp_assert_equal (nunique (a , xp = xp ), xp .asarray (3 ))
527533
528534
529- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no arange, no device" )
535+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no arange, no device" )
530536class TestPad :
531537 def test_simple (self , xp : ModuleType ):
532538 a = xp .arange (1 , 4 )
@@ -576,10 +582,24 @@ def test_sequence_of_tuples_width(self, xp: ModuleType):
576582 assert padded .shape == (4 , 4 )
577583
578584
579- @pytest .mark .skip_xp_backend (Backend .DASK , reason = "no argsort" )
580- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no device kwarg in asarray" )
585+ assume_unique = pytest .mark .parametrize (
586+ "assume_unique" ,
587+ [
588+ True ,
589+ pytest .param (
590+ False ,
591+ marks = pytest .mark .xfail_xp_backend (
592+ Backend .DASK , reason = "NaN-shaped arrays"
593+ ),
594+ ),
595+ ],
596+ )
597+
598+
599+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in asarray()" )
581600class TestSetDiff1D :
582- @pytest .mark .skip_xp_backend (
601+ @pytest .mark .xfail_xp_backend (Backend .DASK , reason = "NaN-shaped arrays" )
602+ @pytest .mark .xfail_xp_backend (
583603 Backend .TORCH , reason = "index_select not implemented for uint32"
584604 )
585605 def test_setdiff1d (self , xp : ModuleType ):
@@ -608,7 +628,7 @@ def test_assume_unique(self, xp: ModuleType):
608628 actual = setdiff1d (x1 , x2 , assume_unique = True )
609629 xp_assert_equal (actual , expected )
610630
611- @pytest . mark . parametrize ( " assume_unique" , [ True , False ])
631+ @assume_unique
612632 @pytest .mark .parametrize ("shape1" , [(), (1 ,), (1 , 1 )])
613633 @pytest .mark .parametrize ("shape2" , [(), (1 ,), (1 , 1 )])
614634 def test_shapes (
@@ -623,8 +643,8 @@ def test_shapes(
623643 actual = setdiff1d (x1 , x2 , assume_unique = assume_unique )
624644 xp_assert_equal (actual , xp .empty ((0 ,)))
625645
646+ @assume_unique
626647 @pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "xp=xp" )
627- @pytest .mark .parametrize ("assume_unique" , [True , False ])
628648 def test_python_scalar (self , xp : ModuleType , assume_unique : bool ):
629649 # Test no dtype promotion to xp.asarray(x2); use x1.dtype
630650 x1 = xp .asarray ([3 , 1 , 2 ], dtype = xp .int16 )
@@ -645,21 +665,22 @@ def test_all_python_scalars(self, assume_unique: bool):
645665 with pytest .raises (TypeError , match = "Unrecognized" ):
646666 setdiff1d (0 , 0 , assume_unique = assume_unique )
647667
648- def test_device (self , xp : ModuleType , device : Device ):
668+ @assume_unique
669+ def test_device (self , xp : ModuleType , device : Device , assume_unique : bool ):
649670 x1 = xp .asarray ([3 , 8 , 20 ], device = device )
650671 x2 = xp .asarray ([2 , 3 , 4 ], device = device )
651- assert get_device (setdiff1d (x1 , x2 )) == device
672+ assert get_device (setdiff1d (x1 , x2 , assume_unique = assume_unique )) == device
652673
653- @pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "explicit xp" )
674+ @pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "xp= xp" )
654675 def test_xp (self , xp : ModuleType ):
655676 x1 = xp .asarray ([3 , 8 , 20 ])
656677 x2 = xp .asarray ([2 , 3 , 4 ])
657678 expected = xp .asarray ([8 , 20 ])
658- actual = setdiff1d (x1 , x2 , xp = xp )
679+ actual = setdiff1d (x1 , x2 , assume_unique = True , xp = xp )
659680 xp_assert_equal (actual , expected )
660681
661682
662- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no isdtype" )
683+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no isdtype" )
663684class TestSinc :
664685 def test_simple (self , xp : ModuleType ):
665686 xp_assert_equal (sinc (xp .asarray (0.0 )), xp .asarray (1.0 ))
0 commit comments