MAINT: Optimize loadtxt usecols.#19618
Merged
charris merged 2 commits intonumpy:mainfrom Aug 23, 2021
Merged
Conversation
eric-wieser
reviewed
Aug 6, 2021
eric-wieser
reviewed
Aug 6, 2021
numpy/lib/npyio.py
Outdated
Comment on lines
+1008
to
+1010
| if usecols: | ||
| vals = [vals[j] for j in usecols] | ||
| if len(vals) != ncols: | ||
| vals = usecols_getter(vals) | ||
| elif len(vals) != ncols: |
Member
There was a problem hiding this comment.
Can you explain this change to an elif?
Contributor
Author
There was a problem hiding this comment.
If usecols is not None, then we already know that usecols_getter will (by construction) return a list with the right number of elements. The performance gain is negligible, but it seems just good to skip the unneeded check.
Member
|
@anntzer Needs rebase. |
50b3b43 to
1d32c6e
Compare
Contributor
Author
|
rebased |
1d32c6e to
45f9118
Compare
This was referenced Aug 17, 2021
45f9118 to
fcf5bba
Compare
charris
reviewed
Aug 22, 2021
Member
|
#19693 is in, everything needs a rebase :) |
fcf5bba to
a59c317
Compare
7-10% speedup in usecols benchmarks; it appears that even in the single-usecol case, avoiding the iteration over `usecols` more than compensates the cost of the extra function call to usecols_getter.
a59c317 to
1767e60
Compare
Member
|
Thanks @anntzer . |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
7-10% speedup in usecols benchmarks; it appears that even in the
single-usecol case, avoiding the iteration over
usecolsmore thancompensates the cost of the extra function call to usecols_getter.