1313
1414from .helper import (
1515 assert_dtype_allclose ,
16+ generate_random_numpy_array ,
1617 get_abs_array ,
1718 get_all_dtypes ,
1819 get_complex_dtypes ,
2223 has_support_aspect16 ,
2324 numpy_version ,
2425)
25- from .test_umath import (
26- _get_numpy_arrays_2in_1out ,
27- _get_output_data_type ,
28- )
26+ from .test_umath import _get_output_data_type
2927
3028"""
3129The scope includes tests with only functions which are instances of
@@ -39,7 +37,9 @@ class TestAdd:
3937
4038 @pytest .mark .parametrize ("dtype" , ALL_DTYPES )
4139 def test_add (self , dtype ):
42- a , b , expected = _get_numpy_arrays_2in_1out ("add" , dtype , [- 5 , 5 , 10 ])
40+ a = generate_random_numpy_array (10 , dtype )
41+ b = generate_random_numpy_array (10 , dtype )
42+ expected = numpy .add (a , b )
4343
4444 ia , ib = dpnp .array (a ), dpnp .array (b )
4545 iout = dpnp .empty (expected .shape , dtype = dtype )
@@ -139,74 +139,53 @@ def test_invalid_out(self, xp, out):
139139 assert_raises (TypeError , xp .add , a , 2 , out )
140140
141141
142+ @pytest .mark .parametrize ("func" , ["fmax" , "fmin" , "maximum" , "minimum" ])
142143class TestBoundFuncs :
143- @pytest .fixture (
144- params = [
145- {"func_name" : "fmax" , "input_values" : [- 5 , 5 , 10 ]},
146- {"func_name" : "fmin" , "input_values" : [- 5 , 5 , 10 ]},
147- {"func_name" : "maximum" , "input_values" : [- 5 , 5 , 10 ]},
148- {"func_name" : "minimum" , "input_values" : [- 5 , 5 , 10 ]},
149- ],
150- ids = [
151- "fmax" ,
152- "fmin" ,
153- "maximum" ,
154- "minimum" ,
155- ],
156- )
157- def func_params (self , request ):
158- return request .param
159-
160144 @pytest .mark .parametrize (
161145 "dtype" , get_all_dtypes (no_bool = True , no_complex = True )
162146 )
163- def test_out (self , func_params , dtype ):
164- func_name = func_params ["func_name" ]
165- input_values = func_params ["input_values" ]
166- a , b , expected = _get_numpy_arrays_2in_1out (
167- func_name , dtype , input_values
168- )
147+ def test_out (self , func , dtype ):
148+ a = generate_random_numpy_array (10 , dtype )
149+ b = generate_random_numpy_array (10 , dtype )
150+ expected = getattr (numpy , func )(a , b )
169151
170152 ia , ib = dpnp .array (a ), dpnp .array (b )
171153 iout = dpnp .empty (expected .shape , dtype = dtype )
172- result = getattr (dpnp , func_name )(ia , ib , out = iout )
154+ result = getattr (dpnp , func )(ia , ib , out = iout )
173155
174156 assert result is iout
175157 assert_dtype_allclose (result , expected )
176158
177159 @pytest .mark .parametrize (
178160 "dtype" , get_all_dtypes (no_bool = True , no_complex = True )
179161 )
180- def test_out_overlap (self , func_params , dtype ):
181- func_name = func_params ["func_name" ]
162+ def test_out_overlap (self , func , dtype ):
182163 size = 15
183164 a = numpy .arange (2 * size , dtype = dtype )
184165 ia = dpnp .array (a )
185166
186- getattr (dpnp , func_name )(ia [size ::], ia [::2 ], out = ia [:size :])
187- getattr (numpy , func_name )(a [size ::], a [::2 ], out = a [:size :])
167+ getattr (dpnp , func )(ia [size ::], ia [::2 ], out = ia [:size :])
168+ getattr (numpy , func )(a [size ::], a [::2 ], out = a [:size :])
188169
189170 assert_dtype_allclose (ia , a )
190171
191172 @pytest .mark .parametrize ("shape" , [(0 ,), (15 ,), (2 , 2 )])
192- def test_invalid_shape (self , func_params , shape ):
193- func_name = func_params ["func_name" ]
173+ def test_invalid_shape (self , func , shape ):
194174 a , b = dpnp .arange (10 ), dpnp .arange (10 )
195175 out = dpnp .empty (shape )
196176
197177 with pytest .raises (ValueError ):
198- getattr (dpnp , func_name )(a , b , out = out )
178+ getattr (dpnp , func )(a , b , out = out )
199179
200180 @pytest .mark .parametrize ("xp" , [dpnp , numpy ])
201181 @pytest .mark .parametrize (
202182 "out" ,
203183 [4 , (), [], (3 , 7 ), [2 , 4 ]],
204184 ids = ["scalar" , "empty_tuple" , "empty_list" , "tuple" , "list" ],
205185 )
206- def test_invalid_out (self , func_params , xp , out ):
207- func_name = func_params ["func_name" ]
186+ def test_invalid_out (self , func , xp , out ):
208187 a = xp .arange (10 )
209- assert_raises (TypeError , getattr (xp , func_name ), a , 2 , out )
188+ assert_raises (TypeError , getattr (xp , func ), a , 2 , out )
210189
211190
212191class TestDivide :
@@ -215,9 +194,9 @@ class TestDivide:
215194 "dtype" , get_all_dtypes (no_none = True , no_bool = True )
216195 )
217196 def test_divide (self , dtype ):
218- a , b , expected = _get_numpy_arrays_2in_1out (
219- "divide" , dtype , [ - 5 , 5 , 10 ]
220- )
197+ a = generate_random_numpy_array ( 10 , dtype )
198+ b = generate_random_numpy_array ( 10 , dtype )
199+ expected = numpy . divide ( a , b )
221200
222201 ia , ib = dpnp .array (a ), dpnp .array (b )
223202 if numpy .issubdtype (dtype , numpy .integer ):
@@ -318,7 +297,9 @@ def do_inplace_op(self, base, other, func):
318297 @pytest .mark .usefixtures ("suppress_divide_numpy_warnings" )
319298 @pytest .mark .parametrize ("dtype" , ALL_DTYPES )
320299 def test_basic (self , func , dtype ):
321- a , b , expected = _get_numpy_arrays_2in_1out (func , dtype , [- 5 , 5 , 10 ])
300+ a = generate_random_numpy_array (10 , dtype )
301+ b = generate_random_numpy_array (10 , dtype )
302+ expected = getattr (numpy , func )(a , b )
322303
323304 ia , ib = dpnp .array (a ), dpnp .array (b )
324305 iout = dpnp .empty (expected .shape , dtype = dtype )
@@ -602,9 +583,9 @@ class TestMultiply:
602583
603584 @pytest .mark .parametrize ("dtype" , ALL_DTYPES )
604585 def test_multiply (self , dtype ):
605- a , b , expected = _get_numpy_arrays_2in_1out (
606- "multiply" , dtype , [ 0 , 10 , 10 ]
607- )
586+ a = generate_random_numpy_array ( 10 , dtype )
587+ b = generate_random_numpy_array ( 10 , dtype )
588+ expected = numpy . multiply ( a , b )
608589
609590 ia , ib = dpnp .array (a ), dpnp .array (b )
610591 iout = dpnp .empty (expected .shape , dtype = dtype )
@@ -853,8 +834,9 @@ def test_basic(self, array, val, data_type, val_type):
853834
854835 @pytest .mark .parametrize ("dtype" , ALL_DTYPES )
855836 def test_power (self , dtype ):
856- numpy .random .seed (42 )
857- a , b , expected = _get_numpy_arrays_2in_1out ("power" , dtype , [0 , 10 , 10 ])
837+ a = generate_random_numpy_array (10 , dtype , low = 0 )
838+ b = generate_random_numpy_array (10 , dtype , low = 0 )
839+ expected = numpy .power (a , b )
858840
859841 ia , ib = dpnp .array (a ), dpnp .array (b )
860842 out_dtype = numpy .int8 if dtype == numpy .bool_ else dtype
@@ -1075,9 +1057,9 @@ class TestSubtract:
10751057
10761058 @pytest .mark .parametrize ("dtype" , ALL_DTYPES )
10771059 def test_add (self , dtype ):
1078- a , b , expected = _get_numpy_arrays_2in_1out (
1079- "subtract" , dtype , [ - 5 , 5 , 10 ]
1080- )
1060+ a = generate_random_numpy_array ( 10 , dtype )
1061+ b = generate_random_numpy_array ( 10 , dtype )
1062+ expected = numpy . subtract ( a , b )
10811063
10821064 ia , ib = dpnp .array (a ), dpnp .array (b )
10831065 iout = dpnp .empty (expected .shape , dtype = dtype )
0 commit comments