Skip to content
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

Update the scope of third party tests with the latest changes #2148

Merged
merged 78 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
9feed4a
Add test_typing.py
antonwolfy Nov 5, 2024
f5bed0d
Update test_type_routines.py
antonwolfy Nov 5, 2024
2868b00
Add test_numpy_interop.py
antonwolfy Nov 5, 2024
7222a42
Update test_ndim.py
antonwolfy Nov 5, 2024
6df0f82
Add test_init.py
antonwolfy Nov 5, 2024
dec81f1
Update statistics_tests/test_order.py
antonwolfy Nov 5, 2024
7d86f2c
Update statistics_tests/test_meanvar.py
antonwolfy Nov 5, 2024
1fdefe6
Update statistics_tests/test_histogram.py
antonwolfy Nov 5, 2024
2981ec8
Update statistics_tests/test_correlation.py
antonwolfy Nov 5, 2024
74cc56c
Update sorting_tests/test_count.py
antonwolfy Nov 14, 2024
378b9a8
Update sorting_tests/test_search.py
antonwolfy Nov 14, 2024
c6cc0f2
Update sorting_tests/test_sort.py
antonwolfy Nov 14, 2024
29bf6ec
Exclude random tests from files with skipped tests
antonwolfy Nov 15, 2024
ba19ec6
Update random_tests/test_sample.py
antonwolfy Nov 15, 2024
f58598c
Update random_tests/test_random.py
antonwolfy Nov 15, 2024
5d3ce10
Update random_tests/test_permutations.py
antonwolfy Nov 15, 2024
65aa25e
Add random_tests/test_init.py
antonwolfy Nov 15, 2024
5459dc4
Add common_distributions.py, test_generator_api.py, common_distributi…
antonwolfy Nov 15, 2024
589e763
Add test_bit_generator.py
antonwolfy Nov 15, 2024
7a7e7f2
Update random_tests/test_distributions.py
antonwolfy Nov 15, 2024
b19b5f1
Update padding tests
antonwolfy Nov 27, 2024
f6e6f58
Update misc_tests/test_byte_bounds.py
antonwolfy Nov 27, 2024
849a345
Added misc_tests/test_memory_ranges.py and misc_tests/test_who.py
antonwolfy Nov 27, 2024
f7a4fdb
Update math_tests/test_arithmetic.py
antonwolfy Nov 27, 2024
0d1f174
Update math_tests/test_matmul.py
antonwolfy Nov 27, 2024
2e05173
Update math_tests/test_misc.py
antonwolfy Nov 27, 2024
d6b87c2
Update math_tests/test_rounding.py
antonwolfy Nov 27, 2024
e5701cb
Update math_tests/test_sumprod.py
antonwolfy Nov 27, 2024
c991ae6
Add math_tests/test_window.py
antonwolfy Nov 27, 2024
72a49b5
Update remaining tests from math_tests
antonwolfy Nov 27, 2024
59688a3
Update manipulation_tests/test_add_remove.py
antonwolfy Nov 27, 2024
027a0fc
Update manipulation_tests/test_basic.py
antonwolfy Nov 27, 2024
69a3012
Update manipulation_tests/test_dims.py
antonwolfy Nov 27, 2024
ee0a78e
Update manipulation_tests/test_join.py
antonwolfy Nov 27, 2024
88b994d
Update manipulation_tests/test_kind.py
antonwolfy Nov 27, 2024
f745c2a
Update manipulation_tests/test_rearrange.py
antonwolfy Nov 27, 2024
f3445e3
Update manipulation_tests/test_shape.py
antonwolfy Nov 27, 2024
e6cc187
Update manipulation_tests/test_transpose.py
antonwolfy Nov 27, 2024
864f32b
Update remaining manipulation tests
antonwolfy Nov 27, 2024
dc384cc
dpnp.ndarray.mT wrongly returns usm_ndarray
antonwolfy Nov 27, 2024
01f7329
Update logic_tests/test_content.py
antonwolfy Nov 28, 2024
7ad6446
Update logic_tests/test_truth.py
antonwolfy Nov 28, 2024
6a275a4
Update logic_tests/test_type_test.py
antonwolfy Nov 28, 2024
f4a67bc
Update linalg_tests/test_decomposition.py
antonwolfy Nov 28, 2024
ec7c4e5
Update linalg_tests/test_eigenvalue.py
antonwolfy Nov 28, 2024
1ee0408
Update linalg_tests/test_einsum.py
antonwolfy Nov 28, 2024
55bb3c5
Update linalg_tests/test_product.py
antonwolfy Nov 28, 2024
0df52ea
Update linalg_tests/test_solve.py
antonwolfy Nov 28, 2024
cbca245
Update remaining LinAlg tests
antonwolfy Nov 28, 2024
e843d7b
Disable tests for broadcast() and interp() by pytest.mark.skip
antonwolfy Nov 28, 2024
eca2d00
Proper handling of input shapes passed to dpnp.random.rand()
antonwolfy Nov 28, 2024
78e0a22
Update scope of lib tests
antonwolfy Nov 28, 2024
977f747
Update scope of I/O tests
antonwolfy Nov 28, 2024
7f7571d
Update scope of indexing tests
antonwolfy Nov 28, 2024
1844089
Update scope of FFT tests
antonwolfy Nov 28, 2024
abaf6ee
Update scope of creation tests
antonwolfy Nov 29, 2024
5895a1e
Added unsupported scopes to core tests.
antonwolfy Nov 29, 2024
27b000c
Update core_tests/test_dlpack.py
antonwolfy Nov 29, 2024
f373576
Update core_tests/test_elementwise.py
antonwolfy Nov 29, 2024
3e1b80e
Added core_tests/test_ndarray_adv_indexing.py
antonwolfy Dec 2, 2024
9bff168
Update core_tests/test_ndarray_complex_ops.py
antonwolfy Dec 2, 2024
dc1735b
Add core_tests/test_ndarray_contiguity.py
antonwolfy Dec 2, 2024
a4f5e0a
Update core_tests/test_ndarray_conversion.py
antonwolfy Dec 2, 2024
9bffc04
update core_tests/test_ndarray_copy_and_view.py
antonwolfy Dec 2, 2024
7d02839
Added test_ndarray_cuda_array_interface.py, test_ndarray_elementwise_…
antonwolfy Dec 2, 2024
4ecf11f
Add core_tests/test_ndarray_indexing.py
antonwolfy Dec 2, 2024
fc45315
Update core_tests/test_ndarray_math.py
antonwolfy Dec 2, 2024
e95c068
Update core_tests/test_ndarray_reduction.py
antonwolfy Dec 2, 2024
f588c3b
Add core_tests/test_nep50_examples.py
antonwolfy Dec 2, 2024
3bf5a76
Add core_tests/test_ufunc_methods.py
antonwolfy Dec 2, 2024
af98016
Update remaining tests in core scope
antonwolfy Dec 2, 2024
3d44bbd
Update tests from binary scope
antonwolfy Dec 3, 2024
cd7e741
Add changes from the latest version of third party tests
antonwolfy Dec 3, 2024
87ea8be
Merge branch 'master' into align-third-party-tests
antonwolfy Dec 6, 2024
33cce1f
Update description of dpnp.random.rand() per review comment
antonwolfy Dec 6, 2024
514bf62
Mute warnings per review comment
antonwolfy Dec 6, 2024
4145b8f
row_stack is an alias on vstack, so no need to run CFD tests for both…
antonwolfy Dec 6, 2024
d9e66e1
Merge branch 'master' into align-third-party-tests
antonwolfy Dec 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading