Skip to content

Commit 0ec6f44

Browse files
Remove floatMAX and update some tests
1 parent 50cb314 commit 0ec6f44

File tree

10 files changed

+187
-222
lines changed

10 files changed

+187
-222
lines changed

tests/conftest.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import dpnp
3030
import numpy
3131
import pytest
32-
from .helper import check_support_float64
3332

3433

3534
skip_mark = pytest.mark.skip(reason='Skipping test.')
@@ -78,6 +77,3 @@ def pytest_collection_modifyitems(config, items):
7877
@pytest.fixture
7978
def allow_fall_back_on_numpy(monkeypatch):
8079
monkeypatch.setattr(dpnp.config, '__DPNP_RAISE_EXCEPION_ON_NUMPY_FALLBACK__', 0)
81-
82-
def pytest_configure():
83-
pytest.floatMAX = "float64" if check_support_float64() else "float32"

tests/helper.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,3 @@ def get_all_dtypes(no_bool=False,
3737
if not no_none:
3838
dtypes.append(None)
3939
return dtypes
40-
41-
def check_support_float64():
42-
"""
43-
Returns True if the default device supports 64-bit precision floating
44-
point operations, False otherwise.
45-
"""
46-
47-
return dpctl.select_default_device().has_aspect_fp64

tests/test_absolute.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,46 @@
11
import pytest
2+
from .helper import get_all_dtypes
23

34
import dpnp as inp
45

56
import numpy
67

78

8-
@pytest.mark.parametrize("type", [numpy.int64], ids=["int64"])
9-
def test_abs_int(type):
10-
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
9+
@pytest.mark.parametrize(
10+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
11+
)
12+
def test_abs(dtype):
13+
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9], dtype=dtype)
1114
ia = inp.array(a)
1215

1316
result = inp.abs(ia)
1417
expected = numpy.abs(a)
1518
numpy.testing.assert_array_equal(expected, result)
1619

1720

18-
@pytest.mark.parametrize("type", [numpy.int64], ids=["int64"])
19-
def test_absolute_int(type):
20-
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
21+
@pytest.mark.parametrize(
22+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
23+
)
24+
def test_absolute(dtype):
25+
a = numpy.array([[-2.0, 3.0, 9.1], [-2.0, 5.0, -2], [1.0, -2.0, 5.0]], dtype=dtype)
2126
ia = inp.array(a)
2227

2328
result = inp.absolute(ia)
2429
expected = numpy.absolute(a)
2530
numpy.testing.assert_array_equal(expected, result)
2631

2732

28-
@pytest.mark.parametrize("type", [numpy.float64], ids=[pytest.floatMAX])
29-
def test_absolute_float(type):
30-
a = numpy.array(
31-
[[-2.0, 3.0, 9.1], [-2.0, 5.0, -2], [1.0, -2.0, 5.0]], dtype=pytest.floatMAX
32-
)
33-
ia = inp.array(a)
34-
35-
result = inp.absolute(ia)
36-
expected = numpy.absolute(a)
37-
numpy.testing.assert_array_equal(expected, result)
38-
39-
40-
@pytest.mark.parametrize("type", [numpy.float64], ids=[pytest.floatMAX])
41-
def test_absolute_float_3(type):
33+
@pytest.mark.parametrize(
34+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
35+
)
36+
def test_absolute_3d(dtype):
4237
a = numpy.array(
4338
[
4439
[[-2.0, 3.0], [9.1, 0.2]],
4540
[[-2.0, 5.0], [-2, -1.2]],
4641
[[1.0, -2.0], [5.0, -1.1]],
4742
],
48-
dtype=pytest.floatMAX,
43+
dtype=dtype,
4944
)
5045
ia = inp.array(a)
5146

tests/test_amin_amax.py

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import pytest
2+
from .helper import get_all_dtypes
23

34
import dpnp
45

56
import numpy
67

78

8-
@pytest.mark.parametrize("type", [numpy.float64], ids=[pytest.floatMAX])
9-
def test_amax_float(type):
9+
@pytest.mark.parametrize(
10+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
11+
)
12+
def test_amax(dtype):
1013
a = numpy.array(
1114
[
1215
[[-2.0, 3.0], [9.1, 0.2]],
1316
[[-2.0, 5.0], [-2, -1.2]],
1417
[[1.0, -2.0], [5.0, -1.1]],
1518
],
16-
dtype=pytest.floatMAX,
19+
dtype=dtype,
1720
)
1821
ia = dpnp.array(a)
1922

@@ -23,25 +26,17 @@ def test_amax_float(type):
2326
numpy.testing.assert_array_equal(expected, result)
2427

2528

