44import pytest
55
66import dpnp as cupy
7+ from dpnp .tests .helper import has_support_aspect64
78from dpnp .tests .third_party .cupy import testing
89
910
1011class TestElementwise (unittest .TestCase ):
12+
1113 def check_copy (self , dtype , src_id , dst_id ):
1214 with cuda .Device (src_id ):
1315 src = testing .shaped_arange ((2 , 3 , 4 ), dtype = dtype )
@@ -16,21 +18,21 @@ def check_copy(self, dtype, src_id, dst_id):
1618 _core .elementwise_copy (src , dst )
1719 testing .assert_allclose (src , dst )
1820
19- @pytest .mark .skip ("`device` argument isn't supported" )
21+ @pytest .mark .skip ("elementwise_copy() argument isn't supported" )
2022 @testing .for_all_dtypes ()
2123 def test_copy (self , dtype ):
2224 device_id = cuda .Device ().id
2325 self .check_copy (dtype , device_id , device_id )
2426
25- @pytest .mark .skip ("`device` argument isn't supported" )
27+ @pytest .mark .skip ("elementwise_copy() argument isn't supported" )
2628 @testing .for_all_dtypes ()
2729 def test_copy_multigpu_nopeer (self , dtype ):
2830 if cuda .runtime .deviceCanAccessPeer (0 , 1 ) == 1 :
2931 pytest .skip ("peer access is available" )
3032 with self .assertRaises (ValueError ):
3133 self .check_copy (dtype , 0 , 1 )
3234
33- @pytest .mark .skip ("`device` argument isn't supported" )
35+ @pytest .mark .skip ("elementwise_copy() argument isn't supported" )
3436 @testing .for_all_dtypes ()
3537 def test_copy_multigpu_peer (self , dtype ):
3638 if cuda .runtime .deviceCanAccessPeer (0 , 1 ) != 1 :
@@ -67,8 +69,9 @@ def test_copy_orders(self, order):
6769 assert b .strides == tuple (x / b_cpu .itemsize for x in b_cpu .strides )
6870
6971
70- @pytest .mark .skip ("`ElementwiseKernel` function isn't supported" )
72+ @pytest .mark .skip ("`ElementwiseKernel` isn't supported" )
7173class TestElementwiseInvalidShape (unittest .TestCase ):
74+
7275 def test_invalid_shape (self ):
7376 with self .assertRaisesRegex (ValueError , "Out shape is mismatched" ):
7477 f = cupy .ElementwiseKernel ("T x" , "T y" , "y += x" )
@@ -77,67 +80,102 @@ def test_invalid_shape(self):
7780 f (x , y )
7881
7982
80- @pytest .mark .skip ("`ElementwiseKernel` function isn't supported" )
83+ @pytest .mark .skip ("`ElementwiseKernel` isn't supported" )
8184class TestElementwiseInvalidArgument (unittest .TestCase ):
85+
8286 def test_invalid_kernel_name (self ):
8387 with self .assertRaisesRegex (ValueError , "Invalid kernel name" ):
8488 cupy .ElementwiseKernel ("T x" , "" , "" , "1" )
8589
8690
87- @pytest .mark .skip ("`iinfo` function isn't supported" )
8891class TestElementwiseType (unittest .TestCase ):
92+
93+ @testing .with_requires ("numpy>=2.0" )
8994 @testing .for_int_dtypes (no_bool = True )
90- @testing .numpy_cupy_array_equal ()
95+ @testing .numpy_cupy_array_equal (accept_error = OverflowError )
9196 def test_large_int_upper_1 (self , xp , dtype ):
92- a = xp .array ([0 ], dtype = xp .int8 )
97+ a = xp .array ([0 ], dtype = numpy .int8 )
9398 b = xp .iinfo (dtype ).max
9499 return a + b
95100
96101 @testing .for_int_dtypes (no_bool = True )
97- @testing .numpy_cupy_array_equal ()
102+ @testing .numpy_cupy_array_equal (accept_error = OverflowError )
98103 def test_large_int_upper_2 (self , xp , dtype ):
99- a = xp .array ([1 ], dtype = xp .int8 )
104+ if (
105+ numpy .issubdtype (dtype , numpy .unsignedinteger )
106+ and numpy .lib .NumpyVersion (numpy .__version__ ) < "2.0.0"
107+ ):
108+ pytest .skip ("numpy promotes dtype differently" )
109+
110+ a = xp .array ([1 ], dtype = numpy .int8 )
100111 b = xp .iinfo (dtype ).max - 1
101112 return a + b
102113
103114 @testing .for_int_dtypes (no_bool = True )
104115 @testing .numpy_cupy_array_equal ()
105116 def test_large_int_upper_3 (self , xp , dtype ):
117+ if (
118+ numpy .issubdtype (dtype , numpy .unsignedinteger )
119+ and numpy .lib .NumpyVersion (numpy .__version__ ) < "2.0.0"
120+ ):
121+ pytest .skip ("numpy promotes dtype differently" )
122+ elif dtype == numpy .uint64 and not has_support_aspect64 ():
123+ pytest .skip ("no fp64 support" )
124+
106125 a = xp .array ([xp .iinfo (dtype ).max ], dtype = dtype )
107- b = xp .int8 (0 )
126+ b = numpy .int8 (0 )
108127 return a + b
109128
110129 @testing .for_int_dtypes (no_bool = True )
111130 @testing .numpy_cupy_array_equal ()
112131 def test_large_int_upper_4 (self , xp , dtype ):
132+ if (
133+ numpy .issubdtype (dtype , numpy .unsignedinteger )
134+ and numpy .lib .NumpyVersion (numpy .__version__ ) < "2.0.0"
135+ ):
136+ pytest .skip ("numpy promotes dtype differently" )
137+ elif dtype == numpy .uint64 and not has_support_aspect64 ():
138+ pytest .skip ("no fp64 support" )
139+
113140 a = xp .array ([xp .iinfo (dtype ).max - 1 ], dtype = dtype )
114- b = xp .int8 (1 )
141+ b = numpy .int8 (1 )
115142 return a + b
116143
117144 @testing .for_int_dtypes (no_bool = True )
118- @testing .numpy_cupy_array_equal ()
145+ @testing .numpy_cupy_array_equal (accept_error = OverflowError )
119146 def test_large_int_lower_1 (self , xp , dtype ):
120- a = xp .array ([0 ], dtype = xp .int8 )
147+ a = xp .array ([0 ], dtype = numpy .int8 )
121148 b = xp .iinfo (dtype ).min
122149 return a + b
123150
124151 @testing .for_int_dtypes (no_bool = True )
125- @testing .numpy_cupy_array_equal ()
152+ @testing .numpy_cupy_array_equal (accept_error = OverflowError )
126153 def test_large_int_lower_2 (self , xp , dtype ):
127- a = xp .array ([- 1 ], dtype = xp .int8 )
154+ a = xp .array ([- 1 ], dtype = numpy .int8 )
128155 b = xp .iinfo (dtype ).min + 1
129156 return a + b
130157
131158 @testing .for_int_dtypes (no_bool = True )
132159 @testing .numpy_cupy_array_equal ()
133160 def test_large_int_lower_3 (self , xp , dtype ):
161+ if (
162+ numpy .issubdtype (dtype , numpy .unsignedinteger )
163+ and numpy .lib .NumpyVersion (numpy .__version__ ) < "2.0.0"
164+ ):
165+ pytest .skip ("numpy promotes dtype differently" )
166+ elif dtype == numpy .uint64 and not has_support_aspect64 ():
167+ pytest .skip ("no fp64 support" )
168+
134169 a = xp .array ([xp .iinfo (dtype ).min ], dtype = dtype )
135- b = xp .int8 (0 )
170+ b = numpy .int8 (0 )
136171 return a + b
137172
138173 @testing .for_int_dtypes (no_bool = True )
139174 @testing .numpy_cupy_array_equal ()
140175 def test_large_int_lower_4 (self , xp , dtype ):
176+ if dtype == numpy .uint64 and not has_support_aspect64 ():
177+ pytest .skip ("no fp64 support" )
178+
141179 a = xp .array ([xp .iinfo (dtype ).min + 1 ], dtype = dtype )
142- b = xp .int8 (- 1 )
180+ b = numpy .int8 (- 1 )
143181 return a + b
0 commit comments