4242lazy_xp_function (sinc , static_argnames = "xp" )
4343
4444
45- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
4645class TestAtLeastND :
4746 def test_0D (self , xp : ModuleType ):
4847 x = xp .asarray (1.0 )
@@ -69,7 +68,7 @@ def test_1D(self, xp: ModuleType):
6968 xp_assert_equal (y , xp .asarray ([[0 , 1 ]]))
7069
7170 y = atleast_nd (x , ndim = 5 )
72- xp_assert_equal (y , xp .reshape ( xp . arange ( 2 ), ( 1 , 1 , 1 , 1 , 2 ) ))
71+ xp_assert_equal (y , xp .asarray ([[[[[ 0 , 1 ]]]]] ))
7372
7473 def test_2D (self , xp : ModuleType ):
7574 x = xp .asarray ([[3.0 ]])
@@ -218,8 +217,10 @@ def test_xp(self, xp: ModuleType):
218217 )
219218
220219
220+ @pytest .mark .skip_xp_backend (
221+ Backend .SPARSE , reason = "read-only backend without .at support"
222+ )
221223class TestCreateDiagonal :
222- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
223224 def test_1d_from_numpy (self , xp : ModuleType ):
224225 # from np.diag tests
225226 vals = 100 * xp .arange (5 , dtype = xp .float64 )
@@ -235,7 +236,6 @@ def test_1d_from_numpy(self, xp: ModuleType):
235236 xp_assert_equal (create_diagonal (vals , offset = 2 ), b )
236237 xp_assert_equal (create_diagonal (vals , offset = - 2 ), c )
237238
238- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
239239 @pytest .mark .parametrize ("n" , range (1 , 10 ))
240240 @pytest .mark .parametrize ("offset" , range (1 , 10 ))
241241 def test_1d_from_scipy (self , xp : ModuleType , n : int , offset : int ):
@@ -251,7 +251,6 @@ def test_0d_raises(self, xp: ModuleType):
251251 with pytest .raises (ValueError , match = "1-dimensional" ):
252252 _ = create_diagonal (xp .asarray (1 ))
253253
254- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
255254 @pytest .mark .parametrize (
256255 "shape" ,
257256 [
@@ -277,21 +276,19 @@ def test_nd(self, xp: ModuleType, shape: tuple[int, ...]):
277276 for i in ndindex (* eager_shape (c )):
278277 xp_assert_equal (c [i ], b [i [:- 1 ]] if i [- 2 ] == i [- 1 ] else zero )
279278
280- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
281279 def test_device (self , xp : ModuleType , device : Device ):
282280 x = xp .asarray ([1 , 2 , 3 ], device = device )
283281 assert get_device (create_diagonal (x )) == device
284282
285- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
286283 def test_xp (self , xp : ModuleType ):
287284 x = xp .asarray ([1 , 2 ])
288285 y = create_diagonal (x , xp = xp )
289286 xp_assert_equal (y , xp .asarray ([[1 , 0 ], [0 , 2 ]]))
290287
291288
292289class TestExpandDims :
293- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
294290 @pytest .mark .xfail_xp_backend (Backend .DASK , reason = "tuple index out of range" )
291+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "tuple index out of range" )
295292 @pytest .mark .xfail_xp_backend (Backend .TORCH , reason = "tuple index out of range" )
296293 def test_functionality (self , xp : ModuleType ):
297294 def _squeeze_all (b : Array ) -> Array :
@@ -308,7 +305,6 @@ def _squeeze_all(b: Array) -> Array:
308305 assert b .shape [axis ] == 1
309306 assert _squeeze_all (b ).shape == s
310307
311- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
312308 def test_axis_tuple (self , xp : ModuleType ):
313309 a = xp .empty ((3 , 3 , 3 ))
314310 assert expand_dims (a , axis = (0 , 1 , 2 )).shape == (1 , 1 , 1 , 3 , 3 , 3 )
@@ -341,12 +337,10 @@ def test_positive_negative_repeated(self, xp: ModuleType):
341337 with pytest .raises (ValueError , match = "Duplicate dimensions" ):
342338 _ = expand_dims (a , axis = (3 , - 3 ))
343339
344- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
345340 def test_device (self , xp : ModuleType , device : Device ):
346341 x = xp .asarray ([1 , 2 , 3 ], device = device )
347342 assert get_device (expand_dims (x , axis = 0 )) == device
348343
349- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
350344 def test_xp (self , xp : ModuleType ):
351345 x = xp .asarray ([1 , 2 , 3 ])
352346 y = expand_dims (x , axis = (0 , 1 , 2 ), xp = xp )
@@ -513,7 +507,6 @@ def test_xp(self, xp: ModuleType):
513507 xp_assert_equal (isclose (a , b , xp = xp ), xp .asarray ([True , False ]))
514508
515509
516- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
517510class TestKron :
518511 def test_basic (self , xp : ModuleType ):
519512 # Using 0-dimensional array
@@ -572,6 +565,7 @@ def test_kron_shape(
572565 k = kron (a , b )
573566 assert k .shape == expected_shape
574567
568+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no isdtype" )
575569 def test_python_scalar (self , xp : ModuleType ):
576570 a = 1
577571 # Test no dtype promotion to xp.asarray(a); use b.dtype
@@ -614,25 +608,27 @@ def test_xp(self, xp: ModuleType):
614608 xp_assert_equal (nunique (a , xp = xp ), xp .asarray (3 ))
615609
616610
617- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no arange, no device" )
618611class TestPad :
619612 def test_simple (self , xp : ModuleType ):
620- a = xp .arange ( 1 , 4 )
613+ a = xp .asarray ([ 1 , 2 , 3 ] )
621614 padded = pad (a , 2 )
622615 xp_assert_equal (padded , xp .asarray ([0 , 0 , 1 , 2 , 3 , 0 , 0 ]))
623616
617+ @pytest .mark .xfail_xp_backend (
618+ Backend .SPARSE , reason = "constant_values can only be equal to fill value"
619+ )
624620 def test_fill_value (self , xp : ModuleType ):
625- a = xp .arange ( 1 , 4 )
621+ a = xp .asarray ([ 1 , 2 , 3 ] )
626622 padded = pad (a , 2 , constant_values = 42 )
627623 xp_assert_equal (padded , xp .asarray ([42 , 42 , 1 , 2 , 3 , 42 , 42 ]))
628624
629625 def test_ndim (self , xp : ModuleType ):
630- a = xp .reshape (xp .arange (2 * 3 * 4 ), (2 , 3 , 4 ))
626+ a = xp .asarray ( np . reshape (np .arange (2 * 3 * 4 ), (2 , 3 , 4 ) ))
631627 padded = pad (a , 2 )
632628 assert padded .shape == (6 , 7 , 8 )
633629
634630 def test_mode_not_implemented (self , xp : ModuleType ):
635- a = xp .arange ( 3 )
631+ a = xp .asarray ([ 1 , 2 , 3 ] )
636632 with pytest .raises (NotImplementedError , match = "Only `'constant'`" ):
637633 _ = pad (a , 2 , mode = "edge" ) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
638634
@@ -645,7 +641,7 @@ def test_xp(self, xp: ModuleType):
645641 xp_assert_equal (padded , xp .asarray (0 ))
646642
647643 def test_tuple_width (self , xp : ModuleType ):
648- a = xp .reshape (xp .arange (12 ), (3 , 4 ))
644+ a = xp .asarray ( np . reshape (np .arange (12 ), (3 , 4 ) ))
649645 padded = pad (a , (1 , 0 ))
650646 assert padded .shape == (4 , 5 )
651647
@@ -656,7 +652,7 @@ def test_tuple_width(self, xp: ModuleType):
656652 _ = pad (a , [(1 , 2 , 3 )]) # type: ignore[list-item] # pyright: ignore[reportArgumentType]
657653
658654 def test_sequence_of_tuples_width (self , xp : ModuleType ):
659- a = xp .reshape (xp .arange (12 ), (3 , 4 ))
655+ a = xp .asarray ( np . reshape (np .arange (12 ), (3 , 4 ) ))
660656
661657 padded = pad (a , ((1 , 0 ), (0 , 2 )))
662658 assert padded .shape == (4 , 6 )
@@ -678,7 +674,7 @@ def test_sequence_of_tuples_width(self, xp: ModuleType):
678674)
679675
680676
681- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in asarray() " )
677+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no argsort " )
682678class TestSetDiff1D :
683679 @pytest .mark .xfail_xp_backend (Backend .DASK , reason = "NaN-shaped arrays" )
684680 @pytest .mark .xfail_xp_backend (
0 commit comments