7
7
8
8
9
9
class TestSearch :
10
+
10
11
@testing .for_all_dtypes (no_complex = True )
11
12
@testing .numpy_cupy_allclose ()
12
13
def test_argmax_all (self , xp , dtype ):
@@ -167,6 +168,13 @@ def test_argmin_int32_overflow(self):
167
168
assert a .argmin ().item () == 2 ** 32
168
169
169
170
171
+ # TODO(leofang): remove this once CUDA 9.0 is dropped
172
+ def _skip_cuda90 (dtype ):
173
+ ver = cupy .cuda .runtime .runtimeGetVersion ()
174
+ if dtype == cupy .float16 and ver == 9000 :
175
+ pytest .skip ("CUB does not support fp16 on CUDA 9.0" )
176
+
177
+
170
178
# This class compares CUB results against NumPy's
171
179
# TODO(leofang): test axis after support is added
172
180
@testing .parameterize (
@@ -180,6 +188,7 @@ def test_argmin_int32_overflow(self):
180
188
)
181
189
@pytest .mark .skip ("The CUB routine is not enabled" )
182
190
class TestCubReduction :
191
+
183
192
@pytest .fixture (autouse = True )
184
193
def setUp (self ):
185
194
self .order , self .axis = self .order_and_axis
@@ -200,6 +209,7 @@ def setUp(self):
200
209
@testing .for_dtypes ("bhilBHILefdFD" )
201
210
@testing .numpy_cupy_allclose (rtol = 1e-5 , contiguous_check = False )
202
211
def test_cub_argmin (self , xp , dtype ):
212
+ _skip_cuda90 (dtype )
203
213
a = testing .shaped_random (self .shape , xp , dtype )
204
214
if self .order == "C" :
205
215
a = xp .ascontiguousarray (a )
@@ -220,7 +230,7 @@ def test_cub_argmin(self, xp, dtype):
220
230
# this is the only function we can mock; the rest is cdef'd
221
231
func_name = "cupy._core._cub_reduction."
222
232
func_name += "_SimpleCubReductionKernel_get_cached_function"
223
- # func = _cub_reduction._SimpleCubReductionKernel_get_cached_function
233
+ func = _cub_reduction ._SimpleCubReductionKernel_get_cached_function
224
234
if self .axis is not None and len (self .shape ) > 1 :
225
235
times_called = 1 # one pass
226
236
else :
@@ -235,7 +245,7 @@ def test_cub_argmin(self, xp, dtype):
235
245
@testing .for_dtypes ("bhilBHILefdFD" )
236
246
@testing .numpy_cupy_allclose (rtol = 1e-5 , contiguous_check = False )
237
247
def test_cub_argmax (self , xp , dtype ):
238
- # _skip_cuda90(dtype)
248
+ _skip_cuda90 (dtype )
239
249
a = testing .shaped_random (self .shape , xp , dtype )
240
250
if self .order == "C" :
241
251
a = xp .ascontiguousarray (a )
@@ -256,7 +266,7 @@ def test_cub_argmax(self, xp, dtype):
256
266
# this is the only function we can mock; the rest is cdef'd
257
267
func_name = "cupy._core._cub_reduction."
258
268
func_name += "_SimpleCubReductionKernel_get_cached_function"
259
- # func = _cub_reduction._SimpleCubReductionKernel_get_cached_function
269
+ func = _cub_reduction ._SimpleCubReductionKernel_get_cached_function
260
270
if self .axis is not None and len (self .shape ) > 1 :
261
271
times_called = 1 # one pass
262
272
else :
@@ -280,6 +290,7 @@ def test_cub_argmax(self, xp, dtype):
280
290
)
281
291
@pytest .mark .skip ("dtype is not supported" )
282
292
class TestArgMinMaxDtype :
293
+
283
294
@testing .for_dtypes (
284
295
dtypes = [numpy .int8 , numpy .int16 , numpy .int32 , numpy .int64 ],
285
296
name = "result_dtype" ,
@@ -304,6 +315,7 @@ def test_argminmax_dtype(self, in_dtype, result_dtype):
304
315
{"cond_shape" : (3 , 4 ), "x_shape" : (2 , 3 , 4 ), "y_shape" : (4 ,)},
305
316
)
306
317
class TestWhereTwoArrays :
318
+
307
319
@testing .for_all_dtypes_combination (names = ["cond_type" , "x_type" , "y_type" ])
308
320
@testing .numpy_cupy_allclose (type_check = has_support_aspect64 ())
309
321
def test_where_two_arrays (self , xp , cond_type , x_type , y_type ):
@@ -323,6 +335,7 @@ def test_where_two_arrays(self, xp, cond_type, x_type, y_type):
323
335
{"cond_shape" : (3 , 4 )},
324
336
)
325
337
class TestWhereCond :
338
+
326
339
@testing .for_all_dtypes ()
327
340
@testing .numpy_cupy_array_equal ()
328
341
def test_where_cond (self , xp , dtype ):
@@ -332,6 +345,7 @@ def test_where_cond(self, xp, dtype):
332
345
333
346
334
347
class TestWhereError :
348
+
335
349
def test_one_argument (self ):
336
350
for xp in (numpy , cupy ):
337
351
cond = testing .shaped_random ((3 , 4 ), xp , dtype = xp .bool_ )
@@ -349,6 +363,7 @@ def test_one_argument(self):
349
363
_ids = False , # Do not generate ids from randomly generated params
350
364
)
351
365
class TestNonzero :
366
+
352
367
@testing .for_all_dtypes ()
353
368
@testing .numpy_cupy_array_equal ()
354
369
def test_nonzero (self , xp , dtype ):
@@ -360,15 +375,21 @@ def test_nonzero(self, xp, dtype):
360
375
{"array" : numpy .array (0 )},
361
376
{"array" : numpy .array (1 )},
362
377
)
363
- @pytest .mark .skip ("Only positive rank is supported" )
364
378
@testing .with_requires ("numpy>=1.17.0" )
365
379
class TestNonzeroZeroDimension :
380
+
381
+ @testing .with_requires ("numpy>=2.1" )
382
+ @testing .for_all_dtypes ()
383
+ def test_nonzero (self , dtype ):
384
+ array = cupy .array (self .array , dtype = dtype )
385
+ with pytest .raises (ValueError ):
386
+ cupy .nonzero (array )
387
+
366
388
@testing .for_all_dtypes ()
367
389
@testing .numpy_cupy_array_equal ()
368
- def test_nonzero (self , xp , dtype ):
390
+ def test_nonzero_explicit (self , xp , dtype ):
369
391
array = xp .array (self .array , dtype = dtype )
370
- with testing .assert_warns (DeprecationWarning ):
371
- return xp .nonzero (array )
392
+ return xp .nonzero (xp .atleast_1d (array ))
372
393
373
394
374
395
@testing .parameterize (
@@ -382,6 +403,7 @@ def test_nonzero(self, xp, dtype):
382
403
_ids = False , # Do not generate ids from randomly generated params
383
404
)
384
405
class TestFlatNonzero :
406
+
385
407
@testing .for_all_dtypes ()
386
408
@testing .numpy_cupy_array_equal ()
387
409
def test_flatnonzero (self , xp , dtype ):
@@ -398,6 +420,7 @@ def test_flatnonzero(self, xp, dtype):
398
420
_ids = False , # Do not generate ids from randomly generated params
399
421
)
400
422
class TestArgwhere :
423
+
401
424
@testing .for_all_dtypes ()
402
425
@testing .numpy_cupy_array_equal ()
403
426
def test_argwhere (self , xp , dtype ):
@@ -411,6 +434,7 @@ def test_argwhere(self, xp, dtype):
411
434
)
412
435
@testing .with_requires ("numpy>=1.18" )
413
436
class TestArgwhereZeroDimension :
437
+
414
438
@testing .for_all_dtypes ()
415
439
@testing .numpy_cupy_array_equal ()
416
440
def test_argwhere (self , xp , dtype ):
@@ -419,6 +443,7 @@ def test_argwhere(self, xp, dtype):
419
443
420
444
421
445
class TestNanArgMin :
446
+
422
447
@testing .for_all_dtypes (no_complex = True )
423
448
@testing .numpy_cupy_allclose ()
424
449
def test_nanargmin_all (self , xp , dtype ):
@@ -509,6 +534,7 @@ def test_nanargmin_zero_size_axis1(self, xp, dtype):
509
534
510
535
511
536
class TestNanArgMax :
537
+
512
538
@testing .for_all_dtypes (no_complex = True )
513
539
@testing .numpy_cupy_allclose ()
514
540
def test_nanargmax_all (self , xp , dtype ):
@@ -620,6 +646,7 @@ def test_nanargmax_zero_size_axis1(self, xp, dtype):
620
646
)
621
647
)
622
648
class TestSearchSorted :
649
+
623
650
@testing .for_all_dtypes (no_bool = True )
624
651
@testing .numpy_cupy_array_equal ()
625
652
def test_searchsorted (self , xp , dtype ):
@@ -639,6 +666,7 @@ def test_ndarray_searchsorted(self, xp, dtype):
639
666
640
667
@testing .parameterize ({"side" : "left" }, {"side" : "right" })
641
668
class TestSearchSortedNanInf :
669
+
642
670
@testing .numpy_cupy_array_equal ()
643
671
def test_searchsorted_nanbins (self , xp ):
644
672
x = testing .shaped_arange ((10 ,), xp , xp .float64 )
@@ -704,6 +732,7 @@ def test_searchsorted_minf(self, xp):
704
732
705
733
706
734
class TestSearchSortedInvalid :
735
+
707
736
# Can't test unordered bins due to numpy undefined
708
737
# behavior for searchsorted
709
738
@@ -723,6 +752,7 @@ def test_ndarray_searchsorted_ndbins(self):
723
752
724
753
725
754
class TestSearchSortedWithSorter :
755
+
726
756
@testing .numpy_cupy_array_equal ()
727
757
def test_sorter (self , xp ):
728
758
x = testing .shaped_arange ((12 ,), xp , xp .float64 )
@@ -741,16 +771,16 @@ def test_invalid_sorter(self):
741
771
742
772
def test_nonint_sorter (self ):
743
773
for xp in (numpy , cupy ):
744
- dt = cupy .default_float_type ()
745
- x = testing .shaped_arange ((12 ,), xp , dt )
774
+ x = testing .shaped_arange ((12 ,), xp , xp .float32 )
746
775
bins = xp .array ([10 , 4 , 2 , 1 , 8 ])
747
- sorter = xp .array ([], dtype = dt )
776
+ sorter = xp .array ([], dtype = xp . float32 )
748
777
with pytest .raises ((TypeError , ValueError )):
749
778
xp .searchsorted (bins , x , sorter = sorter )
750
779
751
780
752
781
@testing .parameterize ({"side" : "left" }, {"side" : "right" })
753
782
class TestNdarraySearchSortedNanInf :
783
+
754
784
@testing .numpy_cupy_array_equal ()
755
785
def test_searchsorted_nanbins (self , xp ):
756
786
x = testing .shaped_arange ((10 ,), xp , xp .float64 )
@@ -816,6 +846,7 @@ def test_searchsorted_minf(self, xp):
816
846
817
847
818
848
class TestNdarraySearchSortedWithSorter :
849
+
819
850
@testing .numpy_cupy_array_equal ()
820
851
def test_sorter (self , xp ):
821
852
x = testing .shaped_arange ((12 ,), xp , xp .float64 )
@@ -834,9 +865,8 @@ def test_invalid_sorter(self):
834
865
835
866
def test_nonint_sorter (self ):
836
867
for xp in (numpy , cupy ):
837
- dt = cupy .default_float_type ()
838
- x = testing .shaped_arange ((12 ,), xp , dt )
868
+ x = testing .shaped_arange ((12 ,), xp , xp .float32 )
839
869
bins = xp .array ([10 , 4 , 2 , 1 , 8 ])
840
- sorter = xp .array ([], dtype = dt )
870
+ sorter = xp .array ([], dtype = xp . float32 )
841
871
with pytest .raises ((TypeError , ValueError )):
842
872
bins .searchsorted (x , sorter = sorter )
0 commit comments