• 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

85.19
/dpnp/random/dpnp_random_state.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 RandomState
30

31
Set of functions to implement NumPy random module API
32

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

35
"""
36

37

38
import dpctl.utils as dpu
1✔
39
import numpy
1✔
40

41
import dpnp
1✔
42
from dpnp.dpnp_utils.dpnp_algo_utils import (
1✔
43
    call_origin,
44
    map_dtype_to_device,
45
    use_origin_backend,
46
)
47
from dpnp.random.dpnp_algo_random import MCG59, MT19937
1✔
48

49
__all__ = ["RandomState"]
1✔
50

51

52
class RandomState:
1✔
53
    """
54
    A container for the Mersenne Twister pseudo-random number generator.
55

56
    For full documentation refer to :obj:`numpy.random.RandomState`.
57

58
    Parameters
59
    ----------
60
    seed : {None, int, array_like}, optional
61
        A random seed to initialize the pseudo-random number generator.
62
        The `seed` can be ``None`` (the default), an integer scalar, or
63
        an array of at most three integer scalars.
64
    device : {None, string, SyclDevice, SyclQueue}, optional
65
        An array API concept of device where the output array is created.
66
        The `device` can be ``None`` (the default), an OneAPI filter selector
67
        string, an instance of :class:`dpctl.SyclDevice` corresponding to
68
        a non-partitioned SYCL device, an instance of :class:`dpctl.SyclQueue`,
69
        or a `Device` object returned by
70
        :obj:`dpnp.dpnp_array.dpnp_array.device` property.
71
    sycl_queue : {None, SyclQueue}, optional
72
        A SYCL queue to use for output array allocation and copying. The
73
        `sycl_queue` can be passed as ``None`` (the default), which means
74
        to get the SYCL queue from `device` keyword if present or to use
75
        a default queue.
76
        Default: ``None``.
77

78
    """
79

80
    def __init__(self, seed=None, device=None, sycl_queue=None):
1✔
81
        self._sycl_queue = dpnp.get_normalized_queue_device(
1✔
82
            device=device, sycl_queue=sycl_queue
83
        )
84

85
        self._sycl_device = self._sycl_queue.sycl_device
1✔
86

87
        is_cpu = self._sycl_device.is_cpu
1✔
88
        if seed is None:
1✔
89
            low = 0
1✔
90
            high = dpnp.iinfo(numpy.int32).max + 1
1✔
91

92
            if is_cpu:
1!
93
                # ask NumPy to generate an array of three random integers as default seed value
94
                self._seed = numpy.random.randint(low=low, high=high, size=3)
1✔
95
            else:
96
                # ask NumPy to generate a random 32-bit integer as default seed value
97
                self._seed = numpy.random.randint(low=low, high=high, size=1)[0]
×
98
        else:
99
            self._seed = seed
1✔
100

101
        # 'float32' is default floating data type if device doesn't support 'float64'
102
        self._def_float_type = map_dtype_to_device(
1✔
103
            dpnp.float64, self._sycl_device
104
        )
105

106
        # TODO: rework through pybind11 extension for OneMKL engine and distribution classes
107
        if is_cpu:
1!
108
            self._random_state = MT19937(self._seed, self._sycl_queue)
1✔
109
        else:
110
            # MCG59 is assumed to provide a better performance on GPU than MT19937
111
            self._random_state = MCG59(self._seed, self._sycl_queue)
×
112
        self._fallback_random_state = call_origin(
1✔
113
            numpy.random.RandomState, seed, allow_fallback=True
114
        )
115

116
    def __repr__(self):
1✔
117
        return self.__str__() + " at 0x{:X}".format(id(self))
×
118

119
    def __str__(self):
1✔
120
        _str = self.__class__.__name__
×
121
        _str += "(" + self._random_state.__class__.__name__ + ")"
×
122
        return _str
×
123

124
    def __getstate__(self):
1✔
125
        return self.get_state()
×
126

127
    def _is_finite_scalar(self, x):
1✔
128
        """Test a scalar for finiteness (not infinity and not Not a Number)."""
129

130
        # TODO: replace with dpnp.isfinite() once function is available in DPNP,
131
        # but for now use direct numpy calls without call_origin() wrapper, since data is a scalar
132
        return numpy.isfinite(x)
1✔
133

134
    def _is_signbit_scalar(self, x):
1✔
135
        """Test a scalar if sign bit is set for it (less than zero)."""
136

137
        # TODO: replace with dpnp.signbit() once function is available in DPNP,
138
        # but for now use direct numpy calls without call_origin() wrapper, since data is a scalar
139
        return numpy.signbit(x)
1✔
140

141
    def _validate_float_dtype(self, dtype, supported_types):
1✔
142
        """
