Accept non-AbstractArrays in 2-arg axes/size#59512
Open
Conversation
Member
|
should |
Member
Author
|
Good point, perhaps we may require |
Member
|
seems fair to me. as long as it is not the other way around (setting |
Member
|
some overlap with my PR #59465 |
nsajko
reviewed
Sep 9, 2025
nsajko
reviewed
Sep 9, 2025
nsajko
reviewed
Sep 9, 2025
`Int` constructor instead of convert in `size` Co-authored-by: Neven Sajko <4944410+nsajko@users.noreply.github.com>
`Int` constructor instead of convert in `axes` Co-authored-by: Neven Sajko <4944410+nsajko@users.noreply.github.com>
Member
Member
Author
|
@nanosoldier |
Collaborator
|
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
nsajko
approved these changes
Sep 23, 2025
| """ | ||
| size(t::AbstractArray{T,N}, d) where {T,N} = d::Integer <= N ? size(t)[d] : 1 | ||
| function size(A, d) | ||
| @inline |
Member
| _size(IteratorSize(A), size(A), d) | ||
| end | ||
| function _size(::HasShape, s::Tuple, d::Integer) | ||
| @inline |
| """ | ||
| function axes(A::AbstractArray{T,N}, d) where {T,N} | ||
| function axes(A, d) | ||
| @inline |
| _axes(IteratorSize(A), axes(A), d) | ||
| end | ||
| function _axes(::HasShape, ax::Tuple, d::Integer) | ||
| @inline |
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.
With this change, any type that implements
axes(A)getsaxes(A, d)for free, and similarly forsize. These would make it easier to accept array-like types such asBroadcastedin functions that require indexing.One caveat is that the default assumption here is that for
d > ndims(A), we return a single-element axisOneTosimilar to what we do forAbstractArrays. This may not always be meaningful for arbitrary types, and indexing with trailing unit indices might not be supported. Such types currently implementaxes(A, d)for themselves and should continue doing so.