Skip to content

Avoid numpy array resize refcheck in svmlight format #31435

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

Merged
merged 2 commits into from
Jul 7, 2025

Conversation

msimacek
Copy link
Contributor

numpy.ndarray.resize does a reference check that there is only one reference to the array and so the resizing is safe. In this specific piece of code, the array has just been created and there is obviously only one reference. But this reference check doesn't work on PyPy and GraalPy, because they don't do reference counting the same way as CPython. I know that neither are officially supported, but they tend to mostly work and turning the check off could help those that want to try them.

Copy link

github-actions bot commented May 27, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: e26bf58. Link to the linter CI: here

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @msimacek.

I'm not very familiar with this part of the code but a quick look showed that query is create as an array with a single value and never used/modified before this resize. So I think it's harmless to just allocate a new array, see my suggestion below. It should be safe for all python implementations, no ?

Co-authored-by: Jérémie du Boisberranger <jeremie@probabl.ai>
@msimacek
Copy link
Contributor Author

msimacek commented Jul 3, 2025

Yes, that seems even better, thanks. Should I squash the commits?

@msimacek msimacek changed the title Disable numpy array resize refcheck in svmlight format Avoid numpy array resize refcheck in svmlight format Jul 3, 2025
Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @msimacek

@jeremiedbb
Copy link
Member

Should I squash the commits?

no need, we do that when merging the PR

@jeremiedbb jeremiedbb merged commit 961afc7 into scikit-learn:main Jul 7, 2025
35 checks passed
@jeremiedbb jeremiedbb mentioned this pull request Jul 15, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants