Skip to content

Commit a8cb6b5

Browse files
authored
Merge 87ea8be into e0c9cf1
2 parents e0c9cf1 + 87ea8be commit a8cb6b5

File tree

118 files changed

+16867
-2081
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+16867
-2081
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ repos:
3434
(?x)^(
3535
dpnp/tests/test_arraycreation.py|
3636
dpnp/tests/test_sycl_queue.py|
37-
dpnp/tests/test_usm_type.py
37+
dpnp/tests/test_usm_type.py|
38+
dpnp/tests/third_party/cupy/core_tests/test_nep50_examples.py
3839
)$
3940
- id: python-no-log-warn
4041
- id: python-use-type-annotations

dpnp/dpnp_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def mT(self):
150150
if self.ndim < 2:
151151
raise ValueError("matrix transpose with ndim < 2 is undefined")
152152

153-
return self._array_obj.mT
153+
return dpnp_array._create_from_usm_ndarray(self._array_obj.mT)
154154

155155
def to_device(self, target_device):
156156
"""Transfer array to target device."""

dpnp/random/dpnp_iface_random.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,25 +1022,31 @@ def power(a, size=None):
10221022
return call_origin(numpy.random.power, a, size)
10231023

10241024

1025-
def rand(d0, *dn, device=None, usm_type="device", sycl_queue=None):
1025+
def rand(*args, device=None, usm_type="device", sycl_queue=None):
10261026
"""
10271027
Random values in a given shape.
10281028
1029-
Create an array of the given shape and populate it with random samples
1030-
from a uniform distribution over [0, 1).
1029+
Create an array of the given shape and populate it with random samples from
1030+
a uniform distribution over ``[0, 1)``.
10311031
10321032
For full documentation refer to :obj:`numpy.random.rand`.
10331033
10341034
Parameters
10351035
----------
1036+
d0, d1, ..., dn : int, optional
1037+
The dimensions of the returned array, must be non-negative.
1038+
If no argument is given a single Python float is returned.
10361039
device : {None, string, SyclDevice, SyclQueue}, optional
10371040
An array API concept of device where the output array is created.
1038-
The `device` can be ``None`` (the default), an OneAPI filter selector string,
1039-
an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
1040-
an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
1041+
The `device` can be ``None`` (the default), an OneAPI filter selector
1042+
string, an instance of :class:`dpctl.SyclDevice` corresponding to
1043+
a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`,
1044+
or a `Device` object returned by
10411045
:obj:`dpnp.dpnp_array.dpnp_array.device` property.
1046+
Default: ``None``.
10421047
usm_type : {"device", "shared", "host"}, optional
10431048
The type of SYCL USM allocation for the output array.
1049+
Default: ``"device"``.
10441050
sycl_queue : {None, SyclQueue}, optional
10451051
A SYCL queue to use for output array allocation and copying. The
10461052
`sycl_queue` can be passed as ``None`` (the default), which means
@@ -1051,23 +1057,27 @@ def rand(d0, *dn, device=None, usm_type="device", sycl_queue=None):
10511057
Returns
10521058
-------
10531059
out : dpnp.ndarray
1054-
Random values in a given shape.
1055-
Output array data type is :obj:`dpnp.float64` if device supports it, or :obj:`dpnp.float32` otherwise.
1060+
Random values in a given shape ``(d0, d1, ..., dn)``.
1061+
Output array data type is :obj:`dpnp.float64` if a device supports it,
1062+
or :obj:`dpnp.float32` type otherwise.
10561063
1057-
Examples
1064+
See Also
10581065
--------
1059-
>>> s = dpnp.random.rand(3, 2)
1066+
:obj:`dpnp.random.random` : Return random floats in the half-open interval
1067+
``[0.0, 1.0)``.
1068+
:obj:`dpnp.random.random_sample` : Return random floats in the half-open
1069+
interval ``[0.0, 1.0)``.
1070+
:obj:`dpnp.random.uniform` : Draw samples from a uniform distribution.
10601071
1061-
See Also
1072+
Examples
10621073
--------
1063-
:obj:`dpnp.random.random`
1064-
:obj:`dpnp.random.random_sample`
1065-
:obj:`dpnp.random.uniform`
1074+
>>> import dpnp as np
1075+
>>> s = np.random.rand(3, 2)
10661076
10671077
"""
10681078

10691079
rs = _get_random_state(device=device, sycl_queue=sycl_queue)
1070-
return rs.rand(d0, *dn, usm_type=usm_type)
1080+
return rs.rand(*args, usm_type=usm_type)
10711081

10721082

10731083
def randint(

dpnp/tests/skipped_tests.tbl

Lines changed: 0 additions & 330 deletions
Large diffs are not rendered by default.

dpnp/tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 331 deletions
Large diffs are not rendered by default.

dpnp/tests/skipped_tests_gpu_no_fp64.tbl

Lines changed: 0 additions & 171 deletions
Large diffs are not rendered by default.

dpnp/tests/test_sycl_queue.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,24 +1079,27 @@ def test_vecdot(device, shape_pair):
10791079

10801080

10811081
@pytest.mark.parametrize(
1082-
"func, kwargs",
1082+
"func, args, kwargs",
10831083
[
1084-
pytest.param("normal", {"loc": 1.0, "scale": 3.4, "size": (5, 12)}),
1085-
pytest.param("rand", {"d0": 20}),
1084+
pytest.param("normal", [], {"loc": 1.0, "scale": 3.4, "size": (5, 12)}),
1085+
pytest.param("rand", [20], {}),
10861086
pytest.param(
10871087
"randint",
1088+
[],
10881089
{"low": 2, "high": 15, "size": (4, 8, 16), "dtype": dpnp.int32},
10891090
),
1090-
pytest.param("randn", {"d0": 20}),
1091-
pytest.param("random", {"size": (35, 45)}),
1091+
pytest.param("randn", [], {"d0": 20}),
1092+
pytest.param("random", [], {"size": (35, 45)}),
1093+
pytest.param(
1094+
"random_integers", [], {"low": -17, "high": 3, "size": (12, 16)}
1095+
),
1096+
pytest.param("random_sample", [], {"size": (7, 7)}),
1097+
pytest.param("ranf", [], {"size": (10, 7, 12)}),
1098+
pytest.param("sample", [], {"size": (7, 9)}),
1099+
pytest.param("standard_normal", [], {"size": (4, 4, 8)}),
10921100
pytest.param(
1093-
"random_integers", {"low": -17, "high": 3, "size": (12, 16)}
1101+
"uniform", [], {"low": 1.0, "high": 2.0, "size": (4, 2, 5)}
10941102
),
1095-
pytest.param("random_sample", {"size": (7, 7)}),
1096-
pytest.param("ranf", {"size": (10, 7, 12)}),
1097-
pytest.param("sample", {"size": (7, 9)}),
1098-
pytest.param("standard_normal", {"size": (4, 4, 8)}),
1099-
pytest.param("uniform", {"low": 1.0, "high": 2.0, "size": (4, 2, 5)}),
11001103
],
11011104
)
11021105
@pytest.mark.parametrize(
@@ -1105,11 +1108,11 @@ def test_vecdot(device, shape_pair):
11051108
ids=[device.filter_string for device in valid_devices],
11061109
)
11071110
@pytest.mark.parametrize("usm_type", ["host", "device", "shared"])
1108-
def test_random(func, kwargs, device, usm_type):
1111+
def test_random(func, args, kwargs, device, usm_type):
11091112
kwargs = {**kwargs, "device": device, "usm_type": usm_type}
11101113

11111114
# test with default SYCL queue per a device
1112-
res_array = getattr(dpnp.random, func)(**kwargs)
1115+
res_array = getattr(dpnp.random, func)(*args, **kwargs)
11131116
assert device == res_array.sycl_device
11141117
assert usm_type == res_array.usm_type
11151118

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

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

dpnp/tests/third_party/cupy/binary_tests/test_elementwise.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
class TestElementwise(unittest.TestCase):
7+
78
@testing.for_int_dtypes()
89
@testing.numpy_cupy_array_equal()
910
def check_unary_int(self, name, xp, dtype):
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import unittest
2+
3+
import numpy
4+
import pytest
5+
6+
import dpnp as cupy
7+
from dpnp.tests.third_party.cupy import testing
8+
9+
pytest.skip(
10+
"packbits() and unpackbits() are not supported yet", allow_module_level=True
11+
)
12+
13+
14+
class TestPacking(unittest.TestCase):
15+
16+
@testing.for_int_dtypes()
17+
@testing.numpy_cupy_array_equal()
18+
def check_packbits(self, data, xp, dtype, bitorder="big"):
19+
# Note numpy <= 1.9 raises an Exception when an input array is bool.
20+
# See https://github.com/numpy/numpy/issues/5377
21+
a = xp.array(data, dtype=dtype)
22+
return xp.packbits(a, bitorder=bitorder)
23+
24+
@testing.numpy_cupy_array_equal()
25+
def check_unpackbits(self, data, xp, bitorder="big"):
26+
a = xp.array(data, dtype=xp.uint8)
27+
return xp.unpackbits(a, bitorder=bitorder)
28+
29+
def test_packbits(self):
30+
self.check_packbits([0])
31+
self.check_packbits([1])
32+
self.check_packbits([0, 1])
33+
self.check_packbits([1, 0, 1, 1, 0, 1, 1, 1])
34+
self.check_packbits([1, 0, 1, 1, 0, 1, 1, 1, 1])
35+
self.check_packbits(numpy.arange(24).reshape((2, 3, 4)) % 2)
36+
37+
def test_packbits_order(self):
38+
for bo in ["big", "little"]:
39+
self.check_packbits([0], bitorder=bo)
40+
self.check_packbits([1], bitorder=bo)
41+
self.check_packbits([0, 1], bitorder=bo)
42+
self.check_packbits([1, 0, 1, 1, 0, 1, 1, 1], bitorder=bo)
43+
self.check_packbits([1, 0, 1, 1, 0, 1, 1, 1, 1], bitorder=bo)
44+
self.check_packbits(
45+
numpy.arange(24).reshape((2, 3, 4)) % 2, bitorder=bo
46+
)
47+
48+
def test_packbits_empty(self):
49+
# Note packbits of numpy <= 1.11 has a bug against empty arrays.
50+
# See https://github.com/numpy/numpy/issues/8324
51+
self.check_packbits([])
52+
53+
def test_pack_invalid_order(self):
54+
a = cupy.array([10, 20, 30])
55+
pytest.raises(ValueError, cupy.packbits, a, bitorder="ascendant")
56+
pytest.raises(ValueError, cupy.packbits, a, bitorder=10.4)
57+
58+
def test_pack_invalid_array(self):
59+
fa = cupy.array([10, 20, 30], dtype=float)
60+
pytest.raises(TypeError, cupy.packbits, fa)
61+
62+
def test_unpackbits(self):
63+
self.check_unpackbits([])
64+
self.check_unpackbits([0])
65+
self.check_unpackbits([1])
66+
self.check_unpackbits([255])
67+
self.check_unpackbits([100, 200, 123, 213])
68+
69+
def test_unpack_invalid_array(self):
70+
a = cupy.array([10, 20, 30])
71+
pytest.raises(TypeError, cupy.unpackbits, a)
72+
pytest.raises(TypeError, cupy.unpackbits, a.astype(float))
73+
74+
def test_pack_unpack_order(self):
75+
for bo in ["big", "little"]:
76+
self.check_unpackbits([], bitorder=bo)
77+
self.check_unpackbits([0], bitorder=bo)
78+
self.check_unpackbits([1], bitorder=bo)
79+
self.check_unpackbits([255], bitorder=bo)
80+
self.check_unpackbits([100, 200, 123, 213], bitorder=bo)
81+
82+
def test_unpack_invalid_order(self):
83+
a = cupy.array([10, 20, 30], dtype=cupy.uint8)
84+
pytest.raises(ValueError, cupy.unpackbits, a, bitorder="r")
85+
pytest.raises(ValueError, cupy.unpackbits, a, bitorder=10)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import unittest
2+
3+
import numpy
4+
import pytest
5+
6+
import dpnp as cupy
7+
from dpnp.tests.third_party.cupy import testing
8+
9+
pytest.skip(
10+
"__array_function__ protocol is not supported", allow_module_level=True
11+
)
12+
13+
14+
class TestArrayFunction(unittest.TestCase):
15+
16+
@testing.with_requires("numpy>=1.17.0")
17+
def test_array_function(self):
18+
a = numpy.random.randn(100, 100)
19+
a_cpu = numpy.asarray(a)
20+
a_gpu = cupy.asarray(a)
21+
22+
# The numpy call for both CPU and GPU arrays is intentional to test the
23+
# __array_function__ protocol
24+
qr_cpu = numpy.linalg.qr(a_cpu)
25+
qr_gpu = numpy.linalg.qr(a_gpu)
26+
27+
if isinstance(qr_cpu, tuple):
28+
for b_cpu, b_gpu in zip(qr_cpu, qr_gpu):
29+
assert b_cpu.dtype == b_gpu.dtype
30+
testing.assert_allclose(b_cpu, b_gpu, atol=1e-4)
31+
else:
32+
assert qr_cpu.dtype == qr_gpu.dtype
33+
testing.assert_allclose(qr_cpu, qr_gpu, atol=1e-4)
34+
35+
@testing.with_requires("numpy>=1.17.0")
36+
def test_array_function2(self):
37+
a = numpy.random.randn(100, 100)
38+
a_cpu = numpy.asarray(a)
39+
a_gpu = cupy.asarray(a)
40+
41+
# The numpy call for both CPU and GPU arrays is intentional to test the
42+
# __array_function__ protocol
43+
out_cpu = numpy.sum(a_cpu, axis=1)
44+
out_gpu = numpy.sum(a_gpu, axis=1)
45+
46+
assert out_cpu.dtype == out_gpu.dtype
47+
testing.assert_allclose(out_cpu, out_gpu, atol=1e-4)
48+
49+
@testing.with_requires("numpy>=1.17.0")
50+
@testing.numpy_cupy_equal()
51+
def test_array_function_can_cast(self, xp):
52+
return numpy.can_cast(xp.arange(2), "f4")
53+
54+
@testing.with_requires("numpy>=1.17.0")
55+
@testing.numpy_cupy_equal()
56+
def test_array_function_common_type(self, xp):
57+
return numpy.common_type(
58+
xp.arange(2, dtype="f8"), xp.arange(2, dtype="f4")
59+
)
60+
61+
@testing.with_requires("numpy>=1.17.0")
62+
@testing.numpy_cupy_equal()
63+
def test_array_function_result_type(self, xp):
64+
return numpy.result_type(3, xp.arange(2, dtype="f8"))

0 commit comments

Comments
 (0)