Support array_like low/high bounds for randint - #168
Conversation
|
@vlad-perevezentsev |
|
@vlad-perevezentsev |
|
@vlad-perevezentsev |
|
|
||
| while (len > 0) { | ||
| MKL_INT c = (len > MKL_INT_MAX) ? (MKL_INT)MKL_INT_MAX : (MKL_INT)len; | ||
| err = viRngUniformBits32(VSL_RNG_METHOD_UNIFORMBITS32_STD, |
There was a problem hiding this comment.
it seems this and viRngUniformBits64 are not supported by WH, MCG31, R250, and MRG32K3A BRNGs.
This may be why array-like was not supported previously
There was a problem hiding this comment.
It returns -1014, which is VSL_RNG_ERROR_BRNG_NOT_SUPPORTED. When it happens, we see a hang.
Claude suggested:
Fix needs two parts. (a) irk_uniform_bits_vec must return the status instead of asserting, and the caller must handle it — at minimum a bounded retry count so a failed fill can never spin. (b) A real word source for these BRNGs. The existing scalar code already has the pattern at mkl_distributions.cpp:1992 — viRngUniform(VSL_RNG_METHOD_UNIFORM_STD, ..., (int *)res, lo - shift, hi - shift + 1) then shift back — so falling back to viRngUniform into the words buffer on VSL_RNG_ERROR_BRNG_NOT_SUPPORTED would be consistent with the file. Note that viRngUniform's int range can't express all 2³² values, so the fallback needs care to stay unbiased. Separately, randint(0, 2**32, dtype=np.uint32) on the scalar path is already silently broken for these same four BRNGs ([3160423200, 31294, 3160423200, 31294, ...]) — pre-existing, untouched by this branch, but the same root cause and probably worth a companion issue.
This PR adds
array_likelow/high support torandintto align withnumpy.random.RandomState.randintIt adds new C routines
irk_rand_<type>_broadcastfor all 9 integer dtypes, drawing per-element integers over [low, high) withLemire's multiply-shift(the same method as NumPy).An earlier
masked-rejectionversion benchmarked slower so it was replaced.A
mulhihelper returns the high half of the product becauseLemirecomputesword × rangewhich overflows the type so the 64-bit case uses a 32-bit schoolbook multiply.It also groups all
randinttests intoTestRandint classand adds new ones.