1
- import dpnp
2
- import numpy
3
1
import pytest
2
+ from .helper import get_all_dtypes
3
+
4
+ import dpnp
4
5
import dpctl .tensor as dpt
5
6
7
+ import numpy
8
+ from numpy .testing import (
9
+ assert_array_equal
10
+ )
11
+
6
12
7
- @pytest .mark .parametrize ("res_dtype" ,
8
- [numpy .float64 , numpy .float32 , numpy .int64 , numpy .int32 , numpy .bool_ , numpy .complex_ ],
9
- ids = ['float64' , 'float32' , 'int64' , 'int32' , 'bool' , 'complex' ])
10
- @pytest .mark .parametrize ("arr_dtype" ,
11
- [numpy .float64 , numpy .float32 , numpy .int64 , numpy .int32 , numpy .bool_ , numpy .complex_ ],
12
- ids = ['float64' , 'float32' , 'int64' , 'int32' , 'bool' , 'complex' ])
13
+ @pytest .mark .parametrize ("res_dtype" , get_all_dtypes ())
14
+ @pytest .mark .parametrize ("arr_dtype" , get_all_dtypes ())
13
15
@pytest .mark .parametrize ("arr" ,
14
16
[[- 2 , - 1 , 0 , 1 , 2 ], [[- 2 , - 1 ], [1 , 2 ]], []],
15
17
ids = ['[-2, -1, 0, 1, 2]' , '[[-2, -1], [1, 2]]' , '[]' ])
@@ -18,12 +20,10 @@ def test_astype(arr, arr_dtype, res_dtype):
18
20
dpnp_array = dpnp .array (numpy_array )
19
21
expected = numpy_array .astype (res_dtype )
20
22
result = dpnp_array .astype (res_dtype )
21
- numpy . testing . assert_array_equal (expected , result )
23
+ assert_array_equal (expected , result )
22
24
23
25
24
- @pytest .mark .parametrize ("arr_dtype" ,
25
- [numpy .float64 , numpy .float32 , numpy .int64 , numpy .int32 , numpy .bool_ , numpy .complex_ ],
26
- ids = ['float64' , 'float32' , 'int64' , 'int32' , 'bool' , 'complex' ])
26
+ @pytest .mark .parametrize ("arr_dtype" , get_all_dtypes ())
27
27
@pytest .mark .parametrize ("arr" ,
28
28
[[- 2 , - 1 , 0 , 1 , 2 ], [[- 2 , - 1 ], [1 , 2 ]], []],
29
29
ids = ['[-2, -1, 0, 1, 2]' , '[[-2, -1], [1, 2]]' , '[]' ])
@@ -32,7 +32,7 @@ def test_flatten(arr, arr_dtype):
32
32
dpnp_array = dpnp .array (arr , dtype = arr_dtype )
33
33
expected = numpy_array .flatten ()
34
34
result = dpnp_array .flatten ()
35
- numpy . testing . assert_array_equal (expected , result )
35
+ assert_array_equal (expected , result )
36
36
37
37
38
38
@pytest .mark .parametrize ("shape" ,
@@ -68,3 +68,29 @@ def test_flags_strides(dtype, order, strides):
68
68
assert usm_array .flags == dpnp_array .flags
69
69
assert numpy_array .flags .c_contiguous == dpnp_array .flags .c_contiguous
70
70
assert numpy_array .flags .f_contiguous == dpnp_array .flags .f_contiguous
71
+
72
+
73
+ @pytest .mark .parametrize ("func" , [bool , float , int , complex ])
74
+ @pytest .mark .parametrize ("shape" , [tuple (), (1 ,), (1 , 1 ), (1 , 1 , 1 )])
75
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_float16 = False , no_complex = True ))
76
+ def test_scalar_type_casting (func , shape , dtype ):
77
+ numpy_array = numpy .full (shape , 5 , dtype = dtype )
78
+ dpnp_array = dpnp .full (shape , 5 , dtype = dtype )
79
+ assert func (numpy_array ) == func (dpnp_array )
80
+
81
+
82
+ @pytest .mark .parametrize ("method" , ["__bool__" , "__float__" , "__int__" , "__complex__" ])
83
+ @pytest .mark .parametrize ("shape" , [tuple (), (1 ,), (1 , 1 ), (1 , 1 , 1 )])
84
+ @pytest .mark .parametrize ("dtype" , get_all_dtypes (no_float16 = False , no_complex = True , no_none = True ))
85
+ def test_scalar_type_casting_by_method (method , shape , dtype ):
86
+ numpy_array = numpy .full (shape , 4.7 , dtype = dtype )
87
+ dpnp_array = dpnp .full (shape , 4.7 , dtype = dtype )
88
+ assert getattr (numpy_array , method )() == getattr (dpnp_array , method )()
89
+
90
+
91
+ @pytest .mark .parametrize ("shape" , [(1 ,), (1 , 1 ), (1 , 1 , 1 )])
92
+ @pytest .mark .parametrize ("index_dtype" , [dpnp .int32 , dpnp .int64 ])
93
+ def test_array_as_index (shape , index_dtype ):
94
+ ind_arr = dpnp .ones (shape , dtype = index_dtype )
95
+ a = numpy .arange (ind_arr .size + 1 )
96
+ assert a [tuple (ind_arr )] == a [1 ]
0 commit comments