Skip to content

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

Open
ndgrigorian wants to merge 1 commit into
feature/device-rng-continuousfrom
feature/device-rng-discrete
Open

ndgrigorian wants to merge 1 commit 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?

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.
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-continuous branch from 0160558 to adf7178 Compare November 4, 2026 19:50
@ndgrigorian
ndgrigorian force-pushed the feature/device-rng-discrete branch from bb0eae2 to 7918e32 Compare November 4, 2026 19:50
@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.0dev0=np2py314h8d9cdd5_29 ran successfully.
Passed: 1491
Failed: 0
Skipped: 6

@coveralls

coveralls commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

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

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.

2 participants