• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IntelPython / dpnp / 12279662243

11 Dec 2024 03:33PM UTC coverage: 65.029% (-0.06%) from 65.09%
12279662243

Pull #2075

github

web-flow
Merge e87174e31 into c4997cc62
Pull Request #2075: Handle dpnp functions and tests to run on CUDA devices

4604 of 11552 branches covered (39.85%)

Branch coverage included in aggregate %.

49 of 89 new or added lines in 7 files covered. (55.06%)

1 existing line in 1 file now uncovered.

16996 of 21664 relevant lines covered (78.45%)

19739.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.28
/dpnp/random/dpnp_iface_random.py
1
# cython: language_level=3
2
# -*- coding: utf-8 -*-
3
# *****************************************************************************
4
# Copyright (c) 2016-2024, Intel Corporation
5
# All rights reserved.
6
#
7
# Redistribution and use in source and binary forms, with or without
8
# modification, are permitted provided that the following conditions are met:
9
# - Redistributions of source code must retain the above copyright notice,
10
#   this list of conditions and the following disclaimer.
11
# - Redistributions in binary form must reproduce the above copyright notice,
12
#   this list of conditions and the following disclaimer in the documentation
13
#   and/or other materials provided with the distribution.
14
#
15
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25
# THE POSSIBILITY OF SUCH DAMAGE.
26
# *****************************************************************************
27

28
"""
29
Module Intel NumPy Random
30

31
Set of functions to implement NumPy random module API
32

33
    .. seealso:: :obj:`numpy.random`
34

35
"""
36

37
import operator
1✔
38

39
import numpy
1✔
40

41
import dpnp
1✔
42
from dpnp.dpnp_algo import *
1✔
43
from dpnp.dpnp_utils import *
1✔
44

45
from .dpnp_algo_random import *
1✔
46
from .dpnp_random_state import RandomState
1✔
47

48
__all__ = [
1✔
49
    "beta",
50
    "binomial",
51
    "bytes",
52
    "chisquare",
53
    "choice",
54
    "dirichlet",
55
    "exponential",
56
    "f",
57
    "gamma",
58
    "geometric",
59
    "gumbel",
60
    "hypergeometric",
61
    "laplace",
62
    "logistic",
63
    "lognormal",
64
    "logseries",
65
    "multinomial",
66
    "multivariate_normal",
67
    "negative_binomial",
68
    "normal",
69
    "noncentral_chisquare",
70
    "noncentral_f",
71
    "pareto",
72
    "permutation",
73
    "poisson",
74
    "power",
75
    "rand",
76
    "randint",
77
    "randn",
78
    "random",
79
    "random_integers",
80
    "random_sample",
81
    "ranf",
82
    "rayleigh",
83
    "sample",
84
    "shuffle",
85
    "seed",
86
    "standard_cauchy",
87
    "standard_exponential",
88
    "standard_gamma",
89
    "standard_normal",
90
    "standard_t",
91
    "triangular",
92
    "uniform",
93
    "vonmises",
94
    "wald",
95
    "weibull",
96
    "zipf",
97
]
98

99

100
def _get_random_state(device=None, sycl_queue=None):
1✔
101
    global _dpnp_random_states
102

103
    if not isinstance(_dpnp_random_states, dict):
1!
104
        _dpnp_random_states = {}
×
105
    sycl_queue = dpnp.get_normalized_queue_device(
1✔
106
        device=device, sycl_queue=sycl_queue
107
    )
108
    if sycl_queue not in _dpnp_random_states:
1✔
109
        rs = RandomState(device=device, sycl_queue=sycl_queue)
1✔
110
        if sycl_queue == rs.get_sycl_queue():
1!
111
            _dpnp_random_states[sycl_queue] = rs
1✔
112
        else:
113
            raise RuntimeError(
×
114
                "Normalized SYCL queue {} mismatched with one returned by RandmoState {}".format(
115
                    sycl_queue, rs.get_sycl_queue()
116
                )
117
            )
118
    return _dpnp_random_states[sycl_queue]
1✔
119

120

121
def beta(a, b, size=None):
1✔
122
    """
123
    Draw samples from a Beta distribution.
124

125
    For full documentation refer to :obj:`numpy.random.beta`.
126

127
    Limitations
128
    -----------
129
    Parameters `a` and `b` are supported as scalar.
130
    Otherwise, :obj:`numpy.random.beta(a, b, size)` samples are drawn.
131
    Output array data type is :obj:`dpnp.float64`.
132

133
    Examples
134
    --------
135
    Draw samples from the distribution:
136

137
    >>> a, b = .4, .5  # alpha, beta
138
    >>> s = dpnp.random.beta(a, b, 1000)
139

140
    """
141

142
    if not use_origin_backend(a):
1!
143
        if dpnp.is_cuda_backend():
1!
NEW
144
            raise NotImplementedError(
×
145
                "Running on CUDA is currently not supported"
146
            )
147

148
        # TODO:
149
        # array_like of floats for `a`, `b`
150
        if not dpnp.isscalar(a):
1✔
151
            pass
1✔
152
        elif not dpnp.isscalar(b):
1!
153
            pass
×
154
        elif a <= 0:
1✔
155
            pass
1✔
156
        elif b <= 0:
1✔
157
            pass
1✔
158
        else:
159
            return dpnp_rng_beta(a, b, size).get_pyobj()
1✔
160

161
    return call_origin(numpy.random.beta, a, b, size)
1✔
162

163

164
def binomial(n, p, size=None):
1✔
165
    """
166
    Draw samples from a binomial distribution.
167

168
    For full documentation refer to :obj:`numpy.random.binomial`.
169

170
    Limitations
171
    -----------
172
    Output array data type is :obj:`dpnp.int32`.
173
    Parameters `n` and `p` are supported as scalar.
174
    Otherwise, :obj:`numpy.random.binomial(n, p, size)` samples are drawn.
175

176
    Examples
177
    --------
178
    Draw samples from the distribution:
179

180
    >>> n, p = 10, .5  # number of trials, probability of each trial
181
    >>> s = dpnp.random.binomial(n, p, 1000)
182
    # result of flipping a coin 10 times, tested 1000 times.
183
    A real world example. A company drills 9 wild-cat oil exploration
184
    wells, each with an estimated probability of success of 0.1. All nine
185
    wells fail. What is the probability of that happening?
186
    Let's do 20,000 trials of the model, and count the number that
187
    generate zero positive results.
188
    >>> sum(dpnp.random.binomial(9, 0.1, 20000) == 0)/20000.
189
    # answer = 0.38885, or 38%.
190

191
    """
192

193
    if not use_origin_backend(n):
1!
194
        if dpnp.is_cuda_backend():
1!
NEW
195
            raise NotImplementedError(
×
196
                "Running on CUDA is currently not supported"
197
            )
198

199
        # TODO:
200
        # array_like of floats for `p` param
201
        if not dpnp.isscalar(n):
1!
202
            pass
×
203
        elif not dpnp.isscalar(p):
1!
204
            pass
×
205
        elif p > 1 or p < 0:
1✔
206
            pass
1✔
207
        elif n < 0:
1✔
208
            pass
1✔
209
        else:
210
            return dpnp_rng_binomial(int(n), p, size).get_pyobj()
1✔
211

212
    return call_origin(numpy.random.binomial, n, p, size)
1✔
213

214

215
def bytes(length):
1✔
216
    """
217
    Return random bytes.
218

219
    For full documentation refer to :obj:`numpy.random.bytes`.
220

221
    Notes
222
    -----
223
    The function uses `numpy.random.bytes` on the backend and will be
224
    executed on fallback backend.
225

226
    """
227

228
    return call_origin(numpy.random.bytes, length)
1✔
229

230

231
def chisquare(df, size=None):
1✔
232
    """
233
    Draw samples from a chi-square distribution.
234

235
    For full documentation refer to :obj:`numpy.random.chisquare`.
236

237
    Limitations
238
    -----------
239
    Parameter `df` is supported as a scalar.
240
    Otherwise, :obj:`numpy.random.chisquare(df, size)` samples are drawn.
241
    Output array data type is default float type.
242

243
    Examples
244
    --------
245
    >>> dpnp.random.chisquare(2,4)
246
    array([ 1.89920014,  9.00867716,  3.13710533,  5.62318272]) # random
247

248
    """
249

250
    if not use_origin_backend(df):
1!
251
        if dpnp.is_cuda_backend():
1!
NEW
252
            raise NotImplementedError(
×
253
                "Running on CUDA is currently not supported"
254
            )
255

256
        # TODO:
257
        # array_like of floats for `df`
258
        if not dpnp.isscalar(df):
1✔
259
            pass
1✔
260
        elif df <= 0:
1✔
261
            pass
1✔
262
        else:
263
            # TODO:
264
            # float to int, safe
265
            return dpnp_rng_chisquare(int(df), size).get_pyobj()
1✔
266

267
    return call_origin(numpy.random.chisquare, df, size)
1✔
268

269

270
def choice(a, size=None, replace=True, p=None):
1✔
271
    """
272
    Generates a random sample from a given 1-D array.
273

274
    For full documentation refer to :obj:`numpy.random.choice`.
275

276
    Notes
277
    -----
278
    The function uses `numpy.random.choice` on the backend and will be
279
    executed on fallback backend.
280

281
    """
282

283
    return call_origin(numpy.random.choice, a, size, replace, p)
×
284

285

286
def dirichlet(alpha, size=None):
1✔
287
    """
288
    Draw samples from the Dirichlet distribution.
289

290
    For full documentation refer to :obj:`numpy.random.dirichlet`.
291

292
    Notes
293
    -----
294
    The function uses `numpy.random.dirichlet` on the backend and will be
295
    executed on fallback backend.
296

297
    """
298

299
    return call_origin(numpy.random.dirichlet, alpha, size)
1✔
300

301

302
def exponential(scale=1.0, size=None):
1✔
303
    """
304
    Draw samples from an exponential distribution.
305

306
    For full documentation refer to :obj:`numpy.random.exponential`.
307

308
    Limitations
309
    -----------
310
    Parameter `scale` is supported as a scalar.
311
    Otherwise, :obj:`numpy.random.exponential(scale, size)` samples are drawn.
312
    Output array data type is :obj:`dpnp.float64`.
313

314
    Examples
315
    --------
316
    Draw samples from the distribution:
317

318
    >>> scale = .5  # alpha
319
    >>> s = dpnp.random.exponential(scale, 1000)
320

321
    """
322

323
    if not use_origin_backend(scale):
1!
324
        if dpnp.is_cuda_backend():
1!
NEW
325
            raise NotImplementedError(
×
326
                "Running on CUDA is currently not supported"
327
            )
328

329
        # TODO:
330
        # array_like of floats for `scale`
331
        if not dpnp.isscalar(scale):
1✔
332
            pass
1✔
333
        elif scale < 0:
1✔
334
            pass
1✔
335
        else:
336
            return dpnp_rng_exponential(scale, size).get_pyobj()
1✔
337

338
    return call_origin(numpy.random.exponential, scale, size)
1✔
339

340

341
def f(dfnum, dfden, size=None):
1✔
342
    """
343
    Draw samples from an F distribution.
344

345
    For full documentation refer to :obj:`numpy.random.f`.
346

347
    Limitations
348
    -----------
349
    Parameters `dfnum` and `dfden` are supported as scalar.
350
    Otherwise, :obj:`numpy.random.f(dfnum, dfden, size)` samples are drawn.
351
    Output array data type is :obj:`dpnp.float64`.
352

353
    Examples
354
    --------
355
    >>> dfnum, dfden = 3., 2.
356
    >>> s = dpnp.random.f(dfnum, dfden, size)
357

358
    """
359

360
    if not use_origin_backend(dfnum):
1!
361
        if dpnp.is_cuda_backend():
1!
NEW
362
            raise NotImplementedError(
×
363
                "Running on CUDA is currently not supported"
364
            )
365

366
        # TODO:
367
        # array_like of floats for `dfnum` and `dfden`
368
        if not dpnp.isscalar(dfnum):
1✔
369
            pass
1✔
370
        elif not dpnp.isscalar(dfden):
1!
371
            pass
×
372
        elif dfnum <= 0:
1✔
373
            pass
1✔
374
        elif dfden <= 0:
1✔
375
            pass
1✔
376
        else:
377
            return dpnp_rng_f(dfnum, dfden, size).get_pyobj()
1✔
378

379
    return call_origin(numpy.random.f, dfnum, dfden, size)
1✔
380

381

382
def gamma(shape, scale=1.0, size=None):
1✔
383
    """
384
    Draw samples from a Gamma distribution.
385

386
    For full documentation refer to :obj:`numpy.random.gamma`.
387

388
    Limitations
389
    -----------
390
    Parameters `shape` and `scale` are supported as scalar.
391
    Otherwise, :obj:`numpy.random.gamma(shape, scale, size)` samples are drawn.
392
    Output array data type is :obj:`dpnp.float64`.
393

394
    Examples
395
    --------
396
    Draw samples from the distribution:
397

398
    >>> shape, scale = 0, 0.1  # shape and scale
399
    >>> s = dpnp.random.gamma(shape, scale, 1000)
400

401
    """
402

403
    if not use_origin_backend(scale):
1!
404
        if dpnp.is_cuda_backend():
1!
NEW
405
            raise NotImplementedError(
×
406
                "Running on CUDA is currently not supported"
407
            )
408

409
        # TODO:
410
        # array_like of floats for `scale` and `shape`
411
        if not dpnp.isscalar(scale):
1✔
412
            pass
1✔
413
        elif not dpnp.isscalar(shape):
1!
414
            pass
×
415
        elif scale < 0:
1✔
416
            pass
1✔
417
        elif shape < 0:
1✔
418
            pass
1✔
419
        else:
420
            return dpnp_rng_gamma(shape, scale, size).get_pyobj()
1✔
421

422
    return call_origin(numpy.random.gamma, shape, scale, size)
1✔
423

424

425
def geometric(p, size=None):
1✔
426
    """
427
    Draw samples from the geometric distribution.
428

429
    For full documentation refer to :obj:`numpy.random.geometric`.
430

431
    Limitations
432
    -----------
433
    Parameter `p` is supported as a scalar.
434
    Otherwise, :obj:`numpy.random.geometric(p, size)` samples are drawn.
435
    Output array data type is :obj:`dpnp.int32`.
436

437
    Examples
438
    --------
439
    Draw ten thousand values from the geometric distribution,
440
    with the probability of an individual success equal to 0.35:
441

442
    >>> z = dpnp.random.geometric(p=0.35, size=10000)
443

444
    """
445

446
    if not use_origin_backend(p):
1!
447
        if dpnp.is_cuda_backend():
1!
NEW
448
            raise NotImplementedError(
×
449
                "Running on CUDA is currently not supported"
450
            )
451

452
        # TODO:
453
        # array_like of floats for `p` param
454
        if not dpnp.isscalar(p):
1✔
455
            pass
1✔
456
        elif p > 1 or p <= 0:
1✔
457
            pass
1✔
458
        else:
459
            return dpnp_rng_geometric(p, size).get_pyobj()
1✔
460

461
    return call_origin(numpy.random.geometric, p, size)
1✔
462

463

464
def gumbel(loc=0.0, scale=1.0, size=None):
1✔
465
    """
466
    Draw samples from a Gumbel distribution.
467

468
    For full documentation refer to :obj:`numpy.random.gumbel`.
469

470
    Limitations
471
    -----------
472
    Parameters `loc` and `scale` are supported as scalar.
473
    Otherwise, :obj:`numpy.random.gumbel(loc, scale, size)` samples are drawn.
474
    Output array data type is :obj:`dpnp.float64`.
475

476
    Examples
477
    --------
478
    Draw samples from the distribution:
479

480
    >>> mu, beta = 0, 0.1 # location and scale
481
    >>> s = dpnp.random.gumbel(mu, beta, 1000)
482

483
    """
484

485
    if not use_origin_backend(loc):
1!
486
        if dpnp.is_cuda_backend():
1!
NEW
487
            raise NotImplementedError(
×
488
                "Running on CUDA is currently not supported"
489
            )
490

491
        # TODO:
492
        # array_like of floats for `loc` and `scale` params
493
        if not dpnp.isscalar(scale):
1✔
494
            pass
1✔
495
        elif not dpnp.isscalar(loc):
1!
496
            pass
×
497
        elif scale < 0:
1✔
498
            pass
1✔
499
        else:
500
            return dpnp_rng_gumbel(loc, scale, size).get_pyobj()
1✔
501

502
    return call_origin(numpy.random.gumbel, loc, scale, size)
1✔
503

504

505
def hypergeometric(ngood, nbad, nsample, size=None):
1✔
506
    """
507
    Draw samples from a Hypergeometric distribution.
508

509
    For full documentation refer to :obj:`numpy.random.hypergeometric`.
510

511
    Limitations
512
    -----------
513
    Parameters `ngood`, `nbad` and `nsample` are supported as scalar.
514
    Otherwise, :obj:`numpy.random.hypergeometric(shape, scale, size)` samples
515
    are drawn.
516
    Output array data type is :obj:`dpnp.int32`.
517

518
    Examples
519
    --------
520
    Draw samples from the distribution:
521

522
    >>> ngood, nbad, nsamp = 100, 2, 10
523
    # number of good, number of bad, and number of samples
524
    >>> s = dpnp.random.hypergeometric(ngood, nbad, nsamp, 1000)
525

526
    """
527

528
    if not use_origin_backend(ngood):
1!
529
        if dpnp.is_cuda_backend():
1!
NEW
530
            raise NotImplementedError(
×
531
                "Running on CUDA is currently not supported"
532
            )
533

534
        # TODO:
535
        # array_like of ints for `ngood`, `nbad`, `nsample` param
536
        if not dpnp.isscalar(ngood):
1✔
537
            pass
1✔
538
        elif not dpnp.isscalar(nbad):
1!
539
            pass
×
540
        elif not dpnp.isscalar(nsample):
1!
541
            pass
×
542
        elif ngood < 0:
1✔
543
            pass
1✔
544
        elif nbad < 0:
1✔
545
            pass
1✔
546
        elif nsample < 0:
1✔
547
            pass
1✔
548
        elif ngood + nbad < nsample:
1✔
549
            pass
1✔
550
        elif nsample < 1:
1✔
551
            pass
1✔
552
        else:
553
            _m = int(ngood)
1✔
554
            _l = int(ngood) + int(nbad)
1✔
555
            _s = int(nsample)
1✔
556
            return dpnp_rng_hypergeometric(_l, _s, _m, size).get_pyobj()
1✔
557

558
    return call_origin(numpy.random.hypergeometric, ngood, nbad, nsample, size)
1✔
559

560

561
def laplace(loc=0.0, scale=1.0, size=None):
1✔
562
    """
563
    Draw samples from the Laplace or double exponential distribution with
564
    specified location (or mean) and scale (decay).
565

566
    For full documentation refer to :obj:`numpy.random.laplace`.
567

568
    Limitations
569
    -----------
570
    Parameters `loc` and `scale` are supported as scalar.
571
    Otherwise, :obj:`numpy.random.laplace(loc, scale, size)` samples are drawn.
572
    Output array data type is :obj:`dpnp.float64`.
573

574
    Examples
575
    --------
576
    >>> loc, scale = 0., 1.
577
    >>> s = dpnp.random.laplace(loc, scale, 1000)
578

579
    """
580

581
    if not use_origin_backend(loc):
1!
582
        if dpnp.is_cuda_backend():
1!
NEW
583
            raise NotImplementedError(
×
584
                "Running on CUDA is currently not supported"
585
            )
586

587
        # TODO:
588
        # array_like of floats for `loc` and `scale`
589
        if not dpnp.isscalar(loc):
1✔
590
            pass
1✔
591
        elif not dpnp.isscalar(scale):
1!
592
            pass
×
593
        elif scale < 0:
1✔
594
            pass
1✔
595
        else:
596
            return dpnp_rng_laplace(loc, scale, size).get_pyobj()
1✔
597

598
    return call_origin(numpy.random.laplace, loc, scale, size)
1✔
599

600

601
def logistic(loc=0.0, scale=1.0, size=None):
1✔
602
    """
603
    Draw samples from a logistic distribution.
604

605
    For full documentation refer to :obj:`numpy.random.logistic`.
606

607
    Limitations
608
    -----------
609
    Parameters `loc` and `scale` are supported as scalar.
610
    Otherwise, :obj:`numpy.random.logistic(loc, scale, size)` samples are drawn.
611
    Output array data type is :obj:`dpnp.float64`.
612

613
    Examples
614
    --------
615
    >>> loc, scale = 0., 1.
616
    >>> s = dpnp.random.logistic(loc, scale, 1000)
617

618
    """
619

620
    if not use_origin_backend(loc):
1!
621
        if dpnp.is_cuda_backend():
1!
NEW
622
            raise NotImplementedError(
×
623
                "Running on CUDA is currently not supported"
624
            )
625

626
        # TODO:
627
        # array_like of floats for `loc` and `scale`
628
        if not dpnp.isscalar(loc):
1✔
629
            pass
1✔
630
        elif not dpnp.isscalar(scale):
1!
631
            pass
×
632
        elif scale < 0:
1✔
633
            pass
1✔
634
        else:
635
            result = dpnp_rng_logistic(loc, scale, size).get_pyobj()
1✔
636
            if size is None or size == 1:
1!
637
                return result[0]
×
638
            else:
639
                return result
1✔
640

641
    return call_origin(numpy.random.logistic, loc, scale, size)
1✔
642

643

644
def lognormal(mean=0.0, sigma=1.0, size=None):
1✔
645
    """
646
    Draw samples from a log-normal distribution.
647

648
    For full documentation refer to :obj:`numpy.random.lognormal`.
649

650
    Limitations
651
    -----------
652
    Parameters `mean` and `sigma` are supported as scalar.
653
    Otherwise, :obj:`numpy.random.lognormal(mean, sigma, size)` samples
654
    are drawn.
655
    Output array data type is :obj:`dpnp.float64`.
656

657
    Examples
658
    --------
659
    Draw samples from the distribution:
660

661
    >>> mu, sigma = 3., 1. # mean and standard deviation
662
    >>> s = dpnp.random.lognormal(mu, sigma, 1000)
663

664
    """
665

666
    if not use_origin_backend(mean):
1!
667
        if dpnp.is_cuda_backend():
1!
NEW
668
            raise NotImplementedError(
×
669
                "Running on CUDA is currently not supported"
670
            )
671

672
        # TODO:
673
        # array_like of floats for `mean` and `sigma` params
674
        if not dpnp.isscalar(mean):
1✔
675
            pass
1✔
676
        elif not dpnp.isscalar(sigma):
1!
677
            pass
×
678
        elif sigma < 0:
1✔
679
            pass
1✔
680
        else:
681
            return dpnp_rng_lognormal(mean, sigma, size).get_pyobj()
1✔
682

683
    return call_origin(numpy.random.lognormal, mean, sigma, size)
1✔
684

685

686
def logseries(p, size=None):
1✔
687
    """
688
    Draw samples from a logarithmic series distribution.
689

690
    For full documentation refer to :obj:`numpy.random.logseries`.
691

692
    Notes
693
    -----
694
    The function uses `numpy.random.logseries` on the backend and will be
695
    executed on fallback backend.
696

697
    """
698

699
    return call_origin(numpy.random.logseries, p, size)
1✔
700

701

702
def multinomial(n, pvals, size=None):
1✔
703
    """
704
    Draw samples from a multinomial distribution.
705

706
    For full documentation refer to :obj:`numpy.random.multinomial`.
707

708
    Limitations
709
    -----------
710
    Parameter `n` limited with int32 max. See, `numpy.iinfo(numpy.int32).max`.
711
    Sum of ``pvals``, `sum(pvals)` should be between (0, 1).
712
    Otherwise, :obj:`numpy.random.multinomial(n, pvals, size)`
713
    samples are drawn.
714

715
    Examples
716
    --------
717
    Throw a dice 20 times:
718

719
    >>> s = dpnp.random.multinomial(20, [1/6.]*6, size=1)
720
    >>> s.shape
721
    (1, 6)
722

723
    """
724

725
    if not use_origin_backend(n):
1!
726
        pvals_sum = sum(pvals)
1✔
727
        pvals_desc = dpnp.get_dpnp_descriptor(dpnp.array(pvals))
1✔
728
        d = len(pvals)
1✔
729
        if dpnp.is_cuda_backend(pvals_desc.get_array()):
1!
NEW
730
            raise NotImplementedError(
×
731
                "Running on CUDA is currently not supported"
732
            )
733

734
        if n < 0:
1✔
735
            pass
1✔
736
        elif n > dpnp.iinfo(dpnp.int32).max:
1!
737
            pass
×
738
        elif pvals_sum > 1.0:
1!
739
            pass
×
740
        elif pvals_sum < 0.0:
1✔
741
            pass
1✔
742
        else:
743
            if size is None:
1!
744
                shape = (d,)
×
745
            else:
746
                try:
1✔
747
                    shape = (operator.index(size), d)
1✔
748
                except Exception:
×
749
                    shape = tuple(size) + (d,)
×
750

751
            return dpnp_rng_multinomial(int(n), pvals_desc, shape).get_pyobj()
1✔
752

753
    return call_origin(numpy.random.multinomial, n, pvals, size)
1✔
754

755

756
def multivariate_normal(mean, cov, size=None, check_valid="warn", tol=1e-8):
1✔
757
    """
758
    Draw random samples from a multivariate normal distribution.
759

760
    For full documentation refer to :obj:`numpy.random.multivariate_normal`.
761

762
    Limitations
763
    -----------
764
    Parameters `check_valid` and `tol` are not supported.
765
    Otherwise, :obj:`numpy.random.multivariate_normal(mean, cov, size, check_valid, tol)`
766
    samples are drawn.
767

768
    Examples
769
    --------
770
    >>> mean = (1, 2)
771
    >>> cov = [[1, 0], [0, 1]]
772
    >>> x = dpnp.random.multivariate_normal(mean, cov, (3, 3))
773
    >>> x.shape
774
    (3, 3, 2)
775

776
    """
777

778
    if not use_origin_backend(mean):
1!
779
        mean_ = dpnp.get_dpnp_descriptor(dpnp.array(mean, dtype=dpnp.float64))
1✔
780
        cov_ = dpnp.get_dpnp_descriptor(dpnp.array(cov, dtype=dpnp.float64))
1✔
781
        if dpnp.is_cuda_backend(mean_.get_array()) or dpnp.is_cuda_backend(
1!
782
            cov_.get_array()
783
        ):
NEW
784
            raise NotImplementedError(
×
785
                "Running on CUDA is currently not supported"
786
            )
787

788
        if size is None:
1!
789
            shape = []
×
790
        elif isinstance(size, (int, dpnp.integer)):
1!
791
            shape = [size]
1✔
792
        else:
793
            shape = size
×
794
        if len(mean_.shape) != 1:
1✔
795
            pass
1✔
796
        elif (len(cov_.shape) != 2) or (cov_.shape[0] != cov_.shape[1]):
1!
797
            pass
1✔
798
        elif mean_.shape[0] != cov_.shape[0]:
×
799
            pass
×
800
        else:
801
            final_shape = list(shape[:])
×
802
            final_shape.append(mean_.shape[0])
×
803
            return dpnp_rng_multivariate_normal(
×
804
                mean_, cov_, final_shape
805
            ).get_pyobj()
806

807
    return call_origin(
1✔
808
        numpy.random.multivariate_normal, mean, cov, size, check_valid, tol
809
    )
810

811

812
def negative_binomial(n, p, size=None):
1✔
813
    """
814
    Draw samples from a negative binomial distribution.
815

816
    For full documentation refer to :obj:`numpy.random.negative_binomial`.
817

818
    Limitations
819
    -----------
820
    Parameters `n` and `p` are supported as scalar.
821
    Otherwise, :obj:`numpy.random.negative_binomial(n, p, size)` samples
822
    are drawn.
823
    Output array data type is :obj:`dpnp.int32`.
824

825
    Examples
826
    --------
827
    Draw samples from the distribution:
828
    A real world example. A company drills wild-cat oil
829
    exploration wells, each with an estimated probability of
830
    success of 0.1.  What is the probability of having one success
831
    for each successive well, that is what is the probability of a
832
    single success after drilling 5 wells, after 6 wells, etc.?
833

834
    >>> s = dpnp.random.negative_binomial(1, 0.1, 100000)
835
    >>> for i in range(1, 11):
836
    ...    probability = sum(s<i) / 100000.
837
    ...    print(i, "wells drilled, probability of one success =", probability)
838

839
    """
840

841
    if not use_origin_backend(n):
1!
842
        if dpnp.is_cuda_backend():
1!
NEW
843
            raise NotImplementedError(
×
844
                "Running on CUDA is currently not supported"
845
            )
846

847
        # TODO:
848
        # array_like of floats for `p` and `n` params
849
        if not dpnp.isscalar(n):
1✔
850
            pass
1✔
851
        elif not dpnp.isscalar(p):
1!
852
            pass
×
853
        elif p > 1 or p < 0:
1✔
854
            pass
1✔
855
        elif n <= 0:
1✔
856
            pass
1✔
857
        else:
858
            return dpnp_rng_negative_binomial(n, p, size).get_pyobj()
1✔
859

860
    return call_origin(numpy.random.negative_binomial, n, p, size)
1✔
861

862

863
def normal(
1✔
864
    loc=0.0,
865
    scale=1.0,
866
    size=None,
867
    device=None,
868
    usm_type="device",
869
    sycl_queue=None,
870
):
871
    """
872
    Draw random samples from a normal (Gaussian) distribution.
873

874
    For full documentation refer to :obj:`numpy.random.normal`.
875

876
    Parameters
877
    ----------
878
    device : {None, string, SyclDevice, SyclQueue}, optional
879
        An array API concept of device where the output array is created.
880
        The `device` can be ``None`` (the default), an OneAPI filter selector string,
881
        an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
882
        an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
883
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
884
    usm_type : {"device", "shared", "host"}, optional
885
        The type of SYCL USM allocation for the output array.
886
    sycl_queue : {None, SyclQueue}, optional
887
        A SYCL queue to use for output array allocation and copying. The
888
        `sycl_queue` can be passed as ``None`` (the default), which means
889
        to get the SYCL queue from `device` keyword if present or to use
890
        a default queue.
891
        Default: ``None``.
892

893
    Returns
894
    -------
895
    out : dpnp.ndarray
896
        Drawn samples from the parameterized normal distribution.
897
        Output array data type is the same as input `dtype`. If `dtype` is ``None`` (the default),
898
        :obj:`dpnp.float64` type will be used if device supports it, or :obj:`dpnp.float32` otherwise.
899

900
    Limitations
901
    -----------
902
    Parameters `loc` and `scale` are supported as scalar.
903
    Otherwise, :obj:`numpy.random.normal(loc, scale, size)` samples are drawn.
904
    Parameter `dtype` is supported only as :obj:`dpnp.float32`, :obj:`dpnp.float64` or ``None``.
905

906
    Examples
907
    --------
908
    Draw samples from the distribution:
909

910
    >>> mu, sigma = 0, 0.1 # mean and standard deviation
911
    >>> s = dpnp.random.normal(mu, sigma, 1000)
912

913
    """
914

915
    rs = _get_random_state(device=device, sycl_queue=sycl_queue)
1✔
916
    return rs.normal(
1✔
917
        loc=loc, scale=scale, size=size, dtype=None, usm_type=usm_type
918
    )
919

920

921
def noncentral_chisquare(df, nonc, size=None):
1✔
922
    """
923
    Draw samples from a non-central chi-square distribution.
924

925
    For full documentation refer to :obj:`numpy.random.noncentral_chisquare`.
926

927
    TODO
928

929
    """
930

931
    if not use_origin_backend(df):
1!
932
        if dpnp.is_cuda_backend():
1!
NEW
933
            raise NotImplementedError(
×
934
                "Running on CUDA is currently not supported"
935
            )
936

937
        # TODO:
938
        # array_like of floats for `mean` and `scale`
939
        if not dpnp.isscalar(df):
1✔
940
            pass
1✔
941
        elif not dpnp.isscalar(nonc):
1!
942
            pass
×
943
        elif df <= 0:
1✔
944
            pass
1✔
945
        elif nonc < 0:
1✔
946
            pass
1✔
947
        else:
948
            return dpnp_rng_noncentral_chisquare(df, nonc, size).get_pyobj()
1✔
949

950
    return call_origin(numpy.random.noncentral_chisquare, df, nonc, size)
1✔
951

952

953
def noncentral_f(dfnum, dfden, nonc, size=None):
1✔
954
    """
955
    Draw samples from the non-central F distribution.
956

957
    For full documentation refer to :obj:`numpy.random.noncentral_f`.
958

959
    Notes
960
    -----
961
    The function uses `numpy.random.noncentral_f` on the backend and
962
    will be executed on fallback backend.
963

964
    """
965

966
    return call_origin(numpy.random.noncentral_f, dfnum, dfden, nonc, size)
1✔
967

968

969
def pareto(a, size=None):
1✔
970
    """
971
    Draw samples from a Pareto II or Lomax distribution with specified shape.
972

973
    For full documentation refer to :obj:`numpy.random.pareto`.
974

975
    Limitations
976
    -----------
977
    Parameter `a` is supported as a scalar.
978
    Otherwise, :obj:`numpy.random.pareto(a, size)` samples are drawn.
979
    Output array data type is :obj:`dpnp.float64`.
980

981
    Examples
982
    --------
983
    Draw samples from the distribution:
984

985
    >>> a = .5  # alpha
986
    >>> s = dpnp.random.pareto(a, 1000)
987

988
    """
989

990
    if not use_origin_backend(a):
1!
991
        if dpnp.is_cuda_backend():
1!
NEW
992
            raise NotImplementedError(
×
993
                "Running on CUDA is currently not supported"
994
            )
995

996
        # TODO:
997
        # array_like of floats for `a`
998
        if not dpnp.isscalar(a):
1✔
999
            pass
1✔
1000
        elif a <= 0:
1✔
1001
            pass
1✔
1002
        else:
1003
            return dpnp_rng_pareto(a, size).get_pyobj()
1✔
1004

1005
    return call_origin(numpy.random.pareto, a, size)
1✔
1006

1007

1008
def permutation(x):
1✔
1009
    """
1010
    Randomly permute a sequence, or return a permuted range.
1011

1012
    For full documentation refer to :obj:`numpy.random.permutation`.
1013

1014
    Examples
1015
    --------
1016
    >>> arr = dpnp.random.permutation(10)
1017
    >>> print(arr)
1018
    [3 8 7 9 0 6 1 2 4 5] # random
1019

1020
    >>> arr = dpnp.random.permutation([1, 4, 9, 12, 15])
1021
    >>> print(arr)
1022
    [12  1  4  9 15] # random
1023

1024
    >>> arr = dpnp.arange(9).reshape((3, 3))
1025
    >>> dpnp.random.permutation(arr)
1026
    >>> print(arr)
1027
    [[0 1 2]
1028
     [3 4 5]
1029
     [6 7 8]]  # random
1030

1031
    """
1032
    if not use_origin_backend(x):
1!
1033
        if isinstance(x, (int, dpnp.integer)):
1✔
1034
            arr = dpnp.arange(x)
1✔
1035
        else:
1036
            arr = dpnp.array(x)
1✔
1037
        shuffle(arr)
1✔
1038
        return arr
1✔
1039

1040
    return call_origin(numpy.random.permutation, x)
×
1041

1042

1043
def poisson(lam=1.0, size=None):
1✔
1044
    """
1045
    Draw samples from a Poisson distribution.
1046

1047
    For full documentation refer to :obj:`numpy.random.poisson`.
1048

1049
    Limitations
1050
    -----------
1051
    Parameter `lam` is supported as a scalar.
1052
    Otherwise, :obj:`numpy.random.poisson(lam, size)` samples are drawn.
1053
    Output array data type is :obj:`dpnp.int32`.
1054

1055
    Examples
1056
    --------
1057
    Draw samples from the distribution:
1058

1059
    >>> import numpy as np
1060
    >>> s = dpnp.random.poisson(5, 10000)
1061

1062
    """
1063

1064
    if not use_origin_backend(lam):
1!
1065
        if dpnp.is_cuda_backend():
1!
NEW
1066
            raise NotImplementedError(
×
1067
                "Running on CUDA is currently not supported"
1068
            )
1069

1070
        # TODO:
1071
        # array_like of floats for `lam` param
1072
        if not dpnp.isscalar(lam):
1✔
1073
            pass
1✔
1074
        elif lam < 0:
1✔
1075
            pass
1✔
1076
        else:
1077
            return dpnp_rng_poisson(lam, size).get_pyobj()
1✔
1078

1079
    return call_origin(numpy.random.poisson, lam, size)
1✔
1080

1081

1082
def power(a, size=None):
1✔
1083
    """
1084
    Draws samples in [0, 1] from a power distribution with positive
1085
    exponent a - 1.
1086

1087
    For full documentation refer to :obj:`numpy.random.power`.
1088

1089
    Limitations
1090
    -----------
1091
    Parameter `a` is supported as a scalar.
1092
    Otherwise, :obj:`numpy.random.power(a, size)` samples are drawn.
1093
    Output array data type is :obj:`dpnp.float64`.
1094

1095
    Examples
1096
    --------
1097
    Draw samples from the distribution:
1098

1099
    >>> a = .5  # alpha
1100
    >>> s = dpnp.random.power(a, 1000)
1101

1102
    """
1103

1104
    if not use_origin_backend(a):
1!
1105
        if dpnp.is_cuda_backend():
1!
NEW
1106
            raise NotImplementedError(
×
1107
                "Running on CUDA is currently not supported"
1108
            )
1109

1110
        # TODO:
1111
        # array_like of floats for `a`
1112
        if not dpnp.isscalar(a):
1✔
1113
            pass
1✔
1114
        elif a <= 0:
1✔
1115
            pass
1✔
1116
        else:
1117
            return dpnp_rng_power(a, size).get_pyobj()
1✔
1118

1119
    return call_origin(numpy.random.power, a, size)
1✔
1120

1121

1122
def rand(*args, device=None, usm_type="device", sycl_queue=None):
1✔
1123
    """
1124
    Random values in a given shape.
1125

1126
    Create an array of the given shape and populate it with random samples from
1127
    a uniform distribution over ``[0, 1)``.
1128

1129
    For full documentation refer to :obj:`numpy.random.rand`.
1130

1131
    Parameters
1132
    ----------
1133
    *args : sequence of ints, optional
1134
        The dimensions of the returned array, must be non-negative.
1135
        If no argument is given a single Python float is returned.
1136
    device : {None, string, SyclDevice, SyclQueue}, optional
1137
        An array API concept of device where the output array is created.
1138
        The `device` can be ``None`` (the default), an OneAPI filter selector
1139
        string, an instance of :class:`dpctl.SyclDevice` corresponding to
1140
        a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`,
1141
        or a `Device` object returned by
1142
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1143
        Default: ``None``.
1144
    usm_type : {"device", "shared", "host"}, optional
1145
        The type of SYCL USM allocation for the output array.
1146
        Default: ``"device"``.
1147
    sycl_queue : {None, SyclQueue}, optional
1148
        A SYCL queue to use for output array allocation and copying. The
1149
        `sycl_queue` can be passed as ``None`` (the default), which means
1150
        to get the SYCL queue from `device` keyword if present or to use
1151
        a default queue.
1152
        Default: ``None``.
1153

1154
    Returns
1155
    -------
1156
    out : dpnp.ndarray
1157
        Random values in a given shape ``(d0, d1, ..., dn)``.
1158
        Output array data type is :obj:`dpnp.float64` if a device supports it,
1159
        or :obj:`dpnp.float32` type otherwise.
1160

1161
    See Also
1162
    --------
1163
    :obj:`dpnp.random.random` : Return random floats in the half-open interval
1164
                                ``[0.0, 1.0)``.
1165
    :obj:`dpnp.random.random_sample` : Return random floats in the half-open
1166
                                       interval ``[0.0, 1.0)``.
1167
    :obj:`dpnp.random.uniform` : Draw samples from a uniform distribution.
1168

1169
    Examples
1170
    --------
1171
    >>> import dpnp as np
1172
    >>> s = np.random.rand(3, 2)
1173

1174
    """
1175

1176
    rs = _get_random_state(device=device, sycl_queue=sycl_queue)
1✔
1177
    return rs.rand(*args, usm_type=usm_type)
1✔
1178

1179

1180
def randint(
1✔
1181
    low,
1182
    high=None,
1183
    size=None,
1184
    dtype=int,
1185
    device=None,
1186
    usm_type="device",
1187
    sycl_queue=None,
1188
):
1189
    """
1190
    Return random integers from `low` (inclusive) to `high` (exclusive).
1191

1192
    For full documentation refer to :obj:`numpy.random.randint`.
1193

1194
    Parameters
1195
    ----------
1196
    device : {None, string, SyclDevice, SyclQueue}, optional
1197
        An array API concept of device where the output array is created.
1198
        The `device` can be ``None`` (the default), an OneAPI filter selector string,
1199
        an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
1200
        an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
1201
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1202
    usm_type : {"device", "shared", "host"}, optional
1203
        The type of SYCL USM allocation for the output array.
1204
    sycl_queue : {None, SyclQueue}, optional
1205
        A SYCL queue to use for output array allocation and copying. The
1206
        `sycl_queue` can be passed as ``None`` (the default), which means
1207
        to get the SYCL queue from `device` keyword if present or to use
1208
        a default queue.
1209
        Default: ``None``.
1210

1211
    Returns
1212
    -------
1213
    out : dpnp.ndarray
1214
        `size`-shaped array of random integers from the appropriate distribution,
1215
        or a single such random int if `size` is not provided.
1216
        Output array data type is the same as input `dtype`.
1217

1218
    Limitations
1219
    -----------
1220
    Parameters `low` and `high` are supported only as a scalar.
1221
    Parameter `dtype` is supported only as :obj:`dpnp.int32` or ``int``,
1222
    but ``int`` value is considered to be exactly equivalent to :obj:`dpnp.int32`.
1223
    Otherwise, :obj:`numpy.random.RandomState.randint(low, high, size, dtype)` samples are drawn.
1224

1225
    Examples
1226
    --------
1227
    Draw samples from the distribution:
1228

1229
    >>> low, high = 3, 11 # low and high
1230
    >>> s = dpnp.random.randint(low, high, 1000, dtype=dpnp.int32)
1231

1232
    See Also
1233
    --------
1234
    :obj:`dpnp.random.random_integers` : similar to `randint`, only for the closed
1235
                                         interval [`low`, `high`], and 1 is the
1236
                                         lowest value if `high` is omitted.
1237

1238
    """
1239

1240
    rs = _get_random_state(device=device, sycl_queue=sycl_queue)
1✔
1241
    return rs.randint(
1✔
1242
        low=low, high=high, size=size, dtype=dtype, usm_type=usm_type
1243
    )
1244

1245

1246
def randn(d0, *dn, device=None, usm_type="device", sycl_queue=None):
1✔
1247
    """
1248
    Return a sample (or samples) from the "standard normal" distribution.
1249

1250
    For full documentation refer to :obj:`numpy.random.randn`.
1251

1252
    Parameters
1253
    ----------
1254
    device : {None, string, SyclDevice, SyclQueue}, optional
1255
        An array API concept of device where the output array is created.
1256
        The `device` can be ``None`` (the default), an OneAPI filter selector string,
1257
        an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
1258
        an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
1259
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1260
    usm_type : {"device", "shared", "host"}, optional
1261
        The type of SYCL USM allocation for the output array.
1262
    sycl_queue : {None, SyclQueue}, optional
1263
        A SYCL queue to use for output array allocation and copying. The
1264
        `sycl_queue` can be passed as ``None`` (the default), which means
1265
        to get the SYCL queue from `device` keyword if present or to use
1266
        a default queue.
1267
        Default: ``None``.
1268

1269
    Returns
1270
    -------
1271
    out : dpnp.ndarray
1272
        A ``(d0, d1, ..., dn)``-shaped array of floating-point samples from
1273
        the standard normal distribution, or a single such float if no parameters were supplied.
1274
        Output array data type is :obj:`dpnp.float64` if device supports it, or :obj:`dpnp.float32` otherwise.
1275

1276
    Examples
1277
    --------
1278
    >>> dpnp.random.randn()
1279
    2.1923875335537315  # random
1280

1281
    Two-by-four array of samples from N(3, 6.25):
1282

1283
    >>> s = 3 + 2.5 * dpnp.random.randn(2, 4)
1284

1285
    See Also
1286
    --------
1287
    :obj:`dpnp.random.standard_normal`
1288
    :obj:`dpnp.random.normal`
1289

1290
    """
1291

1292
    rs = _get_random_state(device=device, sycl_queue=sycl_queue)
1✔
1293
    return rs.randn(d0, *dn, usm_type=usm_type)
1✔
1294

1295

1296
def random(size=None, device=None, usm_type="device", sycl_queue=None):
1✔
1297
    """
1298
    Return random floats in the half-open interval [0.0, 1.0).
1299

1300
    Alias for random_sample.
1301

1302
    For full documentation refer to :obj:`numpy.random.random`.
1303

1304
    Parameters
1305
    ----------
1306
    device : {None, string, SyclDevice, SyclQueue}, optional
1307
        An array API concept of device where the output array is created.
1308
        The `device` can be ``None`` (the default), an OneAPI filter selector string,
1309
        an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
1310
        an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
1311
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1312
    usm_type : {"device", "shared", "host"}, optional
1313
        The type of SYCL USM allocation for the output array.
1314
    sycl_queue : {None, SyclQueue}, optional
1315
        A SYCL queue to use for output array allocation and copying. The
1316
        `sycl_queue` can be passed as ``None`` (the default), which means
1317
        to get the SYCL queue from `device` keyword if present or to use
1318
        a default queue.
1319
        Default: ``None``.
1320

1321
    Returns
1322
    -------
1323
    out : dpnp.ndarray
1324
        Array of random floats of shape `size` (if ``size=None``, zero dimension array with a single float is returned).
1325
        Output array data type is :obj:`dpnp.float64` if device supports it, or :obj:`dpnp.float32` otherwise.
1326

1327
    Examples
1328
    --------
1329
    >>> s = dpnp.random.random(1000)
1330

1331
    See Also
1332
    --------
1333
    :obj:`dpnp.random.rand`
1334
    :obj:`dpnp.random.random_sample`
1335
    :obj:`dpnp.random.uniform`
1336

1337
    """
1338

1339
    return random_sample(
1✔
1340
        size=size, device=device, usm_type=usm_type, sycl_queue=sycl_queue
1341
    )
1342

1343

1344
def random_integers(
1✔
1345
    low, high=None, size=None, device=None, usm_type="device", sycl_queue=None
1346
):
1347
    """
1348
    Random integers between `low` and `high`, inclusive.
1349

1350
    For full documentation refer to :obj:`numpy.random.random_integers`.
1351

1352
    Parameters
1353
    ----------
1354
    device : {None, string, SyclDevice, SyclQueue}, optional
1355
        An array API concept of device where the output array is created.
1356
        The `device` can be ``None`` (the default), an OneAPI filter selector string,
1357
        an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
1358
        an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
1359
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1360
    usm_type : {"device", "shared", "host"}, optional
1361
        The type of SYCL USM allocation for the output array.
1362
    sycl_queue : {None, SyclQueue}, optional
1363
        A SYCL queue to use for output array allocation and copying. The
1364
        `sycl_queue` can be passed as ``None`` (the default), which means
1365
        to get the SYCL queue from `device` keyword if present or to use
1366
        a default queue.
1367
        Default: ``None``.
1368

1369
    Returns
1370
    -------
1371
    out : dpnp.ndarray
1372
        `size`-shaped array of random integers from the appropriate distribution,
1373
        or a single such random int if `size` is not provided.
1374

1375
    Limitations
1376
    -----------
1377
    Parameters `low` and `high` are supported as scalar.
1378
    Otherwise, :obj:`numpy.random.random_integers(low, high, size)` samples are drawn.
1379

1380
    See Also
1381
    --------
1382
    :obj:`dpnp.random.randint`
1383

1384
    """
1385

1386
    if high is None:
1✔
1387
        high = low
1✔
1388
        low = 0
1✔
1389

1390
    # TODO:
1391
    # array_like of floats for `low` and `high` params
1392
    if not dpnp.isscalar(low):
1!
1393
        pass
×
1394
    elif not dpnp.isscalar(high):
1!
1395
        pass
×
1396
    else:
1397
        return randint(
1✔
1398
            low,
1399
            int(high) + 1,
1400
            size=size,
1401
            device=device,
1402
            usm_type=usm_type,
1403
            sycl_queue=sycl_queue,
1404
        )
1405

1406
    return call_origin(numpy.random.random_integers, low, high, size)
×
1407

1408

1409
def random_sample(size=None, device=None, usm_type="device", sycl_queue=None):
1✔
1410
    """
1411
    Return random floats in the half-open interval [0.0, 1.0).
1412

1413
    Results are from the “continuous uniform” distribution over the interval.
1414

1415
    For full documentation refer to :obj:`numpy.random.random_sample`.
1416

1417
    Parameters
1418
    ----------
1419
    device : {None, string, SyclDevice, SyclQueue}, optional
1420
        An array API concept of device where the output array is created.
1421
        The `device` can be ``None`` (the default), an OneAPI filter selector string,
1422
        an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
1423
        an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
1424
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1425
    usm_type : {"device", "shared", "host"}, optional
1426
        The type of SYCL USM allocation for the output array.
1427
    sycl_queue : {None, SyclQueue}, optional
1428
        A SYCL queue to use for output array allocation and copying. The
1429
        `sycl_queue` can be passed as ``None`` (the default), which means
1430
        to get the SYCL queue from `device` keyword if present or to use
1431
        a default queue.
1432
        Default: ``None``.
1433

1434
    Returns
1435
    -------
1436
    out : dpnp.ndarray
1437
        Array of random floats of shape `size` (if ``size=None``, zero dimension array with a single float is returned).
1438
        Output array data type is :obj:`dpnp.float64` if device supports it, or :obj:`dpnp.float32` otherwise.
1439

1440
    Examples
1441
    --------
1442
    >>> s = dpnp.random.random_sample((5,))
1443

1444
    See Also
1445
    --------
1446
    :obj:`dpnp.random.rand`
1447
    :obj:`dpnp.random.random`
1448
    :obj:`dpnp.random.uniform`
1449

1450
    """
1451

1452
    rs = _get_random_state(device=device, sycl_queue=sycl_queue)
1✔
1453
    return rs.random_sample(size=size, usm_type=usm_type)
1✔
1454

1455

1456
def ranf(size=None, device=None, usm_type="device", sycl_queue=None):
1✔
1457
    """
1458
    Return random floats in the half-open interval [0.0, 1.0).
1459

1460
    This is an alias of random_sample.
1461

1462
    For full documentation refer to :obj:`numpy.random.ranf`.
1463

1464
    Parameters
1465
    ----------
1466
    device : {None, string, SyclDevice, SyclQueue}, optional
1467
        An array API concept of device where the output array is created.
1468
        The `device` can be ``None`` (the default), an OneAPI filter selector string,
1469
        an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
1470
        an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
1471
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1472
    usm_type : {"device", "shared", "host"}, optional
1473
        The type of SYCL USM allocation for the output array.
1474
    sycl_queue : {None, SyclQueue}, optional
1475
        A SYCL queue to use for output array allocation and copying. The
1476
        `sycl_queue` can be passed as ``None`` (the default), which means
1477
        to get the SYCL queue from `device` keyword if present or to use
1478
        a default queue.
1479
        Default: ``None``.
1480

1481
    Returns
1482
    -------
1483
    out : dpnp.ndarray
1484
        Array of random floats of shape `size` (if ``size=None``, zero dimension array with a single float is returned).
1485
        Output array data type is :obj:`dpnp.float64` if device supports it, or :obj:`dpnp.float32` otherwise.
1486

1487
    Examples
1488
    --------
1489
    >>> s = dpnp.random.ranf(1000)
1490

1491
    See Also
1492
    --------
1493
    :obj:`dpnp.random.rand`
1494
    :obj:`dpnp.random.random`
1495
    :obj:`dpnp.random.random_sample`
1496
    :obj:`dpnp.random.uniform`
1497

1498
    """
1499

1500
    return random_sample(
1✔
1501
        size=size, device=device, usm_type=usm_type, sycl_queue=sycl_queue
1502
    )
1503

1504

1505
def rayleigh(scale=1.0, size=None):
1✔
1506
    """
1507
    Draw samples from a Rayleigh distribution.
1508

1509
    For full documentation refer to :obj:`numpy.random.rayleigh`.
1510

1511
    Limitations
1512
    -----------
1513
    Parameter `scale` is supported as a scalar.
1514
    Otherwise, :obj:`numpy.random.rayleigh(scale, size)` samples are drawn.
1515
    Output array data type is :obj:`dpnp.float64`.
1516

1517
    Examples
1518
    --------
1519
    Draw samples from the distribution:
1520

1521
    >>> import numpy as np
1522
    >>> s = dpnp.random.rayleigh(1.0, 10000)
1523

1524
    """
1525

1526
    if not use_origin_backend(scale):
1!
1527
        if dpnp.is_cuda_backend():
1!
NEW
1528
            raise NotImplementedError(
×
1529
                "Running on CUDA is currently not supported"
1530
            )
1531

1532
        # TODO:
1533
        # array_like of floats for `scale` params
1534
        if not dpnp.isscalar(scale):
1✔
1535
            pass
1✔
1536
        elif scale < 0:
1✔
1537
            pass
1✔
1538
        else:
1539
            return dpnp_rng_rayleigh(scale, size).get_pyobj()
1✔
1540

1541
    return call_origin(numpy.random.rayleigh, scale, size)
1✔
1542

1543

1544
def sample(size=None, device=None, usm_type="device", sycl_queue=None):
1✔
1545
    """
1546
    Return random floats in the half-open interval [0.0, 1.0).
1547

1548
    This is an alias of random_sample.
1549

1550
    For full documentation refer to :obj:`numpy.random.sample`.
1551

1552
    Parameters
1553
    ----------
1554
    device : {None, string, SyclDevice, SyclQueue}, optional
1555
        An array API concept of device where the output array is created.
1556
        The `device` can be ``None`` (the default), an OneAPI filter selector string,
1557
        an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
1558
        an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
1559
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1560
    usm_type : {"device", "shared", "host"}, optional
1561
        The type of SYCL USM allocation for the output array.
1562
    sycl_queue : {None, SyclQueue}, optional
1563
        A SYCL queue to use for output array allocation and copying. The
1564
        `sycl_queue` can be passed as ``None`` (the default), which means
1565
        to get the SYCL queue from `device` keyword if present or to use
1566
        a default queue.
1567
        Default: ``None``.
1568

1569
    Returns
1570
    -------
1571
    out : dpnp.ndarray
1572
        Array of random floats of shape `size` (if ``size=None``, zero dimension array with a single float is returned).
1573
        Output array data type is :obj:`dpnp.float64` if device supports it, or :obj:`dpnp.float32` otherwise.
1574

1575
    Examples
1576
    --------
1577
    >>> s = dpnp.random.sample(1000)
1578

1579
    See Also
1580
    --------
1581
    :obj:`dpnp.random.rand`
1582
    :obj:`dpnp.random.random`
1583
    :obj:`dpnp.random.random_sample`
1584
    :obj:`dpnp.random.uniform`
1585

1586
    """
1587

1588
    return random_sample(
1✔
1589
        size=size, device=device, usm_type=usm_type, sycl_queue=sycl_queue
1590
    )
1591

1592

1593
def shuffle(x1):
1✔
1594
    """
1595
    Modify a sequence in-place by shuffling its contents.
1596

1597
    For full documentation refer to :obj:`numpy.random.shuffle`.
1598

1599
    Limitations
1600
    -----------
1601
    Otherwise, the function will use :obj:`numpy.random.shuffle` on the backend
1602
    and will be executed on fallback backend.
1603

1604
    """
1605

1606
    x1_desc = dpnp.get_dpnp_descriptor(x1, copy_when_strides=False)
1✔
1607
    if x1_desc:
1✔
1608

1609
        if dpnp.is_cuda_backend(x1_desc.get_array()):
1!
NEW
1610
            raise NotImplementedError(
×
1611
                "Running on CUDA is currently not supported"
1612
            )
1613

