-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
MAINT: Simplify block implementation #9667
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
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a5c6f0d
Simplify block implementation
j-towns 2dcc9aa
np.block style improvements
j-towns e787a9f
Reflect asanyarray behaviour in block
j-towns 95adb77
Add empty list comment to block depth check
j-towns 07a3f43
Use strict type checking (not isinstance)
j-towns 19fc68c
Re-add tuple type-check comment
j-towns 997ac2c
Re-add `atleast_nd` function.
j-towns 7eb1044
Add detailed comment to _block_check_depths_match
j-towns ff7f726
Extend comments _block_check_depths_match
j-towns 6ecd2b4
Try not recomputing list_ndim
j-towns 1211b70
Slight simplification to logic
j-towns ffa6cf6
Add two tests for different arr_ndims
j-towns 3ed6936
Simplify further - matching docstring logic
j-towns 5f9f1fa
Rename list_ndim to max_depth
j-towns 8a83a5f
rm extra line from near top of shape_base
j-towns 5a0557a
Pre-calculate max array ndim
j-towns c2b5be5
Further slight simplifications
j-towns bd6729d
Update block docstrings
j-towns ad278f3
Fix python 3.4 sequence error
j-towns 2c1734b
Correct empty list ndim
j-towns eaddf39
Avoid using zip(*...) syntax
j-towns a5cbc93
Use builtin next method
j-towns a691f2d
Rm unnecessary enumerate
j-towns 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
Fix python 3.4 sequence error
- Loading branch information
commit ad278f3bfea97636b18c8d699babdd02aa3cac5c
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,8 +402,8 @@ def format_index(index): | |
) | ||
) | ||
elif type(arrays) is list and len(arrays) > 0: | ||
indexes, arr_ndims = zip(*(_block_check_depths_match(arr, parent_index + [i]) | ||
for i, arr in enumerate(arrays))) | ||
indexes, arr_ndims = zip(*[_block_check_depths_match(arr, parent_index + [i]) | ||
for i, arr in enumerate(arrays)]) | ||
|
||
first_index = indexes[0] | ||
for i, index in enumerate(indexes): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having this overwrite the |
||
|
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
I suspect this is where things slow - can you just iterate over the full result in the loop below, and use
arr_ndims.append
? I don't expect the*
here to be particularly fastThere 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.
I've implemented something that avoids the zip(*...) and pushed it, it seems a little better, though there are still some things that are a little slower than 8a83a5f, probably just because
_nx.ndim
is called on every item at the bottom of the nesting now, which I think we can't get around without reverting to the previous approach.The two things that are really significantly slower are trivial use cases and are still very fast relative to other use cases anyway.
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.
I.e. in absolute terms there's unlikely to be much slowdown to users' code
Uh oh!
There was an error while loading. Please reload this page.
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.
Wasn't this always the case? The difference is, you previously also called it on every intermediate result too - so if anything, you now call it less.
Does avoiding a generator comprehension speed things up? You could call
_block_check_depths_match
in thefor
loop directly, although I agree what you have is cleanerThere 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.
I was calling
atleast_nd
on every level (including the bottom one), but ndim was only called for depth < max_depth I believe. So perhaps ndim, when called on scalars, is slower than our atleast_nd function (which is just a wrapper for np.array)?