Skip to content

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Sep 8, 2025

With this change, any type that implements axes(A) gets axes(A, d) for free, and similarly for size. These would make it easier to accept array-like types such as Broadcasted in functions that require indexing.

One caveat is that the default assumption here is that for d > ndims(A), we return a single-element axis OneTo similar to what we do for AbstractArrays. This may not always be meaningful for arbitrary types, and indexing with trailing unit indices might not be supported. Such types currently implement axes(A, d) for themselves and should continue doing so.

@jishnub jishnub added the arrays [a, r, r, a, y, s] label Sep 8, 2025
@adienes
Copy link
Member

adienes commented Sep 8, 2025

should ndims then have a fallback length(axes(A)) ? and size one map(length, size(A))? although that might conflict with the existing

function axes(A)
    @inline
    map(unchecked_oneto, size(A))
end

@jishnub
Copy link
Member Author

jishnub commented Sep 8, 2025

Good point, perhaps we may require Base.IteratorSize(A) to be specialized to return an Base.HasShape{N}, and infer ndims from this? I imagine most iterators wouldn't want to opt into the multidimensional array-like behavior that comes with ndims being automatically inferred from size/axes.

@adienes
Copy link
Member

adienes commented Sep 8, 2025

seems fair to me. as long as it is not the other way around (setting IteratorSize based on axes or size ...)

@nsajko
Copy link
Member

nsajko commented Sep 9, 2025

some overlap with my PR #59465

jishnub and others added 2 commits September 9, 2025 23:27
`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]>
@nsajko nsajko added design Design of APIs or of the language itself iteration Involves iteration or the iteration protocol labels Sep 9, 2025
@nsajko
Copy link
Member

nsajko commented Sep 9, 2025

With this change, most two-argument methods of size/axes should perhaps be deleted. In this PR or in followups. However some of that would overlap with my open PR #59442 (which depends on either PR #59465 or this very PR getting merged before it can be mergeable).

@jishnub
Copy link
Member Author

jishnub commented Sep 11, 2025

@nanosoldier runbenchmarks(ALL, vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] design Design of APIs or of the language itself iteration Involves iteration or the iteration protocol
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants