42
42
lazy_xp_function (sinc , static_argnames = "xp" )
43
43
44
44
45
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
46
45
class TestAtLeastND :
47
46
def test_0D (self , xp : ModuleType ):
48
47
x = xp .asarray (1.0 )
@@ -69,7 +68,7 @@ def test_1D(self, xp: ModuleType):
69
68
xp_assert_equal (y , xp .asarray ([[0 , 1 ]]))
70
69
71
70
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 ]]]]] ))
73
72
74
73
def test_2D (self , xp : ModuleType ):
75
74
x = xp .asarray ([[3.0 ]])
@@ -218,8 +217,10 @@ def test_xp(self, xp: ModuleType):
218
217
)
219
218
220
219
220
+ @pytest .mark .skip_xp_backend (
221
+ Backend .SPARSE , reason = "read-only backend without .at support"
222
+ )
221
223
class TestCreateDiagonal :
222
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
223
224
def test_1d_from_numpy (self , xp : ModuleType ):
224
225
# from np.diag tests
225
226
vals = 100 * xp .arange (5 , dtype = xp .float64 )
@@ -235,7 +236,6 @@ def test_1d_from_numpy(self, xp: ModuleType):
235
236
xp_assert_equal (create_diagonal (vals , offset = 2 ), b )
236
237
xp_assert_equal (create_diagonal (vals , offset = - 2 ), c )
237
238
238
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
239
239
@pytest .mark .parametrize ("n" , range (1 , 10 ))
240
240
@pytest .mark .parametrize ("offset" , range (1 , 10 ))
241
241
def test_1d_from_scipy (self , xp : ModuleType , n : int , offset : int ):
@@ -251,7 +251,6 @@ def test_0d_raises(self, xp: ModuleType):
251
251
with pytest .raises (ValueError , match = "1-dimensional" ):
252
252
_ = create_diagonal (xp .asarray (1 ))
253
253
254
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
255
254
@pytest .mark .parametrize (
256
255
"shape" ,
257
256
[
@@ -277,21 +276,19 @@ def test_nd(self, xp: ModuleType, shape: tuple[int, ...]):
277
276
for i in ndindex (* eager_shape (c )):
278
277
xp_assert_equal (c [i ], b [i [:- 1 ]] if i [- 2 ] == i [- 1 ] else zero )
279
278
280
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
281
279
def test_device (self , xp : ModuleType , device : Device ):
282
280
x = xp .asarray ([1 , 2 , 3 ], device = device )
283
281
assert get_device (create_diagonal (x )) == device
284
282
285
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
286
283
def test_xp (self , xp : ModuleType ):
287
284
x = xp .asarray ([1 , 2 ])
288
285
y = create_diagonal (x , xp = xp )
289
286
xp_assert_equal (y , xp .asarray ([[1 , 0 ], [0 , 2 ]]))
290
287
291
288
292
289
class TestExpandDims :
293
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
294
290
@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" )
295
292
@pytest .mark .xfail_xp_backend (Backend .TORCH , reason = "tuple index out of range" )
296
293
def test_functionality (self , xp : ModuleType ):
297
294
def _squeeze_all (b : Array ) -> Array :
@@ -308,7 +305,6 @@ def _squeeze_all(b: Array) -> Array:
308
305
assert b .shape [axis ] == 1
309
306
assert _squeeze_all (b ).shape == s
310
307
311
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
312
308
def test_axis_tuple (self , xp : ModuleType ):
313
309
a = xp .empty ((3 , 3 , 3 ))
314
310
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):
341
337
with pytest .raises (ValueError , match = "Duplicate dimensions" ):
342
338
_ = expand_dims (a , axis = (3 , - 3 ))
343
339
344
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
345
340
def test_device (self , xp : ModuleType , device : Device ):
346
341
x = xp .asarray ([1 , 2 , 3 ], device = device )
347
342
assert get_device (expand_dims (x , axis = 0 )) == device
348
343
349
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
350
344
def test_xp (self , xp : ModuleType ):
351
345
x = xp .asarray ([1 , 2 , 3 ])
352
346
y = expand_dims (x , axis = (0 , 1 , 2 ), xp = xp )
@@ -513,7 +507,6 @@ def test_xp(self, xp: ModuleType):
513
507
xp_assert_equal (isclose (a , b , xp = xp ), xp .asarray ([True , False ]))
514
508
515
509
516
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
517
510
class TestKron :
518
511
def test_basic (self , xp : ModuleType ):
519
512
# Using 0-dimensional array
@@ -572,6 +565,7 @@ def test_kron_shape(
572
565
k = kron (a , b )
573
566
assert k .shape == expected_shape
574
567
568
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no isdtype" )
575
569
def test_python_scalar (self , xp : ModuleType ):
576
570
a = 1
577
571
# Test no dtype promotion to xp.asarray(a); use b.dtype
@@ -614,25 +608,27 @@ def test_xp(self, xp: ModuleType):
614
608
xp_assert_equal (nunique (a , xp = xp ), xp .asarray (3 ))
615
609
616
610
617
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no arange, no device" )
618
611
class TestPad :
619
612
def test_simple (self , xp : ModuleType ):
620
- a = xp .arange ( 1 , 4 )
613
+ a = xp .asarray ([ 1 , 2 , 3 ] )
621
614
padded = pad (a , 2 )
622
615
xp_assert_equal (padded , xp .asarray ([0 , 0 , 1 , 2 , 3 , 0 , 0 ]))
623
616
617
+ @pytest .mark .xfail_xp_backend (
618
+ Backend .SPARSE , reason = "constant_values can only be equal to fill value"
619
+ )
624
620
def test_fill_value (self , xp : ModuleType ):
625
- a = xp .arange ( 1 , 4 )
621
+ a = xp .asarray ([ 1 , 2 , 3 ] )
626
622
padded = pad (a , 2 , constant_values = 42 )
627
623
xp_assert_equal (padded , xp .asarray ([42 , 42 , 1 , 2 , 3 , 42 , 42 ]))
628
624
629
625
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 ) ))
631
627
padded = pad (a , 2 )
632
628
assert padded .shape == (6 , 7 , 8 )
633
629
634
630
def test_mode_not_implemented (self , xp : ModuleType ):
635
- a = xp .arange ( 3 )
631
+ a = xp .asarray ([ 1 , 2 , 3 ] )
636
632
with pytest .raises (NotImplementedError , match = "Only `'constant'`" ):
637
633
_ = pad (a , 2 , mode = "edge" ) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
638
634
@@ -645,7 +641,7 @@ def test_xp(self, xp: ModuleType):
645
641
xp_assert_equal (padded , xp .asarray (0 ))
646
642
647
643
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 ) ))
649
645
padded = pad (a , (1 , 0 ))
650
646
assert padded .shape == (4 , 5 )
651
647
@@ -656,7 +652,7 @@ def test_tuple_width(self, xp: ModuleType):
656
652
_ = pad (a , [(1 , 2 , 3 )]) # type: ignore[list-item] # pyright: ignore[reportArgumentType]
657
653
658
654
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 ) ))
660
656
661
657
padded = pad (a , ((1 , 0 ), (0 , 2 )))
662
658
assert padded .shape == (4 , 6 )
@@ -678,7 +674,7 @@ def test_sequence_of_tuples_width(self, xp: ModuleType):
678
674
)
679
675
680
676
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 " )
682
678
class TestSetDiff1D :
683
679
@pytest .mark .xfail_xp_backend (Backend .DASK , reason = "NaN-shaped arrays" )
684
680
@pytest .mark .xfail_xp_backend (
0 commit comments