Skip to content

Commit 51938b0

Browse files
authored
Update descriptions of functions in RandomState class (#1264)
1 parent 3a31b82 commit 51938b0

File tree

1 file changed

+47
-34
lines changed

1 file changed

+47
-34
lines changed

dpnp/random/dpnp_random_state.py

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ class RandomState:
5757
A container for the Mersenne Twister pseudo-random number generator.
5858
5959
For full documentation refer to :obj:`numpy.random.RandomState`.
60+
61+
Parameters
62+
----------
63+
device : {None, string, SyclDevice, SyclQueue}, optional
64+
An array API concept of device where the output array is created.
65+
`device` can be ``None`` (the default), a oneAPI filter selector string,
66+
an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
67+
an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
68+
:obj:`dpnp.dpnp_array.dpnp_array.device` property.
69+
sycl_queue : {None, SyclQueue}, optional
70+
The SYCL queue to use for output array allocation and copying.
71+
72+
Limitations
73+
-----------
74+
Parameter `seed` is supported as either a integer scalar or array_like
75+
of maximumum three integer scalars.
6076
"""
6177

6278
def __init__(self, seed=None, device=None, sycl_queue=None):
@@ -107,9 +123,9 @@ def _is_signbit_scalar(self, x):
107123

108124
def _validate_float_dtype(self, dtype, supported_types):
109125
"""
110-
Test an input floating type if it is listed in ``supported_types`` and
126+
Test an input floating type if it is listed in `supported_types` and
111127
if it is supported by the used SYCL device.
112-
If ``dtype`` is None, default floating type will be validating.
128+
If `dtype` is ``None``, default floating type will be validating.
113129
Return the examined floating type if it follows all validation checks.
114130
"""
115131

@@ -139,7 +155,7 @@ def get_state(self):
139155

140156
def get_sycl_queue(self):
141157
"""
142-
Return an instance of of :class:`dpctl.SyclQueue` used within the generator for data allocation.
158+
Return an instance of :class:`dpctl.SyclQueue` used within the generator for data allocation.
143159
144160
Returns
145161
-------
@@ -151,7 +167,7 @@ def get_sycl_queue(self):
151167

152168
def get_sycl_device(self):
153169
"""
154-
Return an instance of of :class:`dpctl.SyclDevice` used within the generator to allocate data on.
170+
Return an instance of :class:`dpctl.SyclDevice` used within the generator to allocate data on.
155171
156172
Returns
157173
-------
@@ -169,25 +185,24 @@ def normal(self, loc=0.0, scale=1.0, size=None, dtype=None, usm_type="device"):
169185
170186
Parameters
171187
----------
172-
usm_type : ("device" | "shared" | "host"), optional
188+
usm_type : {"device", "shared", "host"}, optional
173189
The type of SYCL USM allocation for the output array.
174190
175191
Returns
176192
-------
177193
out : dpnp.ndarray
178194
Drawn samples from the parameterized normal distribution.
179-
Output array data type is the same as input ``dtype``. If ``dtype`` is None (default),
180-
:obj:`dpnp.float64` type will be used if device supports it or :obj:`dpnp.float32` otherwise.
195+
Output array data type is the same as input `dtype`. If `dtype` is ``None`` (the default),
196+
:obj:`dpnp.float64` type will be used if device supports it, or :obj:`dpnp.float32` otherwise.
181197
182198
Limitations
183199
-----------
184-
Parameters ``loc`` and ``scale`` are supported as scalar. Otherwise,
200+
Parameters `loc` and `scale` are supported as scalar. Otherwise,
185201
:obj:`numpy.random.RandomState.normal(loc, scale, size)` samples are drawn.
186-
Parameter ``dtype`` is supported only for :obj:`dpnp.float32`, :obj:`dpnp.float64` or `None`.
202+
Parameter `dtype` is supported only as :obj:`dpnp.float32`, :obj:`dpnp.float64` or ``None``.
187203
188204
Examples
189205
--------
190-
Draw samples from the distribution:
191206
>>> s = dpnp.random.RandomState().normal(loc=3.7, scale=2.5, size=(2, 4))
192207
>>> print(s)
193208
[[ 1.58997253 -0.84288406 2.33836967 4.16394577]
@@ -241,14 +256,14 @@ def rand(self, *args, usm_type="device"):
241256
242257
Parameters
243258
----------
244-
usm_type : ("device" | "shared" | "host"), optional
259+
usm_type : {"device", "shared", "host"}, optional
245260
The type of SYCL USM allocation for the output array.
246261
247262
Returns
248263
-------
249264
out : dpnp.ndarray
250265
Random values in a given shape.
251-
Output array data type is :obj:`dpnp.float64` if device supports it or :obj:`dpnp.float32` otherwise.
266+
Output array data type is :obj:`dpnp.float64` if device supports it, or :obj:`dpnp.float32` otherwise.
252267
253268
Examples
254269
--------
@@ -284,21 +299,21 @@ def randint(self, low, high=None, size=None, dtype=int, usm_type="device"):
284299
285300
Parameters
286301
----------
287-
usm_type : ("device" | "shared" | "host"), optional
302+
usm_type : {"device", "shared", "host"}, optional
288303
The type of SYCL USM allocation for the output array.
289304
290305
Returns
291306
-------
292307
out : dpnp.ndarray
293308
`size`-shaped array of random integers from the appropriate distribution,
294-
or a single such random int if `size` not provided.
295-
Output array data type is the same as input ``dtype``.
309+
or a single such random int if `size` is not provided.
310+
Output array data type is the same as input `dtype`.
296311
297312
Limitations
298313
-----------
299-
Parameters ``low`` and ``high`` are supported only as scalar.
300-
Parameter ``dtype`` is supported only as :obj:`dpnp.int32` or `int`,
301-
but `int` value is considered to be exactly equivalent to :obj:`dpnp.int32`.
314+
Parameters `low` and `high` are supported only as a scalar.
315+
Parameter `dtype` is supported only as :obj:`dpnp.int32` or ``int``,
316+
but ``int`` value is considered to be exactly equivalent to :obj:`dpnp.int32`.
302317
Otherwise, :obj:`numpy.random.randint(low, high, size, dtype)` samples are drawn.
303318
304319
Examples
@@ -359,16 +374,16 @@ def randn(self, *args, usm_type="device"):
359374
360375
Parameters
361376
----------
362-
usm_type : ("device" | "shared" | "host"), optional
377+
usm_type : {"device", "shared", "host"}, optional
363378
The type of SYCL USM allocation for the output array.
364379
365380
Returns
366381
-------
367-
Z : dpnp.ndarray
382+
out : dpnp.ndarray
368383
A ``(d0, d1, ..., dn)``-shaped array of floating-point samples from
369384
the standard normal distribution, or a single such float if
370385
no parameters were supplied.
371-
Output array data type is :obj:`dpnp.float64` if device supports it
386+
Output array data type is :obj:`dpnp.float64` if device supports it,
372387
or :obj:`dpnp.float32` otherwise.
373388
374389
Examples
@@ -408,15 +423,15 @@ def random_sample(self, size=None, usm_type="device"):
408423
409424
Parameters
410425
----------
411-
usm_type : ("device" | "shared" | "host"), optional
426+
usm_type : {"device", "shared", "host"}, optional
412427
The type of SYCL USM allocation for the output array.
413428
414429
Returns
415430
-------
416431
out : dpnp.ndarray
417432
Array of random floats of shape `size` (if ``size=None``,
418433
zero dimension array with a single float is returned).
419-
Output array data type is :obj:`dpnp.float64` if device supports it
434+
Output array data type is :obj:`dpnp.float64` if device supports it,
420435
or :obj:`dpnp.float32` otherwise.
421436
422437
Examples
@@ -447,20 +462,19 @@ def standard_normal(self, size=None, usm_type="device"):
447462
448463
Parameters
449464
----------
450-
usm_type : ("device" | "shared" | "host"), optional
465+
usm_type : {"device", "shared", "host"}, optional
451466
The type of SYCL USM allocation for the output array.
452467
453468
Returns
454469
-------
455470
out : dpnp.ndarray
456-
A floating-point array of shape ``size`` of drawn samples, or a
457-
single sample if ``size`` was not specified.
458-
Output array data type is :obj:`dpnp.float64` if device supports it
471+
A floating-point array of shape `size` of drawn samples, or a
472+
single sample if `size` was not specified.
473+
Output array data type is :obj:`dpnp.float64` if device supports it,
459474
or :obj:`dpnp.float32` otherwise.
460475
461476
Examples
462477
--------
463-
Draw samples from the distribution:
464478
>>> s = dpnp.random.RandomState().standard_normal(size=(3, 5))
465479
>>> print(s)
466480
[[-0.84401099 -1.81715362 -0.54465213 0.18557831 0.28352814]
@@ -492,25 +506,24 @@ def uniform(self, low=0.0, high=1.0, size=None, dtype=None, usm_type="device"):
492506
493507
Parameters
494508
----------
495-
usm_type : ("device" | "shared" | "host"), optional
509+
usm_type : {"device", "shared", "host"}, optional
496510
The type of SYCL USM allocation for the output array.
497511
498512
Returns
499513
-------
500514
out : dpnp.ndarray
501515
Drawn samples from the parameterized uniform distribution.
502-
Output array data type is the same as input ``dtype``. If ``dtype`` is None (default),
503-
:obj:`dpnp.float64` type will be used if device supports it or :obj:`dpnp.float32` otherwise.
516+
Output array data type is the same as input `dtype`. If `dtype` is ``None`` (the default),
517+
:obj:`dpnp.float64` type will be used if device supports it, or :obj:`dpnp.float32` otherwise.
504518
505519
Limitations
506520
-----------
507-
Parameters ``low`` and ``high`` are supported as scalar. Otherwise,
521+
Parameters `low` and `high` are supported as scalar. Otherwise,
508522
:obj:`numpy.random.uniform(low, high, size)` samples are drawn.
509-
Parameter ``dtype`` is supported only for :obj:`dpnp.int32`, :obj:`dpnp.float32`, :obj:`dpnp.float64` or `None`.
523+
Parameter `dtype` is supported only as :obj:`dpnp.int32`, :obj:`dpnp.float32`, :obj:`dpnp.float64` or ``None``.
510524
511525
Examples
512526
--------
513-
Draw samples from the distribution:
514527
>>> low, high = 1.23, 10.54 # low and high
515528
>>> s = dpnp.random.RandomState().uniform(low, high, 5)
516529
>>> print(s)

0 commit comments

Comments
 (0)