Skip to content

Commit 5ac019c

Browse files
authored
Merge 47b30be into 6dbeba9
2 parents 6dbeba9 + 47b30be commit 5ac019c

File tree

103 files changed

+13511
-2080
lines changed

Some content is hidden

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

103 files changed

+13511
-2080
lines changed

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
@@ -1078,24 +1078,27 @@ def test_vecdot(device, shape_pair):
10781078

10791079

10801080
@pytest.mark.parametrize(
1081-
"func, kwargs",
1081+
"func, args, kwargs",
10821082
[
1083-
pytest.param("normal", {"loc": 1.0, "scale": 3.4, "size": (5, 12)}),
1084-
pytest.param("rand", {"d0": 20}),
1083+
pytest.param("normal", [], {"loc": 1.0, "scale": 3.4, "size": (5, 12)}),
1084+
pytest.param("rand", [20], {}),
10851085
pytest.param(
10861086
"randint",
1087+
[],
10871088
{"low": 2, "high": 15, "size": (4, 8, 16), "dtype": dpnp.int32},
10881089
),
1089-
pytest.param("randn", {"d0": 20}),
1090-
pytest.param("random", {"size": (35, 45)}),
1090+
pytest.param("randn", [], {"d0": 20}),
1091+
pytest.param("random", [], {"size": (35, 45)}),
1092+
pytest.param(
1093+
"random_integers", [], {"low": -17, "high": 3, "size": (12, 16)}
1094+
),
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)}),
10911099
pytest.param(
1092-
"random_integers", {"low": -17, "high": 3, "size": (12, 16)}
1100+
"uniform", [], {"low": 1.0, "high": 2.0, "size": (4, 2, 5)}
10931101
),
1094-
pytest.param("random_sample", {"size": (7, 7)}),
1095-
pytest.param("ranf", {"size": (10, 7, 12)}),
1096-
pytest.param("sample", {"size": (7, 9)}),
1097-
pytest.param("standard_normal", {"size": (4, 4, 8)}),
1098-
pytest.param("uniform", {"low": 1.0, "high": 2.0, "size": (4, 2, 5)}),
10991102
],
11001103
)
11011104
@pytest.mark.parametrize(
@@ -1104,11 +1107,11 @@ def test_vecdot(device, shape_pair):
11041107
ids=[device.filter_string for device in valid_devices],
11051108
)
11061109
@pytest.mark.parametrize("usm_type", ["host", "device", "shared"])
1107-
def test_random(func, kwargs, device, usm_type):
1110+
def test_random(func, args, kwargs, device, usm_type):
11081111
kwargs = {**kwargs, "device": device, "usm_type": usm_type}
11091112

11101113
# test with default SYCL queue per a device
1111-
res_array = getattr(dpnp.random, func)(**kwargs)
1114+
res_array = getattr(dpnp.random, func)(*args, **kwargs)
11121115
assert device == res_array.sycl_device
11131116
assert usm_type == res_array.usm_type
11141117

