23
23
class TestAsType :
24
24
@pytest .mark .usefixtures ("suppress_complex_warning" )
25
25
@pytest .mark .parametrize ("res_dtype" , get_all_dtypes ())
26
- @pytest .mark .parametrize ("arr_dtype" , get_all_dtypes ())
26
+ @pytest .mark .parametrize ("arr_dtype" , get_all_dtypes (no_none = True ))
27
27
@pytest .mark .parametrize (
28
28
"arr" ,
29
29
[[- 2 , - 1 , 0 , 1 , 2 ], [[- 2 , - 1 ], [1 , 2 ]], []],
@@ -35,7 +35,7 @@ def test_basic(self, arr, arr_dtype, res_dtype):
35
35
36
36
expected = a .astype (res_dtype )
37
37
result = ia .astype (res_dtype )
38
- assert_allclose (expected , result )
38
+ assert_allclose (result , expected )
39
39
40
40
def test_subok_error (self ):
41
41
x = dpnp .ones (4 )
@@ -88,18 +88,18 @@ def test_create_from_usm_ndarray_error(arr):
88
88
dpnp .ndarray ._create_from_usm_ndarray (arr )
89
89
90
90
91
- @pytest .mark .parametrize ("arr_dtype" , get_all_dtypes ())
91
+ @pytest .mark .parametrize ("arr_dtype" , get_all_dtypes (no_none = True ))
92
92
@pytest .mark .parametrize (
93
93
"arr" ,
94
94
[[- 2 , - 1 , 0 , 1 , 2 ], [[- 2 , - 1 ], [1 , 2 ]], []],
95
95
ids = ["[-2, -1, 0, 1, 2]" , "[[-2, -1], [1, 2]]" , "[]" ],
96
96
)
97
97
def test_flatten (arr , arr_dtype ):
98
- numpy_array = get_abs_array (arr , arr_dtype )
99
- dpnp_array = dpnp .array (numpy_array )
100
- expected = numpy_array .flatten ()
101
- result = dpnp_array .flatten ()
102
- assert_array_equal (expected , result )
98
+ a = get_abs_array (arr , arr_dtype )
99
+ ia = dpnp .array (a )
100
+ expected = a .flatten ()
101
+ result = ia .flatten ()
102
+ assert_array_equal (result , expected )
103
103
104
104
105
105
@pytest .mark .parametrize (
@@ -110,17 +110,16 @@ def test_flatten(arr, arr_dtype):
110
110
@pytest .mark .parametrize ("order" , ["C" , "F" ])
111
111
def test_flags (shape , order ):
112
112
usm_array = dpt .usm_ndarray (shape , order = order )
113
- numpy_array = numpy .ndarray (shape , order = order )
114
- dpnp_array = dpnp .ndarray (shape , order = order )
115
- assert usm_array .flags == dpnp_array .flags
116
- assert numpy_array .flags .c_contiguous == dpnp_array .flags .c_contiguous
117
- assert numpy_array .flags .f_contiguous == dpnp_array .flags .f_contiguous
113
+ a = numpy .ndarray (shape , order = order )
114
+ ia = dpnp .ndarray (shape , order = order )
115
+ assert usm_array .flags == ia .flags
116
+ assert a .flags .c_contiguous == ia .flags .c_contiguous
117
+ assert a .flags .f_contiguous == ia .flags .f_contiguous
118
118
119
119
120
120
@pytest .mark .parametrize (
121
121
"dtype" ,
122
122
[numpy .complex64 , numpy .float32 , numpy .int64 , numpy .int32 , numpy .bool_ ],
123
- ids = ["complex64" , "float32" , "int64" , "int32" , "bool" ],
124
123
)
125
124
@pytest .mark .parametrize ("strides" , [(1 , 4 ), (4 , 1 )], ids = ["(1, 4)" , "(4, 1)" ])
126
125
@pytest .mark .parametrize ("order" , ["C" , "F" ])
@@ -130,13 +129,11 @@ def test_flags_strides(dtype, order, strides):
130
129
usm_array = dpt .usm_ndarray (
131
130
(4 , 4 ), dtype = dtype , order = order , strides = strides
132
131
)
133
- numpy_array = numpy .ndarray (
134
- (4 , 4 ), dtype = dtype , order = order , strides = numpy_strides
135
- )
136
- dpnp_array = dpnp .ndarray ((4 , 4 ), dtype = dtype , order = order , strides = strides )
137
- assert usm_array .flags == dpnp_array .flags
138
- assert numpy_array .flags .c_contiguous == dpnp_array .flags .c_contiguous
139
- assert numpy_array .flags .f_contiguous == dpnp_array .flags .f_contiguous
132
+ a = numpy .ndarray ((4 , 4 ), dtype = dtype , order = order , strides = numpy_strides )
133
+ ia = dpnp .ndarray ((4 , 4 ), dtype = dtype , order = order , strides = strides )
134
+ assert usm_array .flags == ia .flags
135
+ assert a .flags .c_contiguous == ia .flags .c_contiguous
136
+ assert a .flags .f_contiguous == ia .flags .f_contiguous
140
137
141
138
142
139
def test_flags_writable ():
@@ -383,9 +380,9 @@ def test_print_dpnp_zero_shape():
383
380
"dtype" , get_all_dtypes (no_float16 = False , no_complex = True )
384
381
)
385
382
def test_scalar_type_casting (func , shape , dtype ):
386
- numpy_array = numpy .full (shape , 5 , dtype = dtype )
387
- dpnp_array = dpnp .full (shape , 5 , dtype = dtype )
388
- assert func (numpy_array ) == func (dpnp_array )
383
+ a = numpy .full (shape , 5 , dtype = dtype )
384
+ ia = dpnp .full (shape , 5 , dtype = dtype )
385
+ assert func (a ) == func (ia )
389
386
390
387
391
388
# Numpy will raise an error when converting a.ndim > 0 to a scalar
@@ -396,12 +393,12 @@ def test_scalar_type_casting(func, shape, dtype):
396
393
)
397
394
@pytest .mark .parametrize ("shape" , [tuple (), (1 ,), (1 , 1 ), (1 , 1 , 1 )])
398
395
@pytest .mark .parametrize (
399
- "dtype" , get_all_dtypes (no_float16 = False , no_complex = True , no_none = True )
396
+ "dtype" , get_all_dtypes (no_float16 = False , no_complex = True )
400
397
)
401
398
def test_scalar_type_casting_by_method (method , shape , dtype ):
402
- numpy_array = numpy .full (shape , 4.7 , dtype = dtype )
403
- dpnp_array = dpnp .full (shape , 4.7 , dtype = dtype )
404
- assert getattr (numpy_array , method )() == getattr (dpnp_array , method )()
399
+ a = numpy .full (shape , 4.7 , dtype = dtype )
400
+ ia = dpnp .full (shape , 4.7 , dtype = dtype )
401
+ assert_allclose ( getattr (a , method )(), getattr (ia , method )(), rtol = 1e-06 )
405
402
406
403
407
404
@pytest .mark .parametrize ("shape" , [(1 ,), (1 , 1 ), (1 , 1 , 1 )])
@@ -452,18 +449,18 @@ def test_ravel():
452
449
453
450
454
451
def test_repeat ():
455
- numpy_array = numpy .arange (4 ).repeat (3 )
456
- dpnp_array = dpnp .arange (4 ).repeat (3 )
457
- assert_array_equal (numpy_array , dpnp_array )
452
+ a = numpy .arange (4 ).repeat (3 )
453
+ ia = dpnp .arange (4 ).repeat (3 )
454
+ assert_array_equal (a , ia )
458
455
459
456
460
457
def test_clip ():
461
- numpy_array = numpy .arange (10 )
462
- dpnp_array = dpnp .arange (10 )
463
- result = dpnp .clip (dpnp_array , 3 , 7 )
464
- expected = numpy .clip (numpy_array , 3 , 7 )
458
+ a = numpy .arange (10 )
459
+ ia = dpnp .arange (10 )
460
+ result = dpnp .clip (ia , 3 , 7 )
461
+ expected = numpy .clip (a , 3 , 7 )
465
462
466
- assert_array_equal (expected , result )
463
+ assert_array_equal (result , expected )
467
464
468
465
469
466
def test_rmatmul_dpnp_array ():
0 commit comments