-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Accept non-AbstractArrays in 2-arg axes/size
#59512
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
base: master
Are you sure you want to change the base?
Conversation
|
should |
|
Good point, perhaps we may require |
|
seems fair to me. as long as it is not the other way around (setting |
|
some overlap with my PR #59465 |
`Int` constructor instead of convert in `size` Co-authored-by: Neven Sajko <[email protected]>
`Int` constructor instead of convert in `axes` Co-authored-by: Neven Sajko <[email protected]>
|
@nanosoldier |
|
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
| """ | ||
| size(t::AbstractArray{T,N}, d) where {T,N} = d::Integer <= N ? size(t)[d] : 1 | ||
| function size(A, d) | ||
| @inline |
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.
| _size(IteratorSize(A), size(A), d) | ||
| end | ||
| function _size(::HasShape, s::Tuple, d::Integer) | ||
| @inline |
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.
| @inline |
| """ | ||
| function axes(A::AbstractArray{T,N}, d) where {T,N} | ||
| function axes(A, d) | ||
| @inline |
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.
| @inline |
| _axes(IteratorSize(A), axes(A), d) | ||
| end | ||
| function _axes(::HasShape, ax::Tuple, d::Integer) | ||
| @inline |
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.
| @inline |
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.