Skip to content

Commit

Permalink
Update the scope of third party tests with the latest changes (IntelP…
Browse files Browse the repository at this point in the history
…ython#2148)

The PR proposes to update scope and content of third party tests with
the latest version.
That would help to reduce future work while implementing missing
functions and to improve code coverage of existing supported
functionality.

Also PR removes impacted tests from the files with a skip list and
replaces that by explicit muting in tests code.
  • Loading branch information
antonwolfy authored Dec 6, 2024
1 parent 4875e59 commit 4d636b3
Show file tree
Hide file tree
Showing 119 changed files with 16,869 additions and 2,083 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ repos:
(?x)^(
dpnp/tests/test_arraycreation.py|
dpnp/tests/test_sycl_queue.py|
dpnp/tests/test_usm_type.py
dpnp/tests/test_usm_type.py|
dpnp/tests/third_party/cupy/core_tests/test_nep50_examples.py
)$
- id: python-no-log-warn
- id: python-use-type-annotations
Expand Down
2 changes: 1 addition & 1 deletion dpnp/dpnp_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def mT(self):
if self.ndim < 2:
raise ValueError("matrix transpose with ndim < 2 is undefined")

return self._array_obj.mT
return dpnp_array._create_from_usm_ndarray(self._array_obj.mT)

def to_device(self, target_device):
"""Transfer array to target device."""
Expand Down
40 changes: 25 additions & 15 deletions dpnp/random/dpnp_iface_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,25 +1022,31 @@ def power(a, size=None):
return call_origin(numpy.random.power, a, size)


def rand(d0, *dn, device=None, usm_type="device", sycl_queue=None):
def rand(*args, device=None, usm_type="device", sycl_queue=None):
"""
Random values in a given shape.
Create an array of the given shape and populate it with random samples
from a uniform distribution over [0, 1).
Create an array of the given shape and populate it with random samples from
a uniform distribution over ``[0, 1)``.
For full documentation refer to :obj:`numpy.random.rand`.
Parameters
----------
*args : sequence of ints, optional
The dimensions of the returned array, must be non-negative.
If no argument is given a single Python float is returned.
device : {None, string, SyclDevice, SyclQueue}, optional
An array API concept of device where the output array is created.
The `device` can be ``None`` (the default), an OneAPI filter selector string,
an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
The `device` can be ``None`` (the default), an OneAPI filter selector
string, an instance of :class:`dpctl.SyclDevice` corresponding to
a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`,
or a `Device` object returned by
:obj:`dpnp.dpnp_array.dpnp_array.device` property.
Default: ``None``.
usm_type : {"device", "shared", "host"}, optional
The type of SYCL USM allocation for the output array.
Default: ``"device"``.
sycl_queue : {None, SyclQueue}, optional
A SYCL queue to use for output array allocation and copying. The
`sycl_queue` can be passed as ``None`` (the default), which means
Expand All @@ -1051,23 +1057,27 @@ def rand(d0, *dn, device=None, usm_type="device", sycl_queue=None):
Returns
-------
out : dpnp.ndarray
Random values in a given shape.
Output array data type is :obj:`dpnp.float64` if device supports it, or :obj:`dpnp.float32` otherwise.
Random values in a given shape ``(d0, d1, ..., dn)``.
Output array data type is :obj:`dpnp.float64` if a device supports it,
or :obj:`dpnp.float32` type otherwise.
Examples
See Also
--------
>>> s = dpnp.random.rand(3, 2)
:obj:`dpnp.random.random` : Return random floats in the half-open interval
``[0.0, 1.0)``.
:obj:`dpnp.random.random_sample` : Return random floats in the half-open
interval ``[0.0, 1.0)``.
:obj:`dpnp.random.uniform` : Draw samples from a uniform distribution.
See Also
Examples
--------
:obj:`dpnp.random.random`
:obj:`dpnp.random.random_sample`
:obj:`dpnp.random.uniform`
>>> import dpnp as np
>>> s = np.random.rand(3, 2)
"""

rs = _get_random_state(device=device, sycl_queue=sycl_queue)
return rs.rand(d0, *dn, usm_type=usm_type)
return rs.rand(*args, usm_type=usm_type)


def randint(
Expand Down
330 changes: 0 additions & 330 deletions dpnp/tests/skipped_tests.tbl

Large diffs are not rendered by default.

331 changes: 0 additions & 331 deletions dpnp/tests/skipped_tests_gpu.tbl

Large diffs are not rendered by default.

171 changes: 0 additions & 171 deletions dpnp/tests/skipped_tests_gpu_no_fp64.tbl

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions dpnp/tests/test_sycl_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,24 +1079,27 @@ def test_vecdot(device, shape_pair):


@pytest.mark.parametrize(
"func, kwargs",
"func, args, kwargs",
[
pytest.param("normal", {"loc": 1.0, "scale": 3.4, "size": (5, 12)}),
pytest.param("rand", {"d0": 20}),
pytest.param("normal", [], {"loc": 1.0, "scale": 3.4, "size": (5, 12)}),
pytest.param("rand", [20], {}),
pytest.param(
"randint",
[],
{"low": 2, "high": 15, "size": (4, 8, 16), "dtype": dpnp.int32},
),
pytest.param("randn", {"d0": 20}),
pytest.param("random", {"size": (35, 45)}),
pytest.param("randn", [], {"d0": 20}),
pytest.param("random", [], {"size": (35, 45)}),
pytest.param(
"random_integers", [], {"low": -17, "high": 3, "size": (12, 16)}
),
pytest.param("random_sample", [], {"size": (7, 7)}),
pytest.param("ranf", [], {"size": (10, 7, 12)}),
pytest.param("sample", [], {"size": (7, 9)}),
pytest.param("standard_normal", [], {"size": (4, 4, 8)}),
pytest.param(
"random_integers", {"low": -17, "high": 3, "size": (12, 16)}
"uniform", [], {"low": 1.0, "high": 2.0, "size": (4, 2, 5)}
),
pytest.param("random_sample", {"size": (7, 7)}),
pytest.param("ranf", {"size": (10, 7, 12)}),
pytest.param("sample", {"size": (7, 9)}),
pytest.param("standard_normal", {"size": (4, 4, 8)}),
pytest.param("uniform", {"low": 1.0, "high": 2.0, "size": (4, 2, 5)}),
],
)
@pytest.mark.parametrize(
Expand All @@ -1105,11 +1108,11 @@ def test_vecdot(device, shape_pair):
ids=[device.filter_string for device in valid_devices],
)
@pytest.mark.parametrize("usm_type", ["host", "device", "shared"])
def test_random(func, kwargs, device, usm_type):
def test_random(func, args, kwargs, device, usm_type):
kwargs = {**kwargs, "device": device, "usm_type": usm_type}

# test with default SYCL queue per a device
res_array = getattr(dpnp.random, func)(**kwargs)
res_array = getattr(dpnp.random, func)(*args, **kwargs)
assert device == res_array.sycl_device
assert usm_type == res_array.usm_type

Expand All @@ -1121,7 +1124,7 @@ def test_random(func, kwargs, device, usm_type):
kwargs["sycl_queue"] = sycl_queue

# test with in-order SYCL queue per a device and passed as argument
res_array = getattr(dpnp.random, func)(**kwargs)
res_array = getattr(dpnp.random, func)(*args, **kwargs)
assert usm_type == res_array.usm_type
assert_sycl_queue_equal(res_array.sycl_queue, sycl_queue)

Expand Down Expand Up @@ -2057,7 +2060,6 @@ def test_broadcast_to(device):
pytest.param("concatenate", [[1, 2], [3, 4]], [[5, 6]]),
pytest.param("dstack", [[1], [2], [3]], [[2], [3], [4]]),
pytest.param("hstack", (1, 2, 3), (4, 5, 6)),
pytest.param("row_stack", [[7], [1], [2], [3]], [[2], [3], [9], [4]]),
pytest.param("stack", [1, 2, 3], [4, 5, 6]),
pytest.param("vstack", [0, 1, 2, 3], [4, 5, 6, 7]),
],
Expand Down
1 change: 0 additions & 1 deletion dpnp/tests/test_usm_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,6 @@ def test_broadcast_to(usm_type):
pytest.param("concatenate", [[1, 2], [3, 4]], [[5, 6]]),
pytest.param("dstack", [[1], [2], [3]], [[2], [3], [4]]),
pytest.param("hstack", (1, 2, 3), (4, 5, 6)),
pytest.param("row_stack", [[7], [1], [2], [3]], [[2], [3], [9], [4]]),
pytest.param("stack", [1, 2, 3], [4, 5, 6]),
pytest.param("vstack", [0, 1, 2, 3], [4, 5, 6, 7]),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


class TestElementwise(unittest.TestCase):

@testing.for_int_dtypes()
@testing.numpy_cupy_array_equal()
def check_unary_int(self, name, xp, dtype):
Expand Down
85 changes: 85 additions & 0 deletions dpnp/tests/third_party/cupy/binary_tests/test_packing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import unittest

import numpy
import pytest

import dpnp as cupy
from dpnp.tests.third_party.cupy import testing

pytest.skip(
"packbits() and unpackbits() are not supported yet", allow_module_level=True
)


class TestPacking(unittest.TestCase):

@testing.for_int_dtypes()
@testing.numpy_cupy_array_equal()
def check_packbits(self, data, xp, dtype, bitorder="big"):
# Note numpy <= 1.9 raises an Exception when an input array is bool.
# See https://github.com/numpy/numpy/issues/5377
a = xp.array(data, dtype=dtype)
return xp.packbits(a, bitorder=bitorder)

@testing.numpy_cupy_array_equal()
def check_unpackbits(self, data, xp, bitorder="big"):
a = xp.array(data, dtype=xp.uint8)
return xp.unpackbits(a, bitorder=bitorder)

def test_packbits(self):
self.check_packbits([0])
self.check_packbits([1])
self.check_packbits([0, 1])
self.check_packbits([1, 0, 1, 1, 0, 1, 1, 1])
self.check_packbits([1, 0, 1, 1, 0, 1, 1, 1, 1])
self.check_packbits(numpy.arange(24).reshape((2, 3, 4)) % 2)

def test_packbits_order(self):
for bo in ["big", "little"]:
self.check_packbits([0], bitorder=bo)
self.check_packbits([1], bitorder=bo)
self.check_packbits([0, 1], bitorder=bo)
self.check_packbits([1, 0, 1, 1, 0, 1, 1, 1], bitorder=bo)
self.check_packbits([1, 0, 1, 1, 0, 1, 1, 1, 1], bitorder=bo)
self.check_packbits(
numpy.arange(24).reshape((2, 3, 4)) % 2, bitorder=bo
)

def test_packbits_empty(self):
# Note packbits of numpy <= 1.11 has a bug against empty arrays.
# See https://github.com/numpy/numpy/issues/8324
self.check_packbits([])

def test_pack_invalid_order(self):
a = cupy.array([10, 20, 30])
pytest.raises(ValueError, cupy.packbits, a, bitorder="ascendant")
pytest.raises(ValueError, cupy.packbits, a, bitorder=10.4)

def test_pack_invalid_array(self):
fa = cupy.array([10, 20, 30], dtype=float)
pytest.raises(TypeError, cupy.packbits, fa)

def test_unpackbits(self):
self.check_unpackbits([])
self.check_unpackbits([0])
self.check_unpackbits([1])
self.check_unpackbits([255])
self.check_unpackbits([100, 200, 123, 213])

def test_unpack_invalid_array(self):
a = cupy.array([10, 20, 30])
pytest.raises(TypeError, cupy.unpackbits, a)
pytest.raises(TypeError, cupy.unpackbits, a.astype(float))

def test_pack_unpack_order(self):
for bo in ["big", "little"]:
self.check_unpackbits([], bitorder=bo)
self.check_unpackbits([0], bitorder=bo)
self.check_unpackbits([1], bitorder=bo)
self.check_unpackbits([255], bitorder=bo)
self.check_unpackbits([100, 200, 123, 213], bitorder=bo)

def test_unpack_invalid_order(self):
a = cupy.array([10, 20, 30], dtype=cupy.uint8)
pytest.raises(ValueError, cupy.unpackbits, a, bitorder="r")
pytest.raises(ValueError, cupy.unpackbits, a, bitorder=10)
64 changes: 64 additions & 0 deletions dpnp/tests/third_party/cupy/core_tests/test_array_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import unittest

import numpy
import pytest

import dpnp as cupy
from dpnp.tests.third_party.cupy import testing

pytest.skip(
"__array_function__ protocol is not supported", allow_module_level=True
)


class TestArrayFunction(unittest.TestCase):

@testing.with_requires("numpy>=1.17.0")
def test_array_function(self):
a = numpy.random.randn(100, 100)
a_cpu = numpy.asarray(a)
a_gpu = cupy.asarray(a)

# The numpy call for both CPU and GPU arrays is intentional to test the
# __array_function__ protocol
qr_cpu = numpy.linalg.qr(a_cpu)
qr_gpu = numpy.linalg.qr(a_gpu)

if isinstance(qr_cpu, tuple):
for b_cpu, b_gpu in zip(qr_cpu, qr_gpu):
assert b_cpu.dtype == b_gpu.dtype
testing.assert_allclose(b_cpu, b_gpu, atol=1e-4)
else:
assert qr_cpu.dtype == qr_gpu.dtype
testing.assert_allclose(qr_cpu, qr_gpu, atol=1e-4)

@testing.with_requires("numpy>=1.17.0")
def test_array_function2(self):
a = numpy.random.randn(100, 100)
a_cpu = numpy.asarray(a)
a_gpu = cupy.asarray(a)

# The numpy call for both CPU and GPU arrays is intentional to test the
# __array_function__ protocol
out_cpu = numpy.sum(a_cpu, axis=1)
out_gpu = numpy.sum(a_gpu, axis=1)

assert out_cpu.dtype == out_gpu.dtype
testing.assert_allclose(out_cpu, out_gpu, atol=1e-4)

@testing.with_requires("numpy>=1.17.0")
@testing.numpy_cupy_equal()
def test_array_function_can_cast(self, xp):
return numpy.can_cast(xp.arange(2), "f4")

@testing.with_requires("numpy>=1.17.0")
@testing.numpy_cupy_equal()
def test_array_function_common_type(self, xp):
return numpy.common_type(
xp.arange(2, dtype="f8"), xp.arange(2, dtype="f4")
)

@testing.with_requires("numpy>=1.17.0")
@testing.numpy_cupy_equal()
def test_array_function_result_type(self, xp):
return numpy.result_type(3, xp.arange(2, dtype="f8"))
Loading

0 comments on commit 4d636b3

Please sign in to comment.