-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforce integer sampling from multinomial #1399
Comments
|
Good catch. I only see the issue when calling from Python. I have not tried calling from Cython. In my testing, the |
That explains it. I'm trying to properly install Numpy 1.26.1, which in turn requires building a fresh pyenv with updated Numba and llvmlite and maybe Aesara and scipy??? These things have inadequate release notes and installation docs. (How to use Apple's Accelerate library now? Install with Numpy updates often require client code changes (e.g. Many of these changes can't be found by static analysis, so we should at least be alert to fix deprecation warnings. (The Jenkins builds now show warnings.) |
Per #1399, In Numpy 1.26, `RandomState.multinomial()` rejects float value n. There could be more such API changes. I'm asking if this is a bug and if it's a side effect of NumPy bindings moving from the Cython project to the NumPy project or by semantic changes in Cython 3.0.
I think the cause of this API change was a changed definition of
|
The numpy bug is tagged for the 1.26.2 release milestone. If they fix it by the time we're ready for a new NumPy release, we won't need the |
Thanks for linking the bug report you made! I find this kind of low-level stuff pretty fascinating. I cloned the Numpy repo and edited |
I think I've teased out all the details here. As noted by the Cython maintainer, Interestingly, commenting out the Conversely, defining a parameter as This all aligns with what you said about Python only enforcing integer types for indices, exactly what the Looking at the current Numpy codebase, I can see that this issue only affects the legacy |
NumPy 1.26.2 has @thalassemia's bug fix and the broader fix for I'll test it soon. |
When
numpy.random.RandomState.multinomial
is called in an environment withCython<3.0.0
(currently, we use0.29.34
), it accepts non-integern
values with no problem (source code for reference). However, something changes inCython>=3.0.0
which causes themultinomial
function to raise an error whenn
is not an integer. In our model, this happens in at least four places: here, here, here, and here. The solution on our end is probably just to cast each of ourn
arguments toint
once we upgrade Cython.Digging deeper into the issue, I noticed that the
TypeError
for floating point values is only raised when a Cython function has a parameter of the typenp.npy_intp
. If the parameter has any other integer type (e.g.int
,long
,np.npy_int
), it is simply cast toint
with no errors raised.Does anyone know if this issue is platform-specific (I tested on Ubuntu 22.04 x86) or intended behavior?
The text was updated successfully, but these errors were encountered: