Skip to content

BUGs in random_choice #393

Closed
Closed
@oyamad

Description

@oyamad

I tried the recently merged random_choice #391 and found the following:

  1. 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.

  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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions