4141lazy_xp_function (sinc , static_argnames = "xp" )
4242
4343
44- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
4544class TestAtLeastND :
4645 def test_0D (self , xp : ModuleType ):
4746 x = xp .asarray (1.0 )
@@ -68,7 +67,7 @@ def test_1D(self, xp: ModuleType):
6867 xp_assert_equal (y , xp .asarray ([[0 , 1 ]]))
6968
7069 y = atleast_nd (x , ndim = 5 )
71- xp_assert_equal (y , xp .reshape ( xp . arange ( 2 ), ( 1 , 1 , 1 , 1 , 2 ) ))
70+ xp_assert_equal (y , xp .asarray ([[[[[ 0 , 1 ]]]]] ))
7271
7372 def test_2D (self , xp : ModuleType ):
7473 x = xp .asarray ([[3.0 ]])
@@ -217,8 +216,10 @@ def test_xp(self, xp: ModuleType):
217216 )
218217
219218
219+ @pytest .mark .skip_xp_backend (
220+ Backend .SPARSE , reason = "read-only backend without .at support"
221+ )
220222class TestCreateDiagonal :
221- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
222223 def test_1d_from_numpy (self , xp : ModuleType ):
223224 # from np.diag tests
224225 vals = 100 * xp .arange (5 , dtype = xp .float64 )
@@ -234,7 +235,6 @@ def test_1d_from_numpy(self, xp: ModuleType):
234235 xp_assert_equal (create_diagonal (vals , offset = 2 ), b )
235236 xp_assert_equal (create_diagonal (vals , offset = - 2 ), c )
236237
237- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
238238 @pytest .mark .parametrize ("n" , range (1 , 10 ))
239239 @pytest .mark .parametrize ("offset" , range (1 , 10 ))
240240 def test_1d_from_scipy (self , xp : ModuleType , n : int , offset : int ):
@@ -250,7 +250,6 @@ def test_0d_raises(self, xp: ModuleType):
250250 with pytest .raises (ValueError , match = "1-dimensional" ):
251251 _ = create_diagonal (xp .asarray (1 ))
252252
253- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
254253 @pytest .mark .parametrize (
255254 "shape" ,
256255 [
@@ -276,28 +275,24 @@ def test_nd(self, xp: ModuleType, shape: tuple[int, ...]):
276275 for i in ndindex (* eager_shape (c )):
277276 xp_assert_equal (c [i ], b [i [:- 1 ]] if i [- 2 ] == i [- 1 ] else zero )
278277
279- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
280278 def test_device (self , xp : ModuleType , device : Device ):
281279 x = xp .asarray ([1 , 2 , 3 ], device = device )
282280 assert get_device (create_diagonal (x )) == device
283281
284- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
285282 def test_xp (self , xp : ModuleType ):
286283 x = xp .asarray ([1 , 2 ])
287284 y = create_diagonal (x , xp = xp )
288285 xp_assert_equal (y , xp .asarray ([[1 , 0 ], [0 , 2 ]]))
289286
290287
291288class TestExpandDims :
292- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
293289 def test_single_axis (self , xp : ModuleType ):
294290 """Trivial case where xpx.expand_dims doesn't add anything to xp.expand_dims"""
295291 a = xp .empty ((2 , 3 , 4 , 5 ))
296292 for axis in range (- 5 , 4 ):
297293 b = expand_dims (a , axis = axis )
298294 xp_assert_equal (b , xp .expand_dims (a , axis = axis ))
299295
300- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
301296 def test_axis_tuple (self , xp : ModuleType ):
302297 a = xp .empty ((3 , 3 , 3 ))
303298 assert expand_dims (a , axis = (0 , 1 , 2 )).shape == (1 , 1 , 1 , 3 , 3 , 3 )
@@ -329,12 +324,10 @@ def test_positive_negative_repeated(self, xp: ModuleType):
329324 with pytest .raises (ValueError , match = "Duplicate dimensions" ):
330325 _ = expand_dims (a , axis = (3 , - 3 ))
331326
332- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
333327 def test_device (self , xp : ModuleType , device : Device ):
334328 x = xp .asarray ([1 , 2 , 3 ], device = device )
335329 assert get_device (expand_dims (x , axis = 0 )) == device
336330
337- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
338331 def test_xp (self , xp : ModuleType ):
339332 x = xp .asarray ([1 , 2 , 3 ])
340333 y = expand_dims (x , axis = (0 , 1 , 2 ), xp = xp )
@@ -501,7 +494,6 @@ def test_xp(self, xp: ModuleType):
501494 xp_assert_equal (isclose (a , b , xp = xp ), xp .asarray ([True , False ]))
502495
503496
504- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
505497class TestKron :
506498 def test_basic (self , xp : ModuleType ):
507499 # Using 0-dimensional array
@@ -560,6 +552,7 @@ def test_kron_shape(
560552 k = kron (a , b )
561553 assert k .shape == expected_shape
562554
555+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no isdtype" )
563556 def test_python_scalar (self , xp : ModuleType ):
564557 a = 1
565558 # Test no dtype promotion to xp.asarray(a); use b.dtype
@@ -602,25 +595,27 @@ def test_xp(self, xp: ModuleType):
602595 xp_assert_equal (nunique (a , xp = xp ), xp .asarray (3 ))
603596
604597
605- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no arange, no device" )
606598class TestPad :
607599 def test_simple (self , xp : ModuleType ):
608- a = xp .arange ( 1 , 4 )
600+ a = xp .asarray ([ 1 , 2 , 3 ] )
609601 padded = pad (a , 2 )
610602 xp_assert_equal (padded , xp .asarray ([0 , 0 , 1 , 2 , 3 , 0 , 0 ]))
611603
604+ @pytest .mark .xfail_xp_backend (
605+ Backend .SPARSE , reason = "constant_values can only be equal to fill value"
606+ )
612607 def test_fill_value (self , xp : ModuleType ):
613- a = xp .arange ( 1 , 4 )
608+ a = xp .asarray ([ 1 , 2 , 3 ] )
614609 padded = pad (a , 2 , constant_values = 42 )
615610 xp_assert_equal (padded , xp .asarray ([42 , 42 , 1 , 2 , 3 , 42 , 42 ]))
616611
617612 def test_ndim (self , xp : ModuleType ):
618- a = xp .reshape (xp .arange (2 * 3 * 4 ), (2 , 3 , 4 ))
613+ a = xp .asarray ( np . reshape (np .arange (2 * 3 * 4 ), (2 , 3 , 4 ) ))
619614 padded = pad (a , 2 )
620615 assert padded .shape == (6 , 7 , 8 )
621616
622617 def test_mode_not_implemented (self , xp : ModuleType ):
623- a = xp .arange ( 3 )
618+ a = xp .asarray ([ 1 , 2 , 3 ] )
624619 with pytest .raises (NotImplementedError , match = "Only `'constant'`" ):
625620 _ = pad (a , 2 , mode = "edge" ) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
626621
@@ -633,7 +628,7 @@ def test_xp(self, xp: ModuleType):
633628 xp_assert_equal (padded , xp .asarray (0 ))
634629
635630 def test_tuple_width (self , xp : ModuleType ):
636- a = xp .reshape (xp .arange (12 ), (3 , 4 ))
631+ a = xp .asarray ( np . reshape (np .arange (12 ), (3 , 4 ) ))
637632 padded = pad (a , (1 , 0 ))
638633 assert padded .shape == (4 , 5 )
639634
@@ -644,7 +639,7 @@ def test_tuple_width(self, xp: ModuleType):
644639 _ = pad (a , [(1 , 2 , 3 )]) # type: ignore[list-item] # pyright: ignore[reportArgumentType]
645640
646641 def test_sequence_of_tuples_width (self , xp : ModuleType ):
647- a = xp .reshape (xp .arange (12 ), (3 , 4 ))
642+ a = xp .asarray ( np . reshape (np .arange (12 ), (3 , 4 ) ))
648643
649644 padded = pad (a , ((1 , 0 ), (0 , 2 )))
650645 assert padded .shape == (4 , 6 )
@@ -666,7 +661,7 @@ def test_sequence_of_tuples_width(self, xp: ModuleType):
666661)
667662
668663
669- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in asarray() " )
664+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no argsort " )
670665class TestSetDiff1D :
671666 @pytest .mark .xfail_xp_backend (Backend .DASK , reason = "NaN-shaped arrays" )
672667 @pytest .mark .xfail_xp_backend (
0 commit comments