Skip to content
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

BUG: Make n a long int for np.random.multinomial #25090

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

thalassemia
Copy link
Contributor

Fixes #25061.

@1fish2
Copy link
Contributor

1fish2 commented Nov 8, 2023

Should the Python Interface file mtrand.pyi also declare multinomial's n argument long?

It's currently typed _ArrayLikeInt_co which seems way off.

@seberg
Copy link
Member

seberg commented Nov 8, 2023

It is of course not safe to change this to long, this was a correct bug fix for windows and huge arrays.

@thalassemia
Copy link
Contributor Author

The other changes to npy_intp I agree with and understand. Changing the type of n to npy_intp is, as far as I can tell, unnecessary and moot because it is subsequently assigned to a long later on in the function and not directly used again.

@seberg
Copy link
Member

seberg commented Nov 9, 2023

ops, sorry, you are right, somehow I thought it was used for a size. So we can do that, still wondering a bit about the other changes away from long (and presumably more in _generator.pyx) which changed if the cython version is important.

@seberg
Copy link
Member

seberg commented Nov 9, 2023

Thanks, this doesn't fix the underlying issue, but it seems fine and rejects very large values that don't fit long but do fit intp, which is potentially a bit safer on windows. Small enough fix even for the legacy random, I would say.

@seberg seberg merged commit fcbf56d into numpy:main Nov 9, 2023
61 checks passed
@charris charris added the 09 - Backport-Candidate PRs tagged should be backported label Nov 9, 2023
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: np.random.multinomial(<float>, ...) raises a TypeError in numpy 1.26
4 participants