143
        Validate an input floating type.
144

145
        Test an input floating type if it is listed in `supported_types` and
146
        if it is supported by the used SYCL device.
147
        If `dtype` is ``None``, default floating type will be validating.
148
        Return the examined floating type if it follows all validation checks.
149
        """
150

151
        if dtype is None:
1✔
152
            dtype = self._def_float_type
1✔
153

154
        if dtype not in supported_types:
1✔
155
            raise TypeError(f"dtype={dtype} is unsupported.")
1✔
156
        elif dtype != map_dtype_to_device(dtype, self._sycl_device):
1!
157
            raise RuntimeError(
×
158
                f"dtype={dtype} is not supported by SYCL device '{self._sycl_device}'"
159
            )
160
        return dtype
1✔
161

162
    def get_state(self):
1✔
163
        """
164
        Return an internal state of the generator.
165

166
        For full documentation refer to :obj:`numpy.random.RandomState.get_state`.
167

168
        Returns
169
        -------
170
        out : object
171
            An object representing the internal state of the generator.
172
        """
173
        return self._random_state
×
174

175
    def get_sycl_queue(self):
1✔
176
        """
177
        Return an instance of :class:`dpctl.SyclQueue` used within the generator for data allocation.
178

179
        Returns
180
        -------
181
        queue : dpctl.SyclQueue
182
            A SYCL queue used for data allocation.
183
        """
184
        return self._sycl_queue
1✔
185

186
    def get_sycl_device(self):
1✔
187
        """
188
        Return an instance of :class:`dpctl.SyclDevice` used within the generator to allocate data on.
189

190
        Returns
191
        -------
192
        device : dpctl.SyclDevice
193
            A SYCL device used to allocate data on.
194
        """
195
        return self._sycl_device
×
196

197
    def normal(
1✔
198
        self, loc=0.0, scale=1.0, size=None, dtype=None, usm_type="device"
199
    ):
200
        """
201
        Draw random samples from a normal (Gaussian) distribution.
202

203
        For full documentation refer to :obj:`numpy.random.RandomState.normal`.
204

205
        Parameters
206
        ----------
207
        usm_type : {"device", "shared", "host"}, optional
208
            The type of SYCL USM allocation for the output array.
209

210
        Returns
211
        -------
212
        out : dpnp.ndarray
213
            Drawn samples from the parameterized normal distribution.
214
            Output array data type is the same as input `dtype`. If `dtype` is ``None`` (the default),
215
            :obj:`dpnp.float64` type will be used if device supports it, or :obj:`dpnp.float32` otherwise.
216

217
        Limitations
218
        -----------
219
        Parameters `loc` and `scale` are supported as a scalar. Otherwise,
220
        :obj:`numpy.random.RandomState.normal(loc, scale, size)` samples are drawn.
221
        Parameter `dtype` is supported only as :obj:`dpnp.float32`, :obj:`dpnp.float64` or ``None``.
222

223
        Examples
224
        --------
225
        >>> s = dpnp.random.RandomState().normal(loc=3.7, scale=2.5, size=(2, 4))
226
        >>> print(s)
227
        [[ 1.58997253 -0.84288406  2.33836967  4.16394577]
228
         [ 4.40882036  5.39295758  6.48927254  6.74921661]]
229

230
        See Also
231
        --------
232
        :obj:`dpnp.random.RandomState.randn`
233
        :obj:`dpnp.random.RandomState.standard_normal`
234

235
        """
236

237
        if not use_origin_backend():
1!
238
            if dpnp.is_cuda_backend():
1!
NEW
239
                raise NotImplementedError(
×
240
                    "Running on CUDA is currently not supported"
241
                )
242

243
            if not dpnp.isscalar(loc):
1✔
244
                pass
1✔
245
            elif not dpnp.isscalar(scale):
1!
246
                pass
×
247
            else:
248
                dtype = self._validate_float_dtype(
1✔
249
                    dtype, (dpnp.float32, dpnp.float64)
250
                )
251
                min_floating = dpnp.finfo(dtype).min
1✔
252
                max_floating = dpnp.finfo(dtype).max
1✔
253

254
                if (
1✔
255
                    loc >= max_floating or loc <= min_floating
256
                ) and self._is_finite_scalar(loc):
257
                    raise OverflowError(
1✔
258
                        f"Range of loc={loc} exceeds valid bounds"
259
                    )
260

261
                if (scale >= max_floating) and self._is_finite_scalar(scale):
1✔
262
                    raise OverflowError(
1✔
263
                        f"Range of scale={scale} exceeds valid bounds"
264
                    )
265
                # scale = -0.0 is cosidered as negative
266
                elif scale < 0 or scale == 0 and self._is_signbit_scalar(scale):
1✔
267
                    raise ValueError(
1✔
268
                        f"scale={scale}, but must be non-negative."
269
                    )
270

271
                dpu.validate_usm_type(usm_type, allow_none=False)
1✔
272
                return self._random_state.normal(
1✔
273
                    loc=loc,
274
                    scale=scale,
275
                    size=size,
276
                    dtype=dtype,
277
                    usm_type=usm_type,
278
                ).get_pyobj()
279

280
        return call_origin(
1✔
281
            self._fallback_random_state.normal,
282
            loc=loc,
283
            scale=scale,
284
            size=size,
285
            sycl_queue=self._sycl_queue,
286
        )
287

288
    def rand(self, *args, usm_type="device"):
1✔
289
        """
290
        Draw random values in a given shape.
291

292
        Create an array of the given shape and populate it with random samples
293
        from a uniform distribution over [0, 1).
294

295
        For full documentation refer to :obj:`numpy.random.RandomState.rand`.
296

297
        Parameters
298
        ----------
299
        usm_type : {"device", "shared", "host"}, optional
300
            The type of SYCL USM allocation for the output array.
301

302
        Returns
303
        -------
304
        out : dpnp.ndarray
305
            Random values in a given shape.
306
            Output array data type is :obj:`dpnp.float64` if device supports it, or :obj:`dpnp.float32` otherwise.
307

308
        Examples
309
        --------
310
        >>> s = dpnp.random.RandomState().rand(5, 2)
311
        >>> print(s)
312
        [[0.13436424 0.56920387]
313
         [0.84743374 0.80226506]
314
         [0.76377462 0.06310682]
315
         [0.25506903 0.1179187 ]
316
         [0.49543509 0.76096244]]
317

318
        See Also
319
        --------
320
        :obj:`dpnp.random.RandomState.random_sample`
321
        :obj:`dpnp.random.RandomState.uniform`
322

323
        """
324

325
        if len(args) == 0:
1✔
326
            return self.random_sample(usm_type=usm_type)
1✔
327
        else:
328
            return self.random_sample(size=args, usm_type=usm_type)
1✔
329

330
    def randint(self, low, high=None, size=None, dtype=int, usm_type="device"):
1✔
331
        """
332
        Draw random integers from `low` (inclusive) to `high` (exclusive).
333

334
        Return random integers from the “discrete uniform” distribution of the specified type
335
        in the “half-open” interval [low, high).
336

