1
1
import numpy
2
2
import pytest
3
+ from numpy .testing import (
4
+ assert_array_equal ,
5
+ )
3
6
4
7
import dpnp
5
- from tests .helper import get_float_dtypes , has_support_aspect64
8
+ from tests .helper import (
9
+ assert_dtype_allclose ,
10
+ get_float_dtypes ,
11
+ has_support_aspect64 ,
12
+ )
6
13
7
14
8
- # Note: numpy .sum() always upcast integers to (u)int64 and float32 to
9
- # float64 for dtype=None. `np .sum` does that too for integers, but not for
15
+ # Note: dpnp .sum() always upcast integers to (u)int64 and float32 to
16
+ # float64 for dtype=None. `numpy .sum() ` does that too for integers, but not for
10
17
# float32, so we need to special-case it for these tests
11
18
@pytest .mark .parametrize ("dtype" , get_float_dtypes ())
12
19
def test_sum_float (dtype ):
@@ -22,11 +29,8 @@ def test_sum_float(dtype):
22
29
23
30
for axis in range (len (a )):
24
31
result = dpnp .sum (ia , axis = axis )
25
- if dtype == dpnp .float32 and has_support_aspect64 ():
26
- expected = numpy .sum (a , axis = axis , dtype = numpy .float64 )
27
- else :
28
- expected = numpy .sum (a , axis = axis )
29
- numpy .testing .assert_array_equal (expected , result )
32
+ expected = numpy .sum (a , axis = axis )
33
+ assert_dtype_allclose (result , expected )
30
34
31
35
32
36
def test_sum_int ():
@@ -35,7 +39,7 @@ def test_sum_int():
35
39
36
40
result = dpnp .sum (ia )
37
41
expected = numpy .sum (a )
38
- numpy . testing . assert_array_equal (expected , result )
42
+ assert_array_equal (expected , result )
39
43
40
44
41
45
def test_sum_axis ():
@@ -54,4 +58,4 @@ def test_sum_axis():
54
58
expected = numpy .sum (a , axis = 1 , dtype = numpy .float64 )
55
59
else :
56
60
expected = numpy .sum (a , axis = 1 )
57
- numpy . testing . assert_array_equal (expected , result )
61
+ assert_array_equal (expected , result )
0 commit comments