Description
I tried the recently merged random_choice
#391 and found the following:
-
This doesn't work with Numba v.0.36 with the following error:
TypeError: Failed at nopython (inline calls to locally defined closures) sequence item 0: expected str instance, NoneType found
It works with Numba v.0.37, so this should be a bug in Numba v.0.36. The problem for us is that the latest Anaconda contains Numba v.0.36.2.
-
Setting a seed with
np.random.seed
within a library (hidden from the user) is problematic: it seems to affect Numba's global random state.Suppose you have the following jit function:
@numba.jit(nopython=True) def my_rand(size): return np.random.uniform(0, 1, size)
Call it after calling
random_choice
with the same seed (with Numba v.0.37):qe.random_choice(np.array([0.1, 0.9]), seed=0) my_rand(5)
Then it always returns the same sequence:
array([0.71518937, 0.60276338, 0.54488318, 0.4236548 , 0.64589411])
@jstac What is your use case where you need a jitted version of this functionality? What's wrong with generating random numbers outside your jit function and then using np.searchsorted
(or qe.searchsorted
) inside the jit function?