Skip to content

Add discrete distributions to dpnp.random.Generator - #3159

Open
ndgrigorian wants to merge 10 commits into
feature/device-rng-continuousfrom
feature/device-rng-discrete
Open

ndgrigorian wants to merge 10 commits into
feature/device-rng-continuousfrom
feature/device-rng-discrete

Conversation

@ndgrigorian

@ndgrigorian ndgrigorian commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

This PR adds integers and the discrete distributions to dpnp.random.Generator, as part of the series splitting #3147. It is stacked on #3158

Adds

  • integers, using NumPy's bounded integer algorithm (Lemire's method)
  • poisson, binomial (inversion and BTPE), negative_binomial, geometric, logseries, zipf and hypergeometric (HRUA)
  • 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. 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 one log1p so that they don't cancel. zipf uses expm1/log1p, deliberately departing from NumPy, whose tail for a close to 1 is too heavy above 2**53 (documented in random.rst)

As in #3158, every rejection sampler returns the smallest int64 for device parameters that would make it loop forever

Also adds umul_hi, which replaces sycl::mul_hi; DPC++ 2026.2 miscompiles sycl::mul_hi on Intel GPUs when one operand is a compile-time constant

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3159/index.html

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.22.0dev2=np2py314h8d9cdd5_34 ran successfully.
Passed: 1491
Failed: 0
Skipped: 6

@coveralls

coveralls commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

Coverage is 84.705% — feature/device-rng-discrete into feature/device-rng-continuous. No base build found for feature/device-rng-continuous.

@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-continuous branch from adf7178 to cfa00bd Compare November 6, 2026 17:55
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-discrete branch 2 times, most recently from 6388643 to f48c80e Compare November 8, 2026 21:54
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-continuous branch from df5cb09 to 7c8127b Compare November 8, 2026 21:54
Comment thread dpnp/tests/test_random_generator.py Resolved
Comment thread dpnp/random/_generator.py Resolved
Comment thread dpnp/random/_generator.py Resolved
Comment thread dpnp/random/_generator.py Resolved
Comment thread dpnp/random/_generator.py Resolved
Comment on lines +36 to +38
// sycl::mul_hi is not used: optimized DPC++ 2026.2 builds get it wrong on
// Intel GPUs when one 64-bit operand is a compile-time constant (all results
// wrong at -O2, right at -O0). oneMKL's device RNG uses 32-bit halves too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This works around a DPC++ bug, and AGENTS.md asks for the full issue URL in such a comment, so it can be reverted later. Is there an intel/llvm issue for the sycl::mul_hi miscompile? The new line in dpnp/libtensor/AGENTS.md could link it too.

Comment thread dpnp/tests/test_random_generator.py Resolved
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-discrete branch from f48c80e to dcabbc2 Compare November 13, 2026 20:06
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-continuous branch from 7c8127b to 9ed9f9a Compare November 13, 2026 20:06
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.
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-discrete branch from dcabbc2 to bb4b69b Compare November 13, 2026 22:41

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants