Repository navigation
Add discrete distributions to dpnp.random.Generator - #3159
ndgrigorian wants to merge 12 commits into
Conversation
9fa550e to
bb0eae2
Compare
0160558 to
adf7178
Compare
bb0eae2 to
7918e32
Compare
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/3159/index.html |
|
Array API standard conformance tests for dpnp=0.22.0dev2=np2py314h8d9cdd5_38 ran successfully. |
adf7178 to
cfa00bd
Compare
6388643 to
f48c80e
Compare
df5cb09 to
7c8127b
Compare
f48c80e to
dcabbc2
Compare
7c8127b to
9ed9f9a
Compare
dcabbc2 to
bb4b69b
Compare
Add integers and the poisson, binomial, negative_binomial, geometric, logseries, zipf and hypergeometric samplers, along with noncentral_chisquare and noncentral_f, which need poisson. The discrete samplers return int64 and compute in double precision, or in single precision on devices without fp64, where host parameters are clipped to stay inside their domain once rounded.
Also move test_usm_type_follows_bounds and test_device_integer_param_dtype into their classes: indented into a fixture and a helper, pytest never collected them.
NumPy skips the bound checks only when size is given; an empty broadcast with size=None still raises for out-of-range bounds.
f4938e0 to
a64886a
Compare
78535ba to
6317de6
Compare
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
I tested the new changes here on GPU and CPU, on an Alder Lake iGPU without fp64, on Windows (Arc B390) and on free-threaded Python 3.14t: everything from the previous round is fixed, and the samples are the same on all devices. One small comment below that I missed earlier.
| if numpy.ndim(x) > 0: | ||
| return numpy.asarray(x).astype(_int64) | ||
| return int(x) |
There was a problem hiding this comment.
An integer parameter of 2**63 or more gives a raw pybind11 error for a scalar and n < 0 for a list, where NumPy raises OverflowError:
import numpy, dpnp
for n in (2**63, [2**63]):
for xp in (numpy, dpnp):
try:
xp.random.default_rng(0).binomial(n, 0.5)
except Exception as e:
print(xp.__name__, n, type(e).__name__)
# numpy 9223372036854775808 OverflowError
# dpnp 9223372036854775808 RuntimeError
# numpy [9223372036854775808] OverflowError
# dpnp [9223372036854775808] ValueErrornumpy.asarray(x, dtype=numpy.int64) in the last two branches gives NumPy's errors, also for [nan].
This PR adds
integersand the discrete distributions todpnp.random.Generator, as part of the series splitting #3147. It is stacked on #3158Adds
integers, using NumPy's bounded integer algorithm (Lemire's method)poisson,binomial(inversion and BTPE),negative_binomial,geometric,logseries,zipfandhypergeometric(HRUA)noncentral_chisquareandnoncentral_f, which needpoissonThe discrete samplers return
int64and compute in double precision, or in single precision on devices without fp64. In single precision, host parameters are clipped so that they stay inside the domain once rounded, and the large log-factorial terms of BTPE and HRUA are gathered into onelog1pso that they don't cancel.zipfusesexpm1/log1p, deliberately departing from NumPy, whose tail foraclose to 1 is too heavy above2**53(documented inrandom.rst)As in #3158, every rejection sampler returns the smallest
int64for device parameters that would make it loop foreverAlso adds
umul_hi, which replacessycl::mul_hi; DPC++ 2026.2 miscompilessycl::mul_hion Intel GPUs when one operand is a compile-time constant