26-
@pytest.mark.parametrize("type", [numpy.int64], ids=["int64"])
27-
def test_amax_int(type):
28-
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
29-
ia = dpnp.array(a)
30-
31-
result = dpnp.amax(ia)
32-
expected = numpy.amax(a)
33-
numpy.testing.assert_array_equal(expected, result)
34-
35-
36-
@pytest.mark.parametrize("type", [numpy.float64], ids=[pytest.floatMAX])
37-
def test_amin_float(type):
29+
@pytest.mark.parametrize(
30+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
31+
)
32+
def test_amin(dtype):
3833
a = numpy.array(
3934
[
4035
[[-2.0, 3.0], [9.1, 0.2]],
4136
[[-2.0, 5.0], [-2, -1.2]],
4237
[[1.0, -2.0], [5.0, -1.1]],
4338
],
44-
dtype=pytest.floatMAX,
39+
dtype=dtype,
4540
)
4641
ia = dpnp.array(a)
4742

@@ -51,16 +46,6 @@ def test_amin_float(type):
5146
numpy.testing.assert_array_equal(expected, result)
5247

5348

54-
@pytest.mark.parametrize("type", [numpy.int64], ids=["int64"])
55-
def test_amin_int(type):
56-
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
57-
ia = dpnp.array(a)
58-
59-
result = dpnp.amin(ia)
60-
expected = numpy.amin(a)
61-
numpy.testing.assert_array_equal(expected, result)
62-
63-
6449
def _get_min_max_input(type, shape):
6550
size = 1
6651
for i in range(len(shape)):
@@ -75,25 +60,13 @@ def _get_min_max_input(type, shape):
7560

7661
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
7762
@pytest.mark.parametrize(
78-
"type",
79-
[
80-
pytest.param(
81-
numpy.float64,
82-
marks=pytest.mark.skipif(
83-
pytest.floatMAX != "float64", reason="No float64 support on this device"
84-
),
85-
),
86-
numpy.float32,
87-
numpy.int64,
88-
numpy.int32,
89-
],
90-
ids=["float64", "float32", "int64", "int32"],
63+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
9164
)
9265
@pytest.mark.parametrize(
9366
"shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2,3)", "(4,5,6)"]
9467
)
95-
def test_amax(type, shape):
96-
a = _get_min_max_input(type, shape)
68+
def test_amax_with_shape(dtype, shape):
69+
a = _get_min_max_input(dtype, shape)
9770

9871
ia = dpnp.array(a)
9972

@@ -108,25 +81,13 @@ def test_amax(type, shape):
10881

10982
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
11083
@pytest.mark.parametrize(
111-
"type",
112-
[
113-
pytest.param(
114-
numpy.float64,
115-
marks=pytest.mark.skipif(
116-
pytest.floatMAX != "float64", reason="No float64 support on this device"
117-
),
118-
),
119-
numpy.float32,
120-
numpy.int64,
121-
numpy.int32,
122-
],
123-
ids=["float64", "float32", "int64", "int32"],
84+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
12485
)
12586
@pytest.mark.parametrize(
12687
"shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2,3)", "(4,5,6)"]
12788
)
128-
def test_amin(type, shape):
129-
a = _get_min_max_input(type, shape)
89+
def test_amin_with_shape(dtype, shape):
90+
a = _get_min_max_input(dtype, shape)
13091

13192
ia = dpnp.array(a)
13293

tests/test_bitwise.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55
import numpy
66

77

8-
@pytest.mark.parametrize("lhs", [[[-7, -6, -5, -4, -3, -2, -1], [0, 1, 2, 3, 4, 5, 6]], [-3, -2, -1, 0, 1, 2, 3], 0])
9-
@pytest.mark.parametrize("rhs", [[[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13]], [0, 1, 2, 3, 4, 5, 6], 3])
8+
@pytest.mark.parametrize(
9+
"lhs",
10+
[
11+
[[-7, -6, -5, -4, -3, -2, -1], [0, 1, 2, 3, 4, 5, 6]],
12+
[-3, -2, -1, 0, 1, 2, 3],
13+
0,
14+
],
15+
)
16+
@pytest.mark.parametrize(
17+
"rhs",
18+
[[[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13]], [0, 1, 2, 3, 4, 5, 6], 3],
19+
)
1020
@pytest.mark.parametrize("dtype", [numpy.int32, numpy.int64])
1121
class TestBitwise:
12-
1322
@staticmethod
1423
def array_or_scalar(xp, data, dtype=None):
1524
if numpy.isscalar(data):
@@ -39,24 +48,24 @@ def _test_binary_int(self, name, lhs, rhs, dtype):
3948

4049
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
4150
def test_bitwise_and(self, lhs, rhs, dtype):
42-
self._test_binary_int('bitwise_and', lhs, rhs, dtype)
51+
self._test_binary_int("bitwise_and", lhs, rhs, dtype)
4352

4453
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
4554
def test_bitwise_or(self, lhs, rhs, dtype):
46-
self._test_binary_int('bitwise_or', lhs, rhs, dtype)
55+
self._test_binary_int("bitwise_or", lhs, rhs, dtype)
4756

4857
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
4958
def test_bitwise_xor(self, lhs, rhs, dtype):
50-
self._test_binary_int('bitwise_xor', lhs, rhs, dtype)
59+
self._test_binary_int("bitwise_xor", lhs, rhs, dtype)
5160

5261
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
5362
def test_invert(self, lhs, rhs, dtype):
54-
self._test_unary_int('invert', lhs, dtype)
63+
self._test_unary_int("invert", lhs, dtype)
5564

5665
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
5766
def test_left_shift(self, lhs, rhs, dtype):
58-
self._test_binary_int('left_shift', lhs, rhs, dtype)
67+
self._test_binary_int("left_shift", lhs, rhs, dtype)
5968

6069
@pytest.mark.usefixtures("allow_fall_back_on_numpy")
6170
def test_right_shift(self, lhs, rhs, dtype):
62-
self._test_binary_int('right_shift', lhs, rhs, dtype)
71+
self._test_binary_int("right_shift", lhs, rhs, dtype)

tests/test_counting.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import pytest
2+
from .helper import get_all_dtypes
23

34
import dpnp
45

56
import numpy
67

78

8-
@pytest.mark.parametrize("type",
9-
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
10-
ids=['float64', 'float32', 'int64', 'int32'])
11-
@pytest.mark.parametrize("size",
12-
[2, 4, 8, 16, 3, 9, 27, 81])
13-
def test_count_nonzero(type, size):
14-
a = numpy.arange(size, dtype=type)
9+
@pytest.mark.parametrize(
10+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
11+
)
12+
@pytest.mark.parametrize("size", [2, 4, 8, 16, 3, 9, 27, 81])
13+
def test_count_nonzero(dtype, size):
14+
a = numpy.arange(size, dtype=dtype)
1515
for i in range(int(size / 2)):
1616
a[(i * (int(size / 3) - 1)) % size] = 0
1717

tests/test_dot.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import pytest
2+
from .helper import get_all_dtypes
23

34
import dpnp as inp
45

56
import numpy
67

78

8-
@pytest.mark.parametrize("type",
9-
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
10-
ids=['float64', 'float32', 'int64', 'int32'])
11-
def test_dot_ones(type):
9+
@pytest.mark.parametrize(
10+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
11+
)
12+
def test_dot_ones(dtype):
1213
n = 10**5
13-
a = numpy.ones(n, dtype=type)
14-
b = numpy.ones(n, dtype=type)
14+
a = numpy.ones(n, dtype=dtype)
15+
b = numpy.ones(n, dtype=dtype)
1516
ia = inp.array(a)
1617
ib = inp.array(b)
1718

@@ -20,13 +21,13 @@ def test_dot_ones(type):
2021
numpy.testing.assert_array_equal(expected, result)
2122

2223

23-
@pytest.mark.parametrize("type",
24-
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
25-
ids=['float64', 'float32', 'int64', 'int32'])
26-
def test_dot_arange(type):
24+
@pytest.mark.parametrize(
25+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
26+
)
27+
def test_dot_arange(dtype):
2728
n = 10**2
2829
m = 10**3
29-
a = numpy.hstack((numpy.arange(n, dtype=type),) * m)
30+
a = numpy.hstack((numpy.arange(n, dtype=dtype),) * m)
3031
b = numpy.flipud(a)
3132
ia = inp.array(a)
3233
ib = inp.array(b)
@@ -36,20 +37,20 @@ def test_dot_arange(type):
3637
numpy.testing.assert_allclose(expected, result)
3738

3839

39-
@pytest.mark.parametrize("type",
40-
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
41-
ids=['float64', 'float32', 'int64', 'int32'])
42-
def test_multi_dot(type):
40+
@pytest.mark.parametrize(
41+
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
42+
)
43+
def test_multi_dot(dtype):
4344
n = 16
44-
a = inp.reshape(inp.arange(n, dtype=type), (4, 4))
45-
b = inp.reshape(inp.arange(n, dtype=type), (4, 4))
46-
c = inp.reshape(inp.arange(n, dtype=type), (4, 4))
47-
d = inp.reshape(inp.arange(n, dtype=type), (4, 4))
48-
49-
a1 = numpy.arange(n, dtype=type).reshape((4, 4))
50-
b1 = numpy.arange(n, dtype=type).reshape((4, 4))
51-
c1 = numpy.arange(n, dtype=type).reshape((4, 4))
52-
d1 = numpy.arange(n, dtype=type).reshape((4, 4))
45+
a = inp.reshape(inp.arange(n, dtype=dtype), (4, 4))
46+
b = inp.reshape(inp.arange(n, dtype=dtype), (4, 4))
47+
c = inp.reshape(inp.arange(n, dtype=dtype), (4, 4))
48+
d = inp.reshape(inp.arange(n, dtype=dtype), (4, 4))
49+
50+
a1 = numpy.arange(n, dtype=dtype).reshape((4, 4))
51+
b1 = numpy.arange(n, dtype=dtype).reshape((4, 4))
52+
c1 = numpy.arange(n, dtype=dtype).reshape((4, 4))
53+
d1 = numpy.arange(n, dtype=dtype).reshape((4, 4))
5354

5455
result = inp.linalg.multi_dot([a, b, c, d])
5556
expected = numpy.linalg.multi_dot([a1, b1, c1, d1])

0 commit comments

Comments
 (0)