337
        For full documentation refer to :obj:`numpy.random.RandomState.randint`.
338

339
        Parameters
340
        ----------
341
        usm_type : {"device", "shared", "host"}, optional
342
            The type of SYCL USM allocation for the output array.
343

344
        Returns
345
        -------
346
        out : dpnp.ndarray
347
            `size`-shaped array of random integers from the appropriate distribution,
348
            or a single such random int if `size` is not provided.
349
            Output array data type is the same as input `dtype`.
350

351
        Limitations
352
        -----------
353
        Parameters `low` and `high` are supported only as a scalar.
354
        Parameter `dtype` is supported only as :obj:`dpnp.int32` or ``int``,
355
        but ``int`` value is considered to be exactly equivalent to :obj:`dpnp.int32`.
356
        Otherwise, :obj:`numpy.random.RandomState.randint(low, high, size, dtype)` samples are drawn.
357

358
        Examples
359
        --------
360
        >>> s = dpnp.random.RandomState().randint(2, size=10)
361
        >>> print(s)
362
        [0 1 1 1 1 0 0 0 0 1]
363

364
        See Also
365
        --------
366
        :obj:`dpnp.random.RandomState.random_integers` : similar to `randint`, only for the closed
367
            interval [`low`, `high`], and 1 is the lowest value if `high` is omitted.
368

369
        """
370

371
        if not use_origin_backend(low):
1!
372
            if dpnp.is_cuda_backend():
1!
NEW
373
                raise NotImplementedError(
×
374
                    "Running on CUDA is currently not supported"
375
                )
376

377
            if not dpnp.isscalar(low):
1✔
378
                pass
1✔
379
            elif not (high is None or dpnp.isscalar(high)):
1!
380
                pass
×
381
            else:
382
                _dtype = dpnp.int32 if dtype is int else dpnp.dtype(dtype)
1✔
383
                if _dtype != dpnp.int32:
1✔
384
                    pass
1✔
385
                else:
386
                    if high is None:
1✔
387
                        high = low
1✔
388
                        low = 0
1✔
389

390
                    min_int = dpnp.iinfo("int32").min
1✔
391
                    max_int = dpnp.iinfo("int32").max
1✔
392

393
                    if (
1✔
394
                        not self._is_finite_scalar(low)
395
                        or low > max_int
396
                        or low < min_int
397
                    ):
398
                        raise OverflowError(
1✔
399
                            f"Range of low={low} exceeds valid bounds"
400
                        )
401
                    elif (
1✔
402
                        not self._is_finite_scalar(high)
403
                        or high > max_int
404
                        or high < min_int
405
                    ):
406
                        raise OverflowError(
1✔
407
                            f"Range of high={high} exceeds valid bounds"
408
                        )
409

410
                    low = int(low)
1✔
411
                    high = int(high)
1✔
412
                    if low >= high:
1✔
413
                        raise ValueError(f"low={low} >= high={high}")
1✔
414

415
                    return self.uniform(
1✔
416
                        low=low,
417
                        high=high,
418
                        size=size,
419
                        dtype=_dtype,
420
                        usm_type=usm_type,
421
                    )
422

423
        return call_origin(
1✔
424
            self._fallback_random_state.randint,
425
            low=low,
426
            high=high,
427
            size=size,
428
            dtype=dtype,
429
            sycl_queue=self._sycl_queue,
430
        )
431

432
    def randn(self, *args, usm_type="device"):
1✔
433
        """
434
        Return a sample (or samples) from the "standard normal" distribution.
435

436
        For full documentation refer to :obj:`numpy.random.RandomState.randn`.
437

438
        Parameters
439
        ----------
440
        usm_type : {"device", "shared", "host"}, optional
441
            The type of SYCL USM allocation for the output array.
442

443
        Returns
444
        -------
445
        out : dpnp.ndarray
446
            A ``(d0, d1, ..., dn)``-shaped array of floating-point samples from
447
            the standard normal distribution, or a single such float if
448
            no parameters were supplied.
449
            Output array data type is :obj:`dpnp.float64` if device supports it,
450
            or :obj:`dpnp.float32` otherwise.
451

452
        Examples
453
        --------
454
        >>> s = dpnp.random.RandomState().randn()
455
        >>> print(s)
456
        -0.84401099
457

458
        Two-by-four array of samples from the normal distribution with
459
        mean 3 and standard deviation 2.5:
460

461
        >>> s = dpnp.random.RandomState().randn(2, 4)
462
        >>> print(s)
463
        [[ 0.88997253 -1.54288406  1.63836967  3.46394577]
464
         [ 3.70882036  4.69295758  5.78927254  6.04921661]]
465

466
        See Also
467
        --------
468
        :obj:`dpnp.random.normal`
469
        :obj:`dpnp.random.standard_normal`
470

471
        """
472

473
        if len(args) == 0:
1✔
474
            return self.standard_normal(usm_type=usm_type)
1✔
475
        return self.standard_normal(size=args, usm_type=usm_type)
1✔
476

477
    def random_sample(self, size=None, usm_type="device"):
1✔
478
        """
479
        Draw random floats in the half-open interval [0.0, 1.0).
480

481
        Results are from the “continuous uniform” distribution over the interval.
482

483
        For full documentation refer to :obj:`numpy.random.RandomState.random_sample`.
484

485
        Parameters
486
        ----------
487
        usm_type : {"device", "shared", "host"}, optional
488
            The type of SYCL USM allocation for the output array.
489

490
        Returns
491
        -------
492
        out : dpnp.ndarray
493
            Array of random floats of shape `size` (if ``size=None``,
494
            zero dimension array with a single float is returned).
495
            Output array data type is :obj:`dpnp.float64` if device supports it,
496
            or :obj:`dpnp.float32` otherwise.
497

498
        Examples
499
        --------
500
        >>> s = dpnp.random.RandomState().random_sample(size=(4,))
501
        >>> print(s)
502
        [0.13436424 0.56920387 0.84743374 0.80226506]
503

504
        See Also
505
        --------
506
        :obj:`dpnp.random.RandomState.rand`
507
        :obj:`dpnp.random.RandomState.uniform`
508

509
        """
510

511
        return self.uniform(
1✔
512
            low=0.0, high=1.0, size=size, dtype=None, usm_type=usm_type
513
        )
514

515
    def standard_normal(self, size=None, usm_type="device"):
1✔
516
        """
517
        Draw samples from a standard Normal distribution ``(mean=0, stdev=1)``.
518

519
        For full documentation refer to :obj:`numpy.random.RandomState.standard_normal`.
520

521
        Parameters
522
        ----------
523
        usm_type : {"device", "shared", "host"}, optional
524
            The type of SYCL USM allocation for the output array.
525

526
        Returns
527
        -------
528
        out : dpnp.ndarray
529
            A floating-point array of shape `size` of drawn samples, or a
530
            single sample if `size` was not specified.
531
            Output array data type is :obj:`dpnp.float64` if device supports it,
532
            or :obj:`dpnp.float32` otherwise.
533

534
        Examples
535
        --------
536
        >>> s = dpnp.random.RandomState().standard_normal(size=(3, 5))
537
        >>> print(s)
538
        [[-0.84401099 -1.81715362 -0.54465213  0.18557831  0.28352814]
539
         [ 0.67718303  1.11570901  1.21968665 -1.18236388  0.08156915]
540
         [ 0.21941987 -1.24544512  0.63522211 -0.673174    0.        ]]
541

542
        See Also
543
        --------
544
        :obj:`dpnp.random.RandomState.normal`
545
        :obj:`dpnp.random.RandomState.randn`
546

547
        """
548

549
        return self.normal(
1✔
550
            loc=0.0, scale=1.0, size=size, dtype=None, usm_type=usm_type
551
        )
552

553
    def uniform(
1✔
554
        self, low=0.0, high=1.0, size=None, dtype=None, usm_type="device"
555
    ):
556
        """
