Skip to content

Commit b875249

Browse files
committed
Proper handling of input shapes passed to dpnp.random.rand()
1 parent 96d128d commit b875249

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

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(

0 commit comments

Comments
 (0)