1- import unittest
1+ from __future__ import annotations
22
33import numpy
44import pytest
1212from dpnp .tests .third_party .cupy import testing
1313
1414
15- class TestElementwise ( unittest . TestCase ) :
15+ class TestElementwise :
1616
1717 def check_copy (self , dtype , src_id , dst_id ):
1818 with cuda .Device (src_id ):
@@ -33,7 +33,7 @@ def test_copy(self, dtype):
3333 def test_copy_multigpu_nopeer (self , dtype ):
3434 if cuda .runtime .deviceCanAccessPeer (0 , 1 ) == 1 :
3535 pytest .skip ("peer access is available" )
36- with self . assertRaises (ValueError ):
36+ with pytest . raises (ValueError ):
3737 self .check_copy (dtype , 0 , 1 )
3838
3939 @pytest .mark .skip ("elementwise_copy() argument isn't supported" )
@@ -74,27 +74,26 @@ def test_copy_orders(self, order):
7474
7575
7676@pytest .mark .skip ("`ElementwiseKernel` isn't supported" )
77- class TestElementwiseInvalidShape ( unittest . TestCase ) :
77+ class TestElementwiseInvalidShape :
7878
7979 def test_invalid_shape (self ):
80- with self . assertRaisesRegex (ValueError , "Out shape is mismatched" ):
80+ with pytest . raises (ValueError , match = "Out shape is mismatched" ):
8181 f = cupy .ElementwiseKernel ("T x" , "T y" , "y += x" )
8282 x = cupy .arange (12 ).reshape (3 , 4 )
8383 y = cupy .arange (4 )
8484 f (x , y )
8585
8686
8787@pytest .mark .skip ("`ElementwiseKernel` isn't supported" )
88- class TestElementwiseInvalidArgument ( unittest . TestCase ) :
88+ class TestElementwiseInvalidArgument :
8989
9090 def test_invalid_kernel_name (self ):
91- with self . assertRaisesRegex (ValueError , "Invalid kernel name" ):
91+ with pytest . raises (ValueError , match = "Invalid kernel name" ):
9292 cupy .ElementwiseKernel ("T x" , "" , "" , "1" )
9393
9494
95- class TestElementwiseType ( unittest . TestCase ) :
95+ class TestElementwiseType :
9696
97- @testing .with_requires ("numpy>=2.0" )
9897 @testing .for_int_dtypes (no_bool = True )
9998 @testing .numpy_cupy_array_equal (accept_error = OverflowError )
10099 def test_large_int_upper_1 (self , xp , dtype ):
@@ -105,14 +104,6 @@ def test_large_int_upper_1(self, xp, dtype):
105104 @testing .for_int_dtypes (no_bool = True )
106105 @testing .numpy_cupy_array_equal (accept_error = OverflowError )
107106 def test_large_int_upper_2 (self , xp , dtype ):
108- if numpy_version () < "2.0.0" :
109- flag = dtype in [xp .int16 , xp .int32 , xp .int64 , xp .longlong ]
110- if xp .issubdtype (dtype , xp .unsignedinteger ) or flag :
111- pytest .skip ("numpy doesn't raise OverflowError" )
112-
113- if dtype in [xp .int8 , xp .intc ] and is_win_platform ():
114- pytest .skip ("numpy promotes dtype differently" )
115-
116107 a = xp .array ([1 ], dtype = xp .int8 )
117108 b = xp .iinfo (dtype ).max - 1
118109 return a + b
@@ -121,62 +112,38 @@ def test_large_int_upper_2(self, xp, dtype):
121112 @testing .numpy_cupy_array_equal ()
122113 def test_large_int_upper_3 (self , xp , dtype ):
123114 if (
124- numpy .issubdtype (dtype , numpy .unsignedinteger )
125- and numpy_version () < "2.0.0"
126- ):
127- pytest .skip ("numpy promotes dtype differently" )
128- elif (
129115 dtype in (numpy .uint64 , numpy .ulonglong )
130116 and not has_support_aspect64 ()
131117 ):
132118 pytest .skip ("no fp64 support" )
133119
134120 a = xp .array ([xp .iinfo (dtype ).max ], dtype = dtype )
135- b = numpy .int8 (0 )
121+ b = xp .int8 (0 )
136122 return a + b
137123
138124 @testing .for_int_dtypes (no_bool = True )
139125 @testing .numpy_cupy_array_equal ()
140126 def test_large_int_upper_4 (self , xp , dtype ):
141127 if (
142- numpy .issubdtype (dtype , numpy .unsignedinteger )
143- and numpy_version () < "2.0.0"
144- ):
145- pytest .skip ("numpy promotes dtype differently" )
146- elif (
147128 dtype in (numpy .uint64 , numpy .ulonglong )
148129 and not has_support_aspect64 ()
149130 ):
150131 pytest .skip ("no fp64 support" )
151132
152133 a = xp .array ([xp .iinfo (dtype ).max - 1 ], dtype = dtype )
153- b = numpy .int8 (1 )
134+ b = xp .int8 (1 )
154135 return a + b
155136
156137 @testing .for_int_dtypes (no_bool = True )
157138 @testing .numpy_cupy_array_equal (accept_error = OverflowError )
158139 def test_large_int_lower_1 (self , xp , dtype ):
159- if numpy_version () < "2.0.0" :
160- if dtype in [xp .int16 , xp .int32 , xp .int64 , xp .longlong ]:
161- pytest .skip ("numpy doesn't raise OverflowError" )
162-
163- if dtype in [xp .int8 , xp .intc ] and is_win_platform ():
164- pytest .skip ("numpy promotes dtype differently" )
165-
166140 a = xp .array ([0 ], dtype = xp .int8 )
167141 b = xp .iinfo (dtype ).min
168142 return a + b
169143
170144 @testing .for_int_dtypes (no_bool = True )
171145 @testing .numpy_cupy_array_equal (accept_error = OverflowError )
172146 def test_large_int_lower_2 (self , xp , dtype ):
173- if numpy_version () < "2.0.0" :
174- if dtype in [xp .int16 , xp .int32 , xp .int64 , xp .longlong ]:
175- pytest .skip ("numpy doesn't raise OverflowError" )
176-
177- if dtype in [xp .int8 , xp .intc ] and is_win_platform ():
178- pytest .skip ("numpy promotes dtype differently" )
179-
180147 a = xp .array ([- 1 ], dtype = xp .int8 )
181148 b = xp .iinfo (dtype ).min + 1
182149 return a + b
@@ -185,18 +152,13 @@ def test_large_int_lower_2(self, xp, dtype):
185152 @testing .numpy_cupy_array_equal ()
186153 def test_large_int_lower_3 (self , xp , dtype ):
187154 if (
188- numpy .issubdtype (dtype , numpy .unsignedinteger )
189- and numpy_version () < "2.0.0"
190- ):
191- pytest .skip ("numpy promotes dtype differently" )
192- elif (
193155 dtype in (numpy .uint64 , numpy .ulonglong )
194156 and not has_support_aspect64 ()
195157 ):
196158 pytest .skip ("no fp64 support" )
197159
198160 a = xp .array ([xp .iinfo (dtype ).min ], dtype = dtype )
199- b = numpy .int8 (0 )
161+ b = xp .int8 (0 )
200162 return a + b
201163
202164 @testing .for_int_dtypes (no_bool = True )
@@ -209,5 +171,5 @@ def test_large_int_lower_4(self, xp, dtype):
209171 pytest .skip ("no fp64 support" )
210172
211173 a = xp .array ([xp .iinfo (dtype ).min + 1 ], dtype = dtype )
212- b = numpy .int8 (- 1 )
174+ b = xp .int8 (- 1 )
213175 return a + b
0 commit comments