1614
        if not dpnp.is_type_supported(x1_desc.dtype):
1!
1615
            pass
×
1616
        else:
1617
            dpnp_rng_shuffle(x1_desc).get_pyobj()
1✔
1618
            return
1✔
1619

1620
    call_origin(numpy.random.shuffle, x1, dpnp_inplace=True)
1✔
1621
    return
1✔
1622

1623

1624
def seed(seed=None, device=None, sycl_queue=None):
1✔
1625
    """
1626
    Reseed a legacy MT19937 random number generator engine.
1627

1628
    Parameters
1629
    ----------
1630
    device : {None, string, SyclDevice, SyclQueue}, optional
1631
        An array API concept of device where an array with generated numbers
1632
        will be created. The `device` can be ``None`` (the default), an OneAPI
1633
        filter selector string, an instance of :class:`dpctl.SyclDevice`
1634
        corresponding to a non-partitioned SYCL device, an instance of
1635
        :class:`dpctl.SyclQueue`, or a `Device` object returned by
1636
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1637
    sycl_queue : {None, SyclQueue}, optional
1638
        A SYCL queue to use for an array with generated numbers.
1639

1640
    Limitations
1641
    -----------
1642
    The `seed` parameter is supported as a scalar or an array of at most three
1643
    integer scalars.
1644

1645
    """
1646

1647
    # update a mt19937 random number for both RandomState and legacy functionality
1648
    global _dpnp_random_states
1649

1650
    sycl_queue = dpnp.get_normalized_queue_device(
1✔
1651
        device=device, sycl_queue=sycl_queue
1652
    )
1653
    _dpnp_random_states[sycl_queue] = RandomState(
1✔
1654
        seed=seed, sycl_queue=sycl_queue
1655
    )
1656

1657
    if not use_origin_backend(seed):
1!
1658
        if dpnp.is_cuda_backend():
1!
NEW
1659
            raise NotImplementedError(
×
1660
                "Running on CUDA is currently not supported"
1661
            )
1662

1663
        # TODO:
1664
        # array_like of ints for `seed`
1665
        if seed is None:
1!
1666
            seed = 1
×
1667
        if not isinstance(seed, int):
1!
1668
            pass
×
1669
        elif seed < 0:
1!
1670
            pass
×
1671
        else:
1672
            # TODO:
1673
            # migrate to a single approach with RandomState class
1674
            dpnp_rng_srand(seed)
1✔
1675

1676
    # always reseed numpy engine also
1677
    return call_origin(numpy.random.seed, seed, allow_fallback=True)
1✔
1678

1679

1680
def standard_cauchy(size=None):
1✔
1681
    """
1682
    Draw samples from a standard Cauchy distribution with mode = 0.
1683

1684
    Also known as the Lorentz distribution.
1685

1686
    Limitations
1687
    -----------
1688
    Output array data type is default float type.
1689

1690
    Examples
1691
    --------
1692
    Draw samples and plot the distribution:
1693

1694
    >>> import matplotlib.pyplot as plt
1695
    >>> s = dpnp.random.standard_cauchy(1000000)
1696
    >>> s = s[(s>-25) & (s<25)]  # truncate distribution so it plots well
1697
    >>> plt.hist(s, bins=100)
1698
    >>> plt.show()
1699

1700
    """
1701

1702
    if not use_origin_backend(size):
1!
1703
        if dpnp.is_cuda_backend():
1!
NEW
1704
            raise NotImplementedError(
×
1705
                "Running on CUDA is currently not supported"
1706
            )
1707
        return dpnp_rng_standard_cauchy(size).get_pyobj()
1✔
1708

1709
    return call_origin(numpy.random.standard_cauchy, size)
×
1710

1711

1712
def standard_exponential(size=None):
1✔
1713
    """
1714
    Draw samples from the standard exponential distribution.
1715

1716
    `standard_exponential` is identical to the exponential distribution
1717
    with a scale parameter of 1.
1718

1719
    Limitations
1720
    -----------
1721
    Output array data type is default float type.
1722

1723
    Examples
1724
    --------
1725
    Output a 3x8000 array:
1726

1727
    >>> n = dpnp.random.standard_exponential((3, 8000))
1728

1729
    """
1730

1731
    if not use_origin_backend(size):
1!
1732
        if dpnp.is_cuda_backend():
1!
NEW
1733
            raise NotImplementedError(
×
1734
                "Running on CUDA is currently not supported"
1735
            )
1736
        return dpnp_rng_standard_exponential(size).get_pyobj()
1✔
1737

1738
    return call_origin(numpy.random.standard_exponential, size)
×
1739

1740

1741
def standard_gamma(shape, size=None):
1✔
1742
    """
1743
    Draw samples from a standard Gamma distribution.
1744

1745
    For full documentation refer to :obj:`numpy.random.standard_gamma`.
1746

1747
    Limitations
1748
    -----------
1749
    Parameter `shape` is supported as a scalar.
1750
    Otherwise, :obj:`numpy.random.standard_gamma(shape, size)` samples
1751
    are drawn.
1752
    Output array data type is :obj:`dpnp.float64`.
1753

1754
    Examples
1755
    --------
1756
    Draw samples from the distribution:
1757

1758
    >>> shape = 2.
1759
    >>> s = dpnp.random.standard_gamma(shape, 1000000)
1760

1761
    """
1762

1763
    if not use_origin_backend(shape):
1!
1764
        if dpnp.is_cuda_backend():
1!
NEW
1765
            raise NotImplementedError(
×
1766
                "Running on CUDA is currently not supported"
1767
            )
1768

1769
        # TODO:
1770
        # array_like of floats for `shape`
1771
        if not dpnp.isscalar(shape):
1✔
1772
            pass
1✔
1773
        elif shape < 0:
1✔
1774
            pass
1✔
1775
        else:
1776
            return dpnp_rng_standard_gamma(shape, size).get_pyobj()
1✔
1777

1778
    return call_origin(numpy.random.standard_gamma, shape, size)
1✔
1779

1780

1781
def standard_normal(size=None, device=None, usm_type="device", sycl_queue=None):
1✔
1782
    """
1783
    Draw samples from a standard Normal distribution ``(mean=0, stdev=1)``.
1784

1785
    For full documentation refer to :obj:`numpy.random.standard_normal`.
1786

1787
    Parameters
1788
    ----------
1789
    device : {None, string, SyclDevice, SyclQueue}, optional
1790
        An array API concept of device where the output array is created.
1791
        The `device` can be ``None`` (the default), an OneAPI filter selector string,
1792
        an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
1793
        an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
1794
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1795
    usm_type : {"device", "shared", "host"}, optional
1796
        The type of SYCL USM allocation for the output array.
1797
    sycl_queue : {None, SyclQueue}, optional
1798
        A SYCL queue to use for output array allocation and copying. The
1799
        `sycl_queue` can be passed as ``None`` (the default), which means
1800
        to get the SYCL queue from `device` keyword if present or to use
1801
        a default queue.
1802
        Default: ``None``.
1803

1804
    Returns
1805
    -------
1806
    out : dpnp.ndarray
1807
        A floating-point array of shape `size` of drawn samples, or a
1808
        single sample if `size` was not specified.
1809
        Output array data type is :obj:`dpnp.float64` if device supports it, or :obj:`dpnp.float32` otherwise.
1810

1811
    Examples
1812
    --------
1813
    Draw samples from the distribution:
1814

1815
    >>> s = dpnp.random.standard_normal(1000)
1816

1817
    """
1818

1819
    rs = _get_random_state(device=device, sycl_queue=sycl_queue)
1✔
1820
    return rs.standard_normal(size=size, usm_type=usm_type)
1✔
1821

1822

1823
def standard_t(df, size=None):
1✔
1824
    """
1825
    Draw samples from a standard Student’s t distribution with
1826
    `df` degrees of freedom.
1827

1828
    For full documentation refer to :obj:`numpy.random.standard_t`.
1829

1830
    Limitations
1831
    -----------
1832
    Parameter `df` is supported as a scalar.
1833
    Otherwise, :obj:`numpy.random.standard_t(df, size)` samples
1834
    are drawn.
1835
    Output array data type is :obj:`dpnp.float64`.
1836

1837
    Examples
1838
    --------
1839
    Draw samples from the distribution:
1840

1841
    >>> df = 2.
1842
    >>> s = dpnp.random.standard_t(df, 1000000)
1843

1844
    """
1845

1846
    if not use_origin_backend(df):
1!
1847
        if dpnp.is_cuda_backend():
1!
NEW
1848
            raise NotImplementedError(
×
1849
                "Running on CUDA is currently not supported"
1850
            )
1851

1852
        # TODO:
1853
        # array_like of floats for `df`
1854
        if not dpnp.isscalar(df):
1✔
1855
            pass
1✔
1856
        elif df <= 0:
1✔
1857
            pass
1✔
1858
        else:
1859
            return dpnp_rng_standard_t(df, size).get_pyobj()
1✔
1860

1861
    return call_origin(numpy.random.standard_t, df, size)
1✔
1862

1863

1864
def triangular(left, mode, right, size=None):
1✔
1865
    """
1866
    Draw samples from the triangular distribution over the interval
1867
    [left, right].
1868

1869
    For full documentation refer to :obj:`numpy.random.triangular`.
1870

1871
    Limitations
1872
    -----------
1873
    Parameters `left`, `mode` and `right` are supported as scalar.
1874
    Otherwise, :obj:`numpy.random.triangular(left, mode, right, size)`
1875
    samples are drawn.
1876
    Output array data type is :obj:`dpnp.float64`.
1877

1878
    Examples
1879
    --------
1880
    Draw samples from the distribution:
1881

1882
    >>> df = 2.
1883
    >>> s = dpnp.random.triangular(-3, 0, 8, 1000000)
1884

1885
    """
