8000 MAINT: Simplify block implementation by j-towns · Pull Request #9667 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

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 23 commits into from
Nov 12, 2017
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify further - matching docstring logic
  • Loading branch information
j-towns committed Sep 25, 2017
commit 3ed6936b82cb444e5516bda705701245d4fa4b4d
2 changes: 1 addition & 1 deletion numpy/core/shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def block_recursion(arrays, depth=0):
arrs = [block_recursion(arr, depth+1) for arr in arrays]
arr_ndim = max(arr.ndim for arr in arrs)
arrs = [atleast_nd(a, arr_ndim) for a in arrs]
Copy link
Member

Choose a reason for hiding this comment

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

Not a huge fan of how atleast_nd gets called repeatedly, rather than just once for each array.

< 93B3 /option>

Copy link
Contributor Author
@j-towns j-towns Oct 9, 2017

Choose a reason for hiding this comment

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

The simplest way to get around this would be to have _block_check_depths_match also find the max array ndim. I'll have a go at drafting that change and see how it looks and whether it improves performance.

return _nx.concatenate(arrs, axis=depth+max(0, arr_ndim-list_ndim))
return _nx.concatenate(arrs, axis=depth-list_ndim)
else:
# We've 'bottomed out' - arrays is either a scalar or an array
return atleast_nd(arrays, list_ndim)
Expand Down
0