-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
[WIP] FIX index overflow error in sparse matrix polynomial expansion (bis) #19676
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a92b8a7
[MRG] FIX index overflow error in sparse matrix polynomial expansion
jianlingzhong c60a3e9
Take over #16831
wdevazelhes b78f40d
Do some first castings to int64 to avoid overflow in expanded_dimensi…
wdevazelhes ed6a5b5
merge with master
wdevazelhes 3f3db6a
Add test
wdevazelhes d5364ce
cast the input dim to int64 outside cython (didn't manage to make it …
wdevazelhes d90233b
cast also expanded indices and indptr
wdevazelhes fe39a7b
cast to int64 using numpy
wdevazelhes 90e12b8
refactor code and factors out the int64 casting
wdevazelhes e5daef8
remove unnecessary changes
wdevazelhes 7138cf4
Update sklearn/preprocessing/_polynomial.py
wdevazelhes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two copies being created here, one from
X.copy
and here when changing the dtype of the indices. I do not see a good alternative. I would expect the following to work:but internally
csr_matrix
checks the indices and will cast back down tonp.int32
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, your solution sounds good
I'm not completely sure to understand the problem with it: is it because when creating a
csr_matrix
with indices that could hold inint32
, scipy automatically chosesint32
indices ?In this case maybe I could avoid copying
X
, but deal with every part of it (data, indices, inptr) separately, like:X = X.copy()
lineX_indices = X.indices.astype(np.int64, copy=False)
(to do a copy only if the type is changed)X_indptr =X_indptr.astype(np.int64, copy=False)
And then return
X.data
, andX_indices
andX_indptr
, which I would use later on in_csr_polynomial_expansion
What do you think ?