41
41
lazy_xp_function (sinc , static_argnames = "xp" )
42
42
43
43
44
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
45
44
class TestAtLeastND :
46
45
def test_0D (self , xp : ModuleType ):
47
46
x = xp .asarray (1.0 )
@@ -68,7 +67,7 @@ def test_1D(self, xp: ModuleType):
68
67
xp_assert_equal (y , xp .asarray ([[0 , 1 ]]))
69
68
70
69
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 ]]]]] ))
72
71
73
72
def test_2D (self , xp : ModuleType ):
74
73
x = xp .asarray ([[3.0 ]])
@@ -217,8 +216,10 @@ def test_xp(self, xp: ModuleType):
217
216
)
218
217
219
218
219
+ @pytest .mark .skip_xp_backend (
220
+ Backend .SPARSE , reason = "read-only backend without .at support"
221
+ )
220
222
class TestCreateDiagonal :
221
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
222
223
def test_1d_from_numpy (self , xp : ModuleType ):
223
224
# from np.diag tests
224
225
vals = 100 * xp .arange (5 , dtype = xp .float64 )
@@ -234,7 +235,6 @@ def test_1d_from_numpy(self, xp: ModuleType):
234
235
xp_assert_equal (create_diagonal (vals , offset = 2 ), b )
235
236
xp_assert_equal (create_diagonal (vals , offset = - 2 ), c )
236
237
237
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
238
238
@pytest .mark .parametrize ("n" , range (1 , 10 ))
239
239
@pytest .mark .parametrize ("offset" , range (1 , 10 ))
240
240
def test_1d_from_scipy (self , xp : ModuleType , n : int , offset : int ):
@@ -250,7 +250,6 @@ def test_0d_raises(self, xp: ModuleType):
250
250
with pytest .raises (ValueError , match = "1-dimensional" ):
251
251
_ = create_diagonal (xp .asarray (1 ))
252
252
253
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
254
253
@pytest .mark .parametrize (
255
254
"shape" ,
256
255
[
@@ -276,28 +275,24 @@ def test_nd(self, xp: ModuleType, shape: tuple[int, ...]):
276
275
for i in ndindex (* eager_shape (c )):
277
276
xp_assert_equal (c [i ], b [i [:- 1 ]] if i [- 2 ] == i [- 1 ] else zero )
278
277
279
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
280
278
def test_device (self , xp : ModuleType , device : Device ):
281
279
x = xp .asarray ([1 , 2 , 3 ], device = device )
282
280
assert get_device (create_diagonal (x )) == device
283
281
284
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
285
282
def test_xp (self , xp : ModuleType ):
286
283
x = xp .asarray ([1 , 2 ])
287
284
y = create_diagonal (x , xp = xp )
288
285
xp_assert_equal (y , xp .asarray ([[1 , 0 ], [0 , 2 ]]))
289
286
290
287
291
288
class TestExpandDims :
292
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
293
289
def test_single_axis (self , xp : ModuleType ):
294
290
"""Trivial case where xpx.expand_dims doesn't add anything to xp.expand_dims"""
295
291
a = xp .empty ((2 , 3 , 4 , 5 ))
296
292
for axis in range (- 5 , 4 ):
297
293
b = expand_dims (a , axis = axis )
298
294
xp_assert_equal (b , xp .expand_dims (a , axis = axis ))
299
295
300
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
301
296
def test_axis_tuple (self , xp : ModuleType ):
302
297
a = xp .empty ((3 , 3 , 3 ))
303
298
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):
329
324
with pytest .raises (ValueError , match = "Duplicate dimensions" ):
330
325
_ = expand_dims (a , axis = (3 , - 3 ))
331
326
332
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
333
327
def test_device (self , xp : ModuleType , device : Device ):
334
328
x = xp .asarray ([1 , 2 , 3 ], device = device )
335
329
assert get_device (expand_dims (x , axis = 0 )) == device
336
330
337
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
338
331
def test_xp (self , xp : ModuleType ):
339
332
x = xp .asarray ([1 , 2 , 3 ])
340
333
y = expand_dims (x , axis = (0 , 1 , 2 ), xp = xp )
@@ -501,7 +494,6 @@ def test_xp(self, xp: ModuleType):
501
494
xp_assert_equal (isclose (a , b , xp = xp ), xp .asarray ([True , False ]))
502
495
503
496
504
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
505
497
class TestKron :
506
498
def test_basic (self , xp : ModuleType ):
507
499
# Using 0-dimensional array
@@ -560,6 +552,7 @@ def test_kron_shape(
560
552
k = kron (a , b )
561
553
assert k .shape == expected_shape
562
554
555
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no isdtype" )
563
556
def test_python_scalar (self , xp : ModuleType ):
564
557
a = 1
565
558
# Test no dtype promotion to xp.asarray(a); use b.dtype
@@ -602,25 +595,27 @@ def test_xp(self, xp: ModuleType):
602
595
xp_assert_equal (nunique (a , xp = xp ), xp .asarray (3 ))
603
596
604
597
605
- @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no arange, no device" )
606
598
class TestPad :
607
599
def test_simple (self , xp : ModuleType ):
608
- a = xp .arange ( 1 , 4 )
600
+ a = xp .asarray ([ 1 , 2 , 3 ] )
609
601
padded = pad (a , 2 )
610
602
xp_assert_equal (padded , xp .asarray ([0 , 0 , 1 , 2 , 3 , 0 , 0 ]))
611
603
604
+ @pytest .mark .xfail_xp_backend (
605
+ Backend .SPARSE , reason = "constant_values can only be equal to fill value"
606
+ )
612
607
def test_fill_value (self , xp : ModuleType ):
613
- a = xp .arange ( 1 , 4 )
608
+ a = xp .asarray ([ 1 , 2 , 3 ] )
614
609
padded = pad (a , 2 , constant_values = 42 )
615
610
xp_assert_equal (padded , xp .asarray ([42 , 42 , 1 , 2 , 3 , 42 , 42 ]))
616
611
617
612
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 ) ))
619
614
padded = pad (a , 2 )
620
615
assert padded .shape == (6 , 7 , 8 )
621
616
622
617
def test_mode_not_implemented (self , xp : ModuleType ):
623
- a = xp .arange ( 3 )
618
+ a = xp .asarray ([ 1 , 2 , 3 ] )
624
619
with pytest .raises (NotImplementedError , match = "Only `'constant'`" ):
625
620
_ = pad (a , 2 , mode = "edge" ) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
626
621
@@ -633,7 +628,7 @@ def test_xp(self, xp: ModuleType):
633
628
xp_assert_equal (padded , xp .asarray (0 ))
634
629
635
630
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 ) ))
637
632
padded = pad (a , (1 , 0 ))
638
633
assert padded .shape == (4 , 5 )
639
634
@@ -644,7 +639,7 @@ def test_tuple_width(self, xp: ModuleType):
644
639
_ = pad (a , [(1 , 2 , 3 )]) # type: ignore[list-item] # pyright: ignore[reportArgumentType]
645
640
646
641
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 ) ))
648
643
649
644
padded = pad (a , ((1 , 0 ), (0 , 2 )))
650
645
assert padded .shape == (4 , 6 )
@@ -666,7 +661,7 @@ def test_sequence_of_tuples_width(self, xp: ModuleType):
666
661
)
667
662
668
663
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 " )
670
665
class TestSetDiff1D :
671
666
@pytest .mark .xfail_xp_backend (Backend .DASK , reason = "NaN-shaped arrays" )
672
667
@pytest .mark .xfail_xp_backend (
0 commit comments