41
41
lazy_xp_function (sinc , jax_jit = False , static_argnames = "xp" )
42
42
43
43
44
- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
44
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
45
45
class TestAtLeastND :
46
46
def test_0D (self , xp : ModuleType ):
47
47
x = xp .asarray (1.0 )
@@ -108,12 +108,12 @@ def test_device(self, xp: ModuleType, device: Device):
108
108
assert get_device (atleast_nd (x , ndim = 2 )) == device
109
109
110
110
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 ,)) )
114
114
115
115
116
- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no isdtype" )
116
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no isdtype" )
117
117
class TestCov :
118
118
def test_basic (self , xp : ModuleType ):
119
119
xp_assert_close (
@@ -152,16 +152,16 @@ def test_device(self, xp: ModuleType, device: Device):
152
152
x = xp .asarray ([1 , 2 , 3 ], device = device )
153
153
assert get_device (cov (x )) == device
154
154
155
- @pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "explicit xp" )
155
+ @pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "xp= xp" )
156
156
def test_xp (self , xp : ModuleType ):
157
157
xp_assert_close (
158
158
cov (xp .asarray ([[0.0 , 2.0 ], [1.0 , 1.0 ], [2.0 , 0.0 ]]).T , xp = xp ),
159
159
xp .asarray ([[1.0 , - 1.0 ], [- 1.0 , 1.0 ]], dtype = xp .float64 ),
160
160
)
161
161
162
162
163
- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no device" )
164
163
class TestCreateDiagonal :
164
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
165
165
def test_1d (self , xp : ModuleType ):
166
166
# from np.diag tests
167
167
vals = 100 * xp .arange (5 , dtype = xp .float64 )
@@ -177,6 +177,7 @@ def test_1d(self, xp: ModuleType):
177
177
xp_assert_equal (create_diagonal (vals , offset = 2 ), b )
178
178
xp_assert_equal (create_diagonal (vals , offset = - 2 ), c )
179
179
180
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
180
181
@pytest .mark .parametrize ("n" , range (1 , 10 ))
181
182
@pytest .mark .parametrize ("offset" , range (1 , 10 ))
182
183
def test_create_diagonal (self , xp : ModuleType , n : int , offset : int ):
@@ -196,20 +197,22 @@ def test_2d(self, xp: ModuleType):
196
197
with pytest .raises (ValueError , match = "1-dimensional" ):
197
198
create_diagonal (xp .asarray ([[1 ]]))
198
199
200
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
199
201
def test_device (self , xp : ModuleType , device : Device ):
200
202
x = xp .asarray ([1 , 2 , 3 ], device = device )
201
203
assert get_device (create_diagonal (x )) == device
202
204
205
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no device kwarg in zeros()" )
203
206
def test_xp (self , xp : ModuleType ):
204
207
x = xp .asarray ([1 , 2 ])
205
208
y = create_diagonal (x , xp = xp )
206
209
xp_assert_equal (y , xp .asarray ([[1 , 0 ], [0 , 2 ]]))
207
210
208
211
209
- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
210
212
class 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" )
213
216
def test_functionality (self , xp : ModuleType ):
214
217
def _squeeze_all (b : Array ) -> Array :
215
218
"""Mimics `np.squeeze(b)`. `xpx.squeeze`?"""
@@ -225,6 +228,7 @@ def _squeeze_all(b: Array) -> Array:
225
228
assert b .shape [axis ] == 1
226
229
assert _squeeze_all (b ).shape == s
227
230
231
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
228
232
def test_axis_tuple (self , xp : ModuleType ):
229
233
a = xp .empty ((3 , 3 , 3 ))
230
234
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):
257
261
with pytest .raises (ValueError , match = "Duplicate dimensions" ):
258
262
expand_dims (a , axis = (3 , - 3 ))
259
263
264
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
260
265
def test_device (self , xp : ModuleType , device : Device ):
261
266
x = xp .asarray ([1 , 2 , 3 ], device = device )
262
267
assert get_device (expand_dims (x , axis = 0 )) == device
263
268
269
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
264
270
def test_xp (self , xp : ModuleType ):
265
271
x = xp .asarray ([1 , 2 , 3 ])
266
272
y = expand_dims (x , axis = (0 , 1 , 2 ), xp = xp )
267
273
assert y .shape == (1 , 1 , 1 , 3 )
268
274
269
275
270
- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no isdtype" )
276
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no isdtype" )
271
277
class TestIsClose :
272
278
# FIXME use lazywhere to avoid warnings on inf
273
279
@pytest .mark .filterwarnings ("ignore:invalid value encountered" )
@@ -402,7 +408,7 @@ def test_none_shape_bool(self, xp: ModuleType):
402
408
xp_assert_equal (isclose (a , b ), xp .asarray ([True , False ]))
403
409
404
410
@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" )
406
412
def test_python_scalar (self , xp : ModuleType ):
407
413
a = xp .asarray ([0.0 , 0.1 ], dtype = xp .float32 )
408
414
xp_assert_equal (isclose (a , 0.0 ), xp .asarray ([True , False ]))
@@ -425,7 +431,7 @@ def test_xp(self, xp: ModuleType):
425
431
xp_assert_equal (isclose (a , b , xp = xp ), xp .asarray ([True , False ]))
426
432
427
433
428
- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
434
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no expand_dims" )
429
435
class TestKron :
430
436
def test_basic (self , xp : ModuleType ):
431
437
# Using 0-dimensional array
@@ -526,7 +532,7 @@ def test_xp(self, xp: ModuleType):
526
532
xp_assert_equal (nunique (a , xp = xp ), xp .asarray (3 ))
527
533
528
534
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" )
530
536
class TestPad :
531
537
def test_simple (self , xp : ModuleType ):
532
538
a = xp .arange (1 , 4 )
@@ -576,10 +582,24 @@ def test_sequence_of_tuples_width(self, xp: ModuleType):
576
582
assert padded .shape == (4 , 4 )
577
583
578
584
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()" )
581
600
class 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 (
583
603
Backend .TORCH , reason = "index_select not implemented for uint32"
584
604
)
585
605
def test_setdiff1d (self , xp : ModuleType ):
@@ -608,7 +628,7 @@ def test_assume_unique(self, xp: ModuleType):
608
628
actual = setdiff1d (x1 , x2 , assume_unique = True )
609
629
xp_assert_equal (actual , expected )
610
630
611
- @pytest . mark . parametrize ( " assume_unique" , [ True , False ])
631
+ @assume_unique
612
632
@pytest .mark .parametrize ("shape1" , [(), (1 ,), (1 , 1 )])
613
633
@pytest .mark .parametrize ("shape2" , [(), (1 ,), (1 , 1 )])
614
634
def test_shapes (
@@ -623,8 +643,8 @@ def test_shapes(
623
643
actual = setdiff1d (x1 , x2 , assume_unique = assume_unique )
624
644
xp_assert_equal (actual , xp .empty ((0 ,)))
625
645
646
+ @assume_unique
626
647
@pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "xp=xp" )
627
- @pytest .mark .parametrize ("assume_unique" , [True , False ])
628
648
def test_python_scalar (self , xp : ModuleType , assume_unique : bool ):
629
649
# Test no dtype promotion to xp.asarray(x2); use x1.dtype
630
650
x1 = xp .asarray ([3 , 1 , 2 ], dtype = xp .int16 )
@@ -645,21 +665,22 @@ def test_all_python_scalars(self, assume_unique: bool):
645
665
with pytest .raises (TypeError , match = "Unrecognized" ):
646
666
setdiff1d (0 , 0 , assume_unique = assume_unique )
647
667
648
- def test_device (self , xp : ModuleType , device : Device ):
668
+ @assume_unique
669
+ def test_device (self , xp : ModuleType , device : Device , assume_unique : bool ):
649
670
x1 = xp .asarray ([3 , 8 , 20 ], device = device )
650
671
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
652
673
653
- @pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "explicit xp" )
674
+ @pytest .mark .skip_xp_backend (Backend .NUMPY_READONLY , reason = "xp= xp" )
654
675
def test_xp (self , xp : ModuleType ):
655
676
x1 = xp .asarray ([3 , 8 , 20 ])
656
677
x2 = xp .asarray ([2 , 3 , 4 ])
657
678
expected = xp .asarray ([8 , 20 ])
658
- actual = setdiff1d (x1 , x2 , xp = xp )
679
+ actual = setdiff1d (x1 , x2 , assume_unique = True , xp = xp )
659
680
xp_assert_equal (actual , expected )
660
681
661
682
662
- @pytest .mark .skip_xp_backend (Backend .SPARSE , reason = "no isdtype" )
683
+ @pytest .mark .xfail_xp_backend (Backend .SPARSE , reason = "no isdtype" )
663
684
class TestSinc :
664
685
def test_simple (self , xp : ModuleType ):
665
686
xp_assert_equal (sinc (xp .asarray (0.0 )), xp .asarray (1.0 ))
0 commit comments