@@ -1120,7 +1123,7 @@ def test_random(func, kwargs, device, usm_type):
11201123
kwargs["sycl_queue"] = sycl_queue
11211124

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

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"))
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import unittest
2+
3+
import pytest
4+
5+
import dpnp as cupy
6+
from dpnp.tests.third_party.cupy import testing
7+
8+
pytest.skip("CArray is not supported", allow_module_level=True)
9+
10+
11+
class TestCArray(unittest.TestCase):
12+
13+
def test_size(self):
14+
x = cupy.arange(3).astype("i")
15+
y = cupy.ElementwiseKernel(
16+
"raw int32 x",
17+
"int32 y",
18+
"y = x.size()",
19+
"test_carray_size",
20+
)(x, size=1)
21+
assert int(y[0]) == 3
22+
23+
def test_shape(self):
24+
x = cupy.arange(6).reshape((2, 3)).astype("i")
25+
y = cupy.ElementwiseKernel(
26+
"raw int32 x",
27+
"int32 y",
28+
"y = x.shape()[i]",
29+
"test_carray_shape",
30+
)(x, size=2)
31+
testing.assert_array_equal(y, (2, 3))
32+
33+
def test_strides(self):
34+
x = cupy.arange(6).reshape((2, 3)).astype("i")
35+
y = cupy.ElementwiseKernel(
36+
"raw int32 x",
37+
"int32 y",
38+
"y = x.strides()[i]",
39+
"test_carray_strides",
40+
)(x, size=2)
41+
testing.assert_array_equal(y, (12, 4))
42+
43+
def test_getitem_int(self):
44+
x = cupy.arange(24).reshape((2, 3, 4)).astype("i")
45+
y = cupy.empty_like(x)
46+
y = cupy.ElementwiseKernel(
47+
"raw T x",
48+
"int32 y",
49+
"y = x[i]",
50+
"test_carray_getitem_int",
51+
)(x, y)
52+
testing.assert_array_equal(y, x)
53+
54+
def test_getitem_idx(self):
55+
x = cupy.arange(24).reshape((2, 3, 4)).astype("i")
56+
y = cupy.empty_like(x)
57+
y = cupy.ElementwiseKernel(
58+
"raw T x",
59+
"int32 y",
60+
"ptrdiff_t idx[] = {i / 12, i / 4 % 3, i % 4}; y = x[idx]",
61+
"test_carray_getitem_idx",
62+
)(x, y)
63+
testing.assert_array_equal(y, x)
64+
65+
66+
@testing.parameterize(
67+
{"size": 2**31 - 1024},
68+
{"size": 2**31},
69+
{"size": 2**31 + 1024},
70+
{"size": 2**32 - 1024},
71+
{"size": 2**32},
72+
{"size": 2**32 + 1024},
73+
)
74+
@testing.slow
75+
class TestCArray32BitBoundary(unittest.TestCase):
76+
# This test case is intended to confirm CArray indexing work correctly
77+
# with input/output arrays whose size is so large that it crosses the
78+
# 32-bit boundary (in terms of both number of elements and size in bytes).
79+
# This test requires approx. 8 GiB GPU memory to run.
80+
# See https://github.com/cupy/cupy/pull/882 for detailed discussions.
81+
82+
def tearDown(self):
83+
# Free huge memory for slow test
84+
cupy.get_default_memory_pool().free_all_blocks()
85+
86+
# HIP is known to fail with sizes > 2**32-1024
87+
@unittest.skipIf(cupy.cuda.runtime.is_hip, "HIP does not support this")
88+
def test(self):
89+
# Elementwise
90+
a = cupy.full((1, self.size), 7, dtype=cupy.int8)
91+
# Reduction
92+
result = a.sum(axis=0, dtype=cupy.int8)
93+
# Explicitly specify the dtype to absorb Linux/Windows difference.
94+
assert result.sum(dtype=cupy.int64) == self.size * 7
95+
96+
# HIP is known to fail with sizes > 2**32-1024
97+
@unittest.skipIf(cupy.cuda.runtime.is_hip, "HIP does not support this")
98+
def test_assign(self):
99+
a = cupy.zeros(self.size, dtype=cupy.int8)
100+
a[-1] = 1.0
101+
assert a.sum() == 1

dpnp/tests/third_party/cupy/core_tests/test_core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010

1111
class TestSize(unittest.TestCase):
12+
1213
# def tearDown(self):
1314
# # Free huge memory for slow test
1415
# cupy.get_default_memory_pool().free_all_blocks()
@@ -51,6 +52,7 @@ def test_size_huge(self, xp):
5152

5253
@pytest.mark.skip("no cupy._core submodule")
5354
class TestOrder(unittest.TestCase):
55+
5456
@testing.for_orders(_orders.keys())
5557
def test_ndarray(self, order):
5658
order_expect = _orders[order]
@@ -101,6 +103,7 @@ def test_cupy_ndarray(self, dtype):
101103
)
102104
@pytest.mark.skip("compiling cupy headers are not supported")
103105
class TestCuPyHeaders(unittest.TestCase):
106+
104107
def setUp(self):
105108
self.temporary_cache_dir_context = test_raw.use_temporary_cache_dir()
106109
self.cache_dir = self.temporary_cache_dir_context.__enter__()

0 commit comments

Comments
 (0)