1886

1887
    if not use_origin_backend(left):
1!
1888
        if dpnp.is_cuda_backend():
1!
NEW
1889
            raise NotImplementedError(
×
1890
                "Running on CUDA is currently not supported"
1891
            )
1892

1893
        # TODO:
1894
        # array_like of floats for `left`, `mode`, `right`.
1895
        if not dpnp.isscalar(left):
1✔
1896
            pass
1✔
1897
        elif not dpnp.isscalar(mode):
1!
1898
            pass
×
1899
        elif not dpnp.isscalar(right):
1!
1900
            pass
×
1901
        elif left > mode:
1✔
1902
            pass
1✔
1903
        elif mode > right:
1✔
1904
            pass
1✔
1905
        elif left == right:
1!
1906
            pass
×
1907
        else:
1908
            return dpnp_rng_triangular(left, mode, right, size).get_pyobj()
1✔
1909

1910
    return call_origin(numpy.random.triangular, left, mode, right, size)
1✔
1911

1912

1913
def uniform(
1✔
1914
    low=0.0,
1915
    high=1.0,
1916
    size=None,
1917
    device=None,
1918
    usm_type="device",
1919
    sycl_queue=None,
1920
):
1921
    """
1922
    Draw samples from a uniform distribution.
1923

1924
    Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high).
1925
    In other words, any value within the given interval is equally likely to be drawn by uniform.
1926

1927
    For full documentation refer to :obj:`numpy.random.uniform`.
1928

1929
    Parameters
1930
    ----------
1931
    device : {None, string, SyclDevice, SyclQueue}, optional
1932
        An array API concept of device where the output array is created.
1933
        The `device` can be ``None`` (the default), an OneAPI filter selector string,
1934
        an instance of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL device,
1935
        an instance of :class:`dpctl.SyclQueue`, or a `Device` object returned by
1936
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
1937
    usm_type : {"device", "shared", "host"}, optional
1938
        The type of SYCL USM allocation for the output array.
1939
    sycl_queue : {None, SyclQueue}, optional
1940
        A SYCL queue to use for output array allocation and copying. The
1941
        `sycl_queue` can be passed as ``None`` (the default), which means
1942
        to get the SYCL queue from `device` keyword if present or to use
1943
        a default queue.
1944
        Default: ``None``.
1945

1946
    Returns
1947
    -------
1948
    out : dpnp.ndarray
1949
        Drawn samples from the parameterized uniform distribution.
1950
        Output array data type is the same as input `dtype`. If `dtype` is ``None`` (the default),
1951
        :obj:`dpnp.float64` type will be used if device supports it, or :obj:`dpnp.float32` otherwise.
1952

1953
    Limitations
1954
    -----------
1955
    Parameters `low` and `high` are supported as a scalar. Otherwise,
1956
    :obj:`numpy.random.uniform(low, high, size)` samples are drawn.
1957
    Parameter `dtype` is supported only as :obj:`dpnp.int32`, :obj:`dpnp.float32`, :obj:`dpnp.float64` or ``None``.
1958

1959
    Examples
1960
    --------
1961
    Draw samples from the distribution:
1962

1963
    >>> low, high = 0, 0.1 # low and high
1964
    >>> s = dpnp.random.uniform(low, high, 10000)
1965

1966
    See Also
1967
    --------
1968
    :obj:`dpnp.random.random` : Floats uniformly distributed over ``[0, 1)``.
1969

1970
    """
1971

1972
    rs = _get_random_state(device=device, sycl_queue=sycl_queue)
1✔
1973
    return rs.uniform(
1✔
1974
        low=low, high=high, size=size, dtype=None, usm_type=usm_type
1975
    )
1976

1977

1978
def vonmises(mu, kappa, size=None):
1✔
1979
    """
1980
    Draw samples from a von Mises distribution.
1981

1982
    For full documentation refer to :obj:`numpy.random.vonmises`.
1983

1984
    Limitations
1985
    -----------
1986
    Parameters `mu` and `kappa` are supported as scalar.
1987
    Otherwise, :obj:`numpy.random.vonmises(mu, kappa, size)`
1988
    samples are drawn.
1989
    Output array data type is :obj:`dpnp.float64`.
1990

1991
    Examples
1992
    --------
1993
    Draw samples from the distribution:
1994

1995
    >>> mu, kappa = 0.0, 4.0 # mean and dispersion
1996
    >>> s = dpnp.random.vonmises(mu, kappa, 1000)
1997

1998
    """
1999

2000
    if not use_origin_backend(mu):
1!
2001
        if dpnp.is_cuda_backend():
1!
NEW
2002
            raise NotImplementedError(
×
2003
                "Running on CUDA is currently not supported"
2004
            )
2005

2006
        # TODO:
2007
        # array_like of floats for `mu`, `kappa`.
2008
        if not dpnp.isscalar(mu):
1✔
2009
            pass
1✔
2010
        elif not dpnp.isscalar(kappa):
1!
2011
            pass
×
2012
        elif numpy.isnan(kappa):
1!
2013
            return dpnp.nan
×
2014
        elif kappa < 0:
1✔
2015
            pass
1✔
2016
        else:
2017
            return dpnp_rng_vonmises(mu, kappa, size).get_pyobj()
1✔
2018

2019
    return call_origin(numpy.random.vonmises, mu, kappa, size)
1✔
2020

2021

2022
def wald(mean, scale, size=None):
1✔
2023
    """
2024
    Draw samples from a Wald, or inverse Gaussian, distribution.
2025

2026
    For full documentation refer to :obj:`numpy.random.wald`.
2027

2028
    Limitations
2029
    -----------
2030
    Parameters `mean` and `scale` are supported as scalar.
2031
    Otherwise, :obj:`numpy.random.wald(mean, scale, size)` samples are drawn.
2032
    Output array data type is :obj:`dpnp.float64`.
2033

2034
    Examples
2035
    --------
2036
    >>> loc, scale = 3., 2.
2037
    >>> s = dpnp.random.wald(loc, scale, 1000)
2038

2039
    """
2040

2041
    if not use_origin_backend(mean):
1!
2042
        if dpnp.is_cuda_backend():
1!
NEW
2043
            raise NotImplementedError(
×
2044
                "Running on CUDA is currently not supported"
2045
            )
2046

2047
        # TODO:
2048
        # array_like of floats for `mean` and `scale`
2049
        if not dpnp.isscalar(mean):
1✔
2050
            pass
1✔
2051
        elif not dpnp.isscalar(scale):
1!
2052
            pass
×
2053
        elif mean <= 0:
1✔
2054
            pass
1✔
2055
        elif scale <= 0:
1✔
2056
            pass
1✔
2057
        else:
2058
            return dpnp_rng_wald(mean, scale, size).get_pyobj()
1✔
2059

2060
    return call_origin(numpy.random.wald, mean, scale, size)
1✔
2061

2062

2063
def weibull(a, size=None):
1✔
2064
    """
2065
    Draw samples from a Weibull distribution.
2066

2067
    For full documentation refer to :obj:`numpy.random.weibull`.
2068

2069
    Limitations
2070
    -----------
2071
    Parameter `a` is supported as a scalar.
2072
    Otherwise, :obj:`numpy.random.weibull(a, size)` samples are drawn.
2073
    Output array data type is :obj:`dpnp.float64`.
2074

2075
    Examples
2076
    --------
2077
    >>> a = 5. # shape
2078
    >>> s = np.random.weibull(a, 1000)
2079

2080
    """
2081

2082
    if not use_origin_backend(a):
1!
2083
        if dpnp.is_cuda_backend():
1!
NEW
2084
            raise NotImplementedError(
×
2085
                "Running on CUDA is currently not supported"
2086
            )
2087

2088
        # TODO:
2089
        # array_like of floats for `a` param
2090
        if not dpnp.isscalar(a):
1✔
2091
            pass
1✔
2092
        elif a < 0:
1✔
2093
            pass
1✔
2094
        else:
2095
            return dpnp_rng_weibull(a, size).get_pyobj()
1✔
2096

2097
    return call_origin(numpy.random.weibull, a, size)
1✔
2098

2099

2100
def zipf(a, size=None):
1✔
2101
    """
2102
    Returns an array of samples drawn from the Zipf distribution.
2103

2104
    For full documentation refer to :obj:`numpy.random.zipf`.
2105

2106
    Limitations
2107
    -----------
2108
    Parameter `a`` is supported as a scalar.
2109
    Otherwise, :obj:`numpy.zipf.weibull(a, size)` samples are drawn.
2110
    Output array data type is :obj:`dpnp.float64`.
2111

2112
    Examples
2113
    --------
2114
    >>> a = 2. # parameter
2115
    >>> s = np.random.zipf(a, 1000)
2116

2117
    """
2118

2119
    if not use_origin_backend(a):
1!
2120
        if dpnp.is_cuda_backend():
1!
NEW
2121
            raise NotImplementedError(
×
2122
                "Running on CUDA is currently not supported"
2123
            )
2124

2125
        # TODO:
2126
        # array_like of floats for `a` param
2127
        if not dpnp.isscalar(a):
1✔
2128
            pass
1✔
2129
        elif a <= 1:
1✔
2130
            pass
1✔
2131
        else:
2132
            return dpnp_rng_zipf(a, size).get_pyobj()
1✔
2133

2134
    return call_origin(numpy.random.zipf, a, size)
1✔
2135

2136

2137
_dpnp_random_states = {}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc