Skip to content

Update dpnp tests to run on Iris Xe #1294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

27 changes: 27 additions & 0 deletions tests/helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dpctl
import dpnp
import pytest


def get_all_dtypes(no_bool=False,
Expand Down Expand Up @@ -37,3 +38,29 @@ def get_all_dtypes(no_bool=False,
if not no_none:
dtypes.append(None)
return dtypes


def skip_or_check_if_dtype_not_supported(dtype, device=None, check_dtype=False):
"""
The function to check input type supported in DPNP based on the device capabilities.
"""

dev = dpctl.select_default_device() if device is None else device
dev_has_dp = dev.has_aspect_fp64
if dtype is dpnp.float64 and dev_has_dp is False:
if check_dtype:
return False
else:
pytest.skip(
f"{dev.name} does not support double precision floating point types"
)
dev_has_hp = dev.has_aspect_fp16
if dtype is dpnp.complex128 and dev_has_hp is False:
if check_dtype:
return False
else:
pytest.skip(
f"{dev.name} does not support double precision floating point types"
)

return True
48 changes: 21 additions & 27 deletions tests/test_absolute.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,45 @@
import pytest
from .helper import get_all_dtypes

import dpnp as inp

import numpy


@pytest.mark.parametrize("type",
[numpy.int64],
ids=['int64'])
def test_abs_int(type):
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
@pytest.mark.parametrize("dtype", get_all_dtypes(no_bool=True, no_complex=True))
def test_abs(dtype):
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9], dtype=dtype)
ia = inp.array(a)

result = inp.abs(ia)
expected = numpy.abs(a)
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("type",
[numpy.int64],
ids=['int64'])
def test_absolute_int(type):
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
)
def test_absolute(dtype):
a = numpy.array([[-2.0, 3.0, 9.1], [-2.0, 5.0, -2], [1.0, -2.0, 5.0]], dtype=dtype)
ia = inp.array(a)

result = inp.absolute(ia)
expected = numpy.absolute(a)
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("type",
[numpy.float64],
ids=['float64'])
def test_absolute_float(type):
a = numpy.array([[-2., 3., 9.1], [-2., 5.0, -2], [1.0, -2., 5.0]])
ia = inp.array(a)

result = inp.absolute(ia)
expected = numpy.absolute(a)
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("type",
[numpy.float64],
ids=['float64'])
def test_absolute_float_3(type):
a = numpy.array([[[-2., 3.], [9.1, 0.2]], [[-2., 5.0], [-2, -1.2]], [[1.0, -2.], [5.0, -1.1]]])
@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
)
def test_absolute_float_3d(dtype):
a = numpy.array(
[
[[-2.0, 3.0], [9.1, 0.2]],
[[-2.0, 5.0], [-2, -1.2]],
[[1.0, -2.0], [5.0, -1.1]],
],
dtype=dtype,
)
ia = inp.array(a)

result = inp.absolute(ia)
Expand Down
91 changes: 41 additions & 50 deletions tests/test_amin_amax.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import pytest
from .helper import get_all_dtypes

import dpnp

import numpy


@pytest.mark.parametrize("type",
[numpy.float64],
ids=['float64'])
def test_amax_float64(type):
a = numpy.array([[[-2., 3.], [9.1, 0.2]], [[-2., 5.0], [-2, -1.2]], [[1.0, -2.], [5.0, -1.1]]])
@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
)
def test_amax(dtype):
a = numpy.array(
[
[[-2.0, 3.0], [9.1, 0.2]],
[[-2.0, 5.0], [-2, -1.2]],
[[1.0, -2.0], [5.0, -1.1]],
],
dtype=dtype,
)
ia = dpnp.array(a)

for axis in range(len(a)):
Expand All @@ -18,23 +26,18 @@ def test_amax_float64(type):
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("type",
[numpy.int64],
ids=['int64'])
def test_amax_int(type):
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
ia = dpnp.array(a)

result = dpnp.amax(ia)
expected = numpy.amax(a)
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("type",
[numpy.float64],
ids=['float64'])
def test_amin_float64(type):
a = numpy.array([[[-2., 3.], [9.1, 0.2]], [[-2., 5.0], [-2, -1.2]], [[1.0, -2.], [5.0, -1.1]]])
@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
)
def test_amin(dtype):
a = numpy.array(
[
[[-2.0, 3.0], [9.1, 0.2]],
[[-2.0, 5.0], [-2, -1.2]],
[[1.0, -2.0], [5.0, -1.1]],
],
dtype=dtype,
)
ia = dpnp.array(a)

for axis in range(len(a)):
Expand All @@ -43,18 +46,6 @@ def test_amin_float64(type):
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("type",
[numpy.int64],
ids=['int64'])
def test_amin_int(type):
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
ia = dpnp.array(a)

result = dpnp.amin(ia)
expected = numpy.amin(a)
numpy.testing.assert_array_equal(expected, result)


def _get_min_max_input(type, shape):
size = 1
for i in range(len(shape)):
Expand All @@ -68,14 +59,14 @@ def _get_min_max_input(type, shape):


@pytest.mark.usefixtures("allow_fall_back_on_numpy")
@pytest.mark.parametrize("type",
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
ids=['float64', 'float32', 'int64', 'int32'])
@pytest.mark.parametrize("shape",
[(4,), (2, 3), (4, 5, 6)],
ids=['(4,)', '(2,3)', '(4,5,6)'])
def test_amax(type, shape):
a = _get_min_max_input(type, shape)
@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
)
@pytest.mark.parametrize(
"shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2,3)", "(4,5,6)"]
)
def test_amax_with_shape(dtype, shape):
a = _get_min_max_input(dtype, shape)

ia = dpnp.array(a)

Expand All @@ -89,14 +80,14 @@ def test_amax(type, shape):


@pytest.mark.usefixtures("allow_fall_back_on_numpy")
@pytest.mark.parametrize("type",
[numpy.float64, numpy.float32, numpy.int64, numpy.int32],
ids=['float64', 'float32', 'int64', 'int32'])
@pytest.mark.parametrize("shape",
[(4,), (2, 3), (4, 5, 6)],
ids=['(4,)', '(2,3)', '(4,5,6)'])
def test_amin(type, shape):
a = _get_min_max_input(type, shape)
@pytest.mark.parametrize(
"dtype", get_all_dtypes(no_bool=True, no_none=True, no_complex=True)
)
@pytest.mark.parametrize(
"shape", [(4,), (2, 3), (4, 5, 6)], ids=["(4,)", "(2,3)", "(4,5,6)"]
)
def test_amin_with_shape(dtype, shape):
a = _get_min_max_input(dtype, shape)

ia = dpnp.array(a)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_arraycreation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_eye(N, M, k, dtype, order):


@pytest.mark.usefixtures("allow_fall_back_on_numpy")
@pytest.mark.parametrize("dtype", get_all_dtypes(no_float16=False))
@pytest.mark.parametrize("dtype", get_all_dtypes(no_float16=False, no_none=True))
def test_frombuffer(dtype):
buffer = b'12345678ABCDEF00'
func = lambda xp: xp.frombuffer(buffer, dtype=dtype)
Expand Down
24 changes: 9 additions & 15 deletions tests/test_flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,29 @@
import numpy


@pytest.mark.parametrize("type",
[numpy.int64],
ids=['int64'])
def test_flat(type):
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9])
@pytest.mark.parametrize("dtype", [numpy.int64], ids=["int64"])
def test_flat(dtype):
a = numpy.array([1, 0, 2, -3, -1, 2, 21, -9], dtype=dtype)
ia = inp.array(a)

result = ia.flat[0]
expected = a.flat[0]
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("type",
[numpy.int64],
ids=['int64'])
def test_flat2(type):
a = numpy.arange(1, 7).reshape(2, 3)
@pytest.mark.parametrize("dtype", [numpy.int64], ids=["int64"])
def test_flat2(dtype):
a = numpy.arange(1, 7, dtype=dtype).reshape(2, 3)
ia = inp.array(a)

result = ia.flat[3]
expected = a.flat[3]
numpy.testing.assert_array_equal(expected, result)


@pytest.mark.parametrize("type",
[numpy.int64],
ids=['int64'])
def test_flat3(type):
a = numpy.arange(1, 7).reshape(2, 3).T
@pytest.mark.parametrize("dtype", [numpy.int64], ids=["int64"])
def test_flat3(dtype):
a = numpy.arange(1, 7, dtype=dtype).reshape(2, 3).T
ia = inp.array(a)

result = ia.flat[3]
Expand Down
22 changes: 18 additions & 4 deletions tests/test_manipulation.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import pytest
from .helper import get_all_dtypes
import numpy
import dpnp


dtypes_list = get_all_dtypes(no_none=True, no_complex=True)
testdata = []
testdata += [([True, False, True], dtype) for dtype in ['float32', 'float64', 'int32', 'int64', 'bool']]
testdata += [([1, -1, 0], dtype) for dtype in ['float32', 'float64', 'int32', 'int64']]
testdata += [([0.1, 0.0, -0.1], dtype) for dtype in ['float32', 'float64']]
testdata += [([1j, -1j, 1 - 2j], dtype) for dtype in ['complex128']]
testdata += [([True, False, True], dtype) for dtype in dtypes_list]
testdata += [
([1, -1, 0], dtype)
for dtype in dtypes_list
if not numpy.issubdtype(dtype, numpy.bool_)
]
testdata += [
([0.1, 0.0, -0.1], dtype)
for dtype in dtypes_list
if numpy.issubdtype(dtype, numpy.floating)
]
testdata += [
([1j, -1j, 1 - 2j], dtype)
for dtype in ["complex128"]
if numpy.complex128 in get_all_dtypes(no_none=True, no_bool=True)
]


@pytest.mark.parametrize("in_obj,out_dtype", testdata)
Expand Down
Loading