23
23
generate_random_numpy_array ,
24
24
get_abs_array ,
25
25
get_all_dtypes ,
26
+ get_array ,
26
27
get_complex_dtypes ,
27
28
get_float_complex_dtypes ,
28
29
get_float_dtypes ,
@@ -648,12 +649,8 @@ def test_basic(self, array, dtype):
648
649
)
649
650
def test_to_begin (self , to_begin ):
650
651
a = numpy .array ([1 , 2 , 4 , 7 , 0 ])
651
- ia = dpnp .array ([1 , 2 , 4 , 7 , 0 ])
652
-
653
- if isinstance (to_begin , dpnp .ndarray ):
654
- np_to_begin = dpnp .asnumpy (to_begin )
655
- else :
656
- np_to_begin = to_begin
652
+ ia = dpnp .array (a )
653
+ np_to_begin = get_array (numpy , to_begin )
657
654
658
655
result = dpnp .ediff1d (ia , to_begin = to_begin )
659
656
expected = numpy .ediff1d (a , to_begin = np_to_begin )
@@ -672,12 +669,8 @@ def test_to_begin(self, to_begin):
672
669
)
673
670
def test_to_end (self , to_end ):
674
671
a = numpy .array ([1 , 2 , 4 , 7 , 0 ])
675
- ia = dpnp .array ([1 , 2 , 4 , 7 , 0 ])
676
-
677
- if isinstance (to_end , dpnp .ndarray ):
678
- np_to_end = dpnp .asnumpy (to_end )
679
- else :
680
- np_to_end = to_end
672
+ ia = dpnp .array (a )
673
+ np_to_end = get_array (numpy , to_end )
681
674
682
675
result = dpnp .ediff1d (ia , to_end = to_end )
683
676
expected = numpy .ediff1d (a , to_end = np_to_end )
@@ -696,17 +689,10 @@ def test_to_end(self, to_end):
696
689
)
697
690
def test_to_begin_to_end (self , to_begin , to_end ):
698
691
a = numpy .array ([1 , 2 , 4 , 7 , 0 ])
699
- ia = dpnp .array ([1 , 2 , 4 , 7 , 0 ])
700
-
701
- if isinstance (to_begin , dpnp .ndarray ):
702
- np_to_begin = dpnp .asnumpy (to_begin )
703
- else :
704
- np_to_begin = to_begin
692
+ ia = dpnp .array (a )
705
693
706
- if isinstance (to_end , dpnp .ndarray ):
707
- np_to_end = dpnp .asnumpy (to_end )
708
- else :
709
- np_to_end = to_end
694
+ np_to_begin = get_array (numpy , to_begin )
695
+ np_to_end = get_array (numpy , to_end )
710
696
711
697
result = dpnp .ediff1d (ia , to_end = to_end , to_begin = to_begin )
712
698
expected = numpy .ediff1d (a , to_end = np_to_end , to_begin = np_to_begin )
@@ -1790,7 +1776,7 @@ def get_numpy_func(self):
1790
1776
return numpy .trapz
1791
1777
return numpy .trapezoid
1792
1778
1793
- @pytest .mark .parametrize ("dt" , get_all_dtypes (no_bool = True ))
1779
+ @pytest .mark .parametrize ("dt" , get_all_dtypes (no_none = True , no_bool = True ))
1794
1780
@pytest .mark .parametrize (
1795
1781
"data" ,
1796
1782
[[1 , 2 , 3 ], [[1 , 2 , 3 ], [4 , 5 , 6 ]], [1 , 4 , 6 , 9 , 10 , 12 ], [], [1 ]],
@@ -1816,8 +1802,8 @@ def test_simple(self, dt):
1816
1802
)
1817
1803
assert_allclose (result , expected , rtol = 1e-6 )
1818
1804
1819
- @pytest .mark .parametrize ("y_dt" , get_all_dtypes (no_bool = True ))
1820
- @pytest .mark .parametrize ("x_dt" , get_all_dtypes (no_bool = True ))
1805
+ @pytest .mark .parametrize ("y_dt" , get_all_dtypes (no_none = True , no_bool = True ))
1806
+ @pytest .mark .parametrize ("x_dt" , get_all_dtypes (no_none = True , no_bool = True ))
1821
1807
@pytest .mark .parametrize ("y_arr" , [[1 , 2 , 4 , 5 ], [1.0 , 2.5 , 6.0 , 7.0 ]])
1822
1808
@pytest .mark .parametrize ("x_arr" , [[2 , 5 , 6 , 9 ]])
1823
1809
def test_x_samples (self , y_arr , x_arr , y_dt , x_dt ):
@@ -1979,7 +1965,7 @@ def test_discont(self, dt):
1979
1965
1980
1966
@pytest .mark .usefixtures ("suppress_divide_invalid_numpy_warnings" )
1981
1967
@pytest .mark .parametrize ("val_type" , [bool , int , float ])
1982
- @pytest .mark .parametrize ("data_type " , get_all_dtypes ())
1968
+ @pytest .mark .parametrize ("dtype " , get_all_dtypes (no_none = True ))
1983
1969
@pytest .mark .parametrize (
1984
1970
"func" , ["add" , "divide" , "multiply" , "power" , "subtract" ]
1985
1971
)
@@ -1996,30 +1982,24 @@ def test_discont(self, dt):
1996
1982
[[[1 , 3 ], [3 , 1 ]], [[0 , 1 ], [1 , 3 ]]],
1997
1983
],
1998
1984
],
1999
- ids = [
2000
- "[[0, 0], [0, 0]]" ,
2001
- "[[1, 2], [1, 2]]" ,
2002
- "[[1, 2], [3, 4]]" ,
2003
- "[[[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]]]" ,
2004
- "[[[[1, 2], [3, 4]], [[1, 2], [2, 1]]], [[[1, 3], [3, 1]], [[0, 1], [1, 3]]]]" ,
2005
- ],
1985
+ ids = ["2D-zeros" , "2D-repetitive" , "2D" , "3D" , "4D" ],
2006
1986
)
2007
- def test_op_with_scalar (array , val , func , data_type , val_type ):
2008
- a = numpy .array (array , dtype = data_type )
2009
- ia = dpnp .array (array , dtype = data_type )
1987
+ def test_op_with_scalar (array , val , func , dtype , val_type ):
1988
+ a = numpy .array (array , dtype = dtype )
1989
+ ia = dpnp .array (a )
2010
1990
val_ = val_type (val )
2011
1991
2012
1992
if func == "power" :
2013
1993
if (
2014
1994
val_ == 0
2015
- and numpy .issubdtype (data_type , numpy .complexfloating )
1995
+ and numpy .issubdtype (dtype , numpy .complexfloating )
2016
1996
and not dpnp .all (ia )
2017
1997
):
2018
1998
pytest .skip (
2019
1999
"(0j ** 0) is different: (NaN + NaNj) in dpnp and (1 + 0j) in numpy"
2020
2000
)
2021
2001
2022
- if func == "subtract" and val_type == bool and data_type == dpnp .bool :
2002
+ if func == "subtract" and val_type == bool and dtype == dpnp .bool :
2023
2003
with pytest .raises (TypeError ):
2024
2004
result = getattr (dpnp , func )(ia , val_ )
2025
2005
expected = getattr (numpy , func )(a , val_ )
@@ -2037,43 +2017,43 @@ def test_op_with_scalar(array, val, func, data_type, val_type):
2037
2017
2038
2018
2039
2019
@pytest .mark .parametrize ("shape" , [(), (3 , 2 )], ids = ["0D" , "2D" ])
2040
- @pytest .mark .parametrize ("dtype" , get_all_dtypes ())
2020
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
2041
2021
def test_multiply_scalar (shape , dtype ):
2042
2022
a = numpy .ones (shape , dtype = dtype )
2043
- ia = dpnp .ones ( shape , dtype = dtype )
2023
+ ia = dpnp .array ( a )
2044
2024
2045
2025
result = 0.5 * ia * 1.7
2046
2026
expected = 0.5 * a * 1.7
2047
2027
assert_allclose (result , expected )
2048
2028
2049
2029
2050
2030
@pytest .mark .parametrize ("shape" , [(), (3 , 2 )], ids = ["0D" , "2D" ])
2051
- @pytest .mark .parametrize ("dtype" , get_all_dtypes ())
2031
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
2052
2032
def test_add_scalar (shape , dtype ):
2053
2033
a = numpy .ones (shape , dtype = dtype )
2054
- ia = dpnp .ones ( shape , dtype = dtype )
2034
+ ia = dpnp .array ( a )
2055
2035
2056
2036
result = 0.5 + ia + 1.7
2057
2037
expected = 0.5 + a + 1.7
2058
2038
assert_allclose (result , expected )
2059
2039
2060
2040
2061
2041
@pytest .mark .parametrize ("shape" , [(), (3 , 2 )], ids = ["0D" , "2D" ])
2062
- @pytest .mark .parametrize ("dtype" , get_all_dtypes ())
2042
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
2063
2043
def test_subtract_scalar (shape , dtype ):
2064
2044
a = numpy .ones (shape , dtype = dtype )
2065
- ia = dpnp .ones ( shape , dtype = dtype )
2045
+ ia = dpnp .array ( a )
2066
2046
2067
2047
result = 0.5 - ia - 1.7
2068
2048
expected = 0.5 - a - 1.7
2069
2049
assert_allclose (result , expected )
2070
2050
2071
2051
2072
2052
@pytest .mark .parametrize ("shape" , [(), (3 , 2 )], ids = ["0D" , "2D" ])
2073
- @pytest .mark .parametrize ("dtype" , get_all_dtypes ())
2053
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
2074
2054
def test_divide_scalar (shape , dtype ):
2075
2055
a = numpy .ones (shape , dtype = dtype )
2076
- ia = dpnp .ones ( shape , dtype = dtype )
2056
+ ia = dpnp .array ( a )
2077
2057
2078
2058
result = 0.5 / ia / 1.7
2079
2059
expected = 0.5 / a / 1.7
@@ -2084,7 +2064,7 @@ def test_divide_scalar(shape, dtype):
2084
2064
"data" , [[[1.0 , - 1.0 ], [0.1 , - 0.1 ]], [- 2 , - 1 , 0 , 1 , 2 ]], ids = ["2D" , "1D" ]
2085
2065
)
2086
2066
@pytest .mark .parametrize (
2087
- "dtype" , get_all_dtypes (no_bool = True , no_unsigned = True )
2067
+ "dtype" , get_all_dtypes (no_none = True , no_bool = True , no_unsigned = True )
2088
2068
)
2089
2069
def test_negative (data , dtype ):
2090
2070
a = numpy .array (data , dtype = dtype )
@@ -2116,7 +2096,7 @@ def test_negative_boolean():
2116
2096
@pytest .mark .parametrize (
2117
2097
"data" , [[[1.0 , - 1.0 ], [0.1 , - 0.1 ]], [- 2 , - 1 , 0 , 1 , 2 ]], ids = ["2D" , "1D" ]
2118
2098
)
2119
- @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_bool = True ))
2099
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True , no_bool = True ))
2120
2100
def test_positive (data , dtype ):
2121
2101
a = get_abs_array (data , dtype = dtype )
2122
2102
ia = dpnp .array (a )
@@ -2215,11 +2195,11 @@ def test_sign(dtype):
2215
2195
ids = ["[2, 0, -2]" , "[1.1, -1.1]" ],
2216
2196
)
2217
2197
@pytest .mark .parametrize (
2218
- "dtype" , get_all_dtypes (no_complex = True , no_unsigned = True )
2198
+ "dtype" , get_all_dtypes (no_none = True , no_complex = True , no_unsigned = True )
2219
2199
)
2220
2200
def test_signbit (data , dtype ):
2221
2201
a = numpy .array (data , dtype = dtype )
2222
- ia = dpnp .array (data , dtype = dtype )
2202
+ ia = dpnp .array (a )
2223
2203
2224
2204
result = dpnp .signbit (ia )
2225
2205
expected = numpy .signbit (a )
@@ -2233,7 +2213,7 @@ def test_signbit(data, dtype):
2233
2213
2234
2214
2235
2215
class TestRealImag :
2236
- @pytest .mark .parametrize ("dtype" , get_all_dtypes ())
2216
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
2237
2217
def test_real_imag (self , dtype ):
2238
2218
a = generate_random_numpy_array (20 , dtype )
2239
2219
ia = dpnp .array (a )
@@ -2284,7 +2264,7 @@ def test_projection_infinity(self, dtype):
2284
2264
assert iout is result
2285
2265
assert dpnp .allclose (result , expected )
2286
2266
2287
- @pytest .mark .parametrize ("dtype" , get_all_dtypes ())
2267
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_none = True ))
2288
2268
def test_projection (self , dtype ):
2289
2269
result = dpnp .proj (dpnp .array (1 , dtype = dtype ))
2290
2270
expected = dpnp .array (complex (1 , 0 ))
@@ -2303,7 +2283,9 @@ class TestRoundingFuncs:
2303
2283
def func_params (self , request ):
2304
2284
return request .param
2305
2285
2306
- @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_complex = True ))
2286
+ @pytest .mark .parametrize (
2287
+ "dtype" , get_all_dtypes (no_none = True , no_complex = True )
2288
+ )
2307
2289
def test_out (self , func_params , dtype ):
2308
2290
func_name = func_params ["func_name" ]
2309
2291
input_values = func_params ["input_values" ]
@@ -2349,7 +2331,7 @@ def test_invalid_shape(self, func_params, shape):
2349
2331
2350
2332
class TestHypot :
2351
2333
@pytest .mark .parametrize (
2352
- "dtype" , get_all_dtypes (no_bool = True , no_complex = True )
2334
+ "dtype" , get_all_dtypes (no_none = True , no_bool = True , no_complex = True )
2353
2335
)
2354
2336
def test_hypot (self , dtype ):
2355
2337
a , b , expected = _get_numpy_arrays_2in_1out ("hypot" , dtype , [0 , 10 , 10 ])
@@ -2413,28 +2395,6 @@ def test_basic(self, dtype, axis, keepdims):
2413
2395
2414
2396
assert_dtype_allclose (res , exp )
2415
2397
2416
- @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_complex = True ))
2417
- @pytest .mark .parametrize ("axis" , [None , 2 , - 1 , (0 , 1 )])
2418
- @pytest .mark .parametrize ("keepdims" , [True , False ])
2419
- def test_logsumexp_out (self , dtype , axis , keepdims ):
2420
- a = dpnp .ones ((3 , 4 , 5 , 6 , 7 ), dtype = dtype )
2421
- exp_dt = None
2422
- dtype_list = [dpnp .bool , dpnp .int8 , dpnp .uint8 , dpnp .int16 , dpnp .uint16 ]
2423
- if dtype in dtype_list :
2424
- exp_dt = dpnp .default_float_type (a .device )
2425
- exp = numpy .logaddexp .reduce (
2426
- dpnp .asnumpy (a ), axis = axis , keepdims = keepdims , dtype = exp_dt
2427
- )
2428
-
2429
- exp_dt = exp .dtype
2430
- if exp_dt == numpy .float64 and not has_support_aspect64 ():
2431
- exp_dt = numpy .float32
2432
- iout = dpnp .empty_like (a , shape = exp .shape , dtype = exp_dt )
2433
- res = dpnp .logsumexp (a , axis = axis , out = iout , keepdims = keepdims )
2434
-
2435
- assert res is iout
2436
- assert_dtype_allclose (res , exp )
2437
-
2438
2398
@pytest .mark .parametrize (
2439
2399
"in_dt" , get_all_dtypes (no_none = True , no_bool = True , no_complex = True )
2440
2400
)
0 commit comments