557
        Draw samples from a uniform distribution.
558

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

562
        For full documentation refer to :obj:`numpy.random.RandomState.uniform`.
563

564
        Parameters
565
        ----------
566
        usm_type : {"device", "shared", "host"}, optional
567
            The type of SYCL USM allocation for the output array.
568

569
        Returns
570
        -------
571
        out : dpnp.ndarray
572
            Drawn samples from the parameterized uniform distribution.
573
            Output array data type is the same as input `dtype`. If `dtype` is ``None`` (the default),
574
            :obj:`dpnp.float64` type will be used if device supports it, or :obj:`dpnp.float32` otherwise.
575

576
        Limitations
577
        -----------
578
        Parameters `low` and `high` are supported as a scalar. Otherwise,
579
        :obj:`numpy.random.RandomState.uniform(low, high, size)` samples are drawn.
580
        Parameter `dtype` is supported only as :obj:`dpnp.int32`, :obj:`dpnp.float32`, :obj:`dpnp.float64` or ``None``.
581

582
        Examples
583
        --------
584
        >>> low, high = 1.23, 10.54    # low and high
585
        >>> s = dpnp.random.RandomState().uniform(low, high, 5)
586
        >>> print(s)
587
        [2.48093112 6.52928804 9.1196081  8.6990877  8.34074171]
588

589
        See Also
590
        --------
591
        :obj:`dpnp.random.RandomState.randint` : Discrete uniform distribution, yielding integers.
592
        :obj:`dpnp.random.RandomState.random_integers` : Discrete uniform distribution over the closed interval ``[low, high]``.
593
        :obj:`dpnp.random.RandomState.random_sample` : Floats uniformly distributed over ``[0, 1)``.
594
        :obj:`dpnp.random.RandomState.random` : Alias for :obj:`dpnp.random.RandomState.random_sample`.
595
        :obj:`dpnp.random.RandomState.rand` : Convenience function that accepts dimensions as input, e.g.,
596
            ``rand(2, 2)`` would generate a 2-by-2 array of floats, uniformly distributed over ``[0, 1)``.
597

598
        """
599

600
        if not use_origin_backend():
1!
601
            if dpnp.is_cuda_backend():
1!
NEW
602
                raise NotImplementedError(
×
603
                    "Running on CUDA is currently not supported"
604
                )
605

606
            if not dpnp.isscalar(low):
1✔
607
                pass
1✔
608
            elif not dpnp.isscalar(high):
1!
609
                pass
×
610
            else:
611
                min_double = dpnp.finfo("double").min
1✔
612
                max_double = dpnp.finfo("double").max
1✔
613

614
                if (
1✔
615
                    not self._is_finite_scalar(low)
616
                    or low >= max_double
617
                    or low <= min_double
618
                ):
619
                    raise OverflowError(
1✔
620
                        f"Range of low={low} exceeds valid bounds"
621
                    )
622
                elif (
1✔
623
                    not self._is_finite_scalar(high)
624
                    or high >= max_double
625
                    or high <= min_double
626
                ):
627
                    raise OverflowError(
1✔
628
                        f"Range of high={high} exceeds valid bounds"
629
                    )
630

631
                if low > high:
1✔
632
                    low, high = high, low
1✔
633

634
                dtype = self._validate_float_dtype(
1✔
635
                    dtype, (dpnp.int32, dpnp.float32, dpnp.float64)
636
                )
637
                dpu.validate_usm_type(usm_type, allow_none=False)
1✔
638

639
                return self._random_state.uniform(
1✔
640
                    low=low,
641
                    high=high,
642
                    size=size,
643
                    dtype=dtype,
644
                    usm_type=usm_type,
645
                ).get_pyobj()
646

647
        return call_origin(
1✔
648
            self._fallback_random_state.uniform,
649
            low=low,
650
            high=high,
651
            size=size,
652
            sycl_queue=self._sycl_queue,
653
        )
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