Skip to content

Enable stacking of 0-dim arguments #3 #15

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 1 commit into from
May 27, 2025
Merged
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion src/StackViews.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function Base.axes(A::StackView{T,N,D}) where {T,N,D}
prev, post = Base.IteratorsMD.split(frame_axes, Val(D-1))

# use homogenous range to make _append_tuple happy
Copy link
Member

Choose a reason for hiding this comment

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

I think I use typeof(first(frame_axes)) rather than eltype(prev) for a "performance" reason.
Mostly Any[...] vs [...]`, can you check if they still work similarly in terms of performance for non-trivial large arrays (ttfx time and average time)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do some comparisons today. Used eltype(prev) here because _apend_tuple assumes a homogeneous tuple prev anyways, and I thought eltype would be something like eltype(::NTuple{N, T}) where {N, T}=T. Upon closer inspection, eltype on tuple (or rather tuple types) is a bit more complicated, but there does not seem to be obvious problems with type stability.
With previous typeof(first(frame_axes)) there were issues because frame_axes == () for 0-dim slices. Alternative: new helper _fill_range_type with methods for non-empty tuples (falling back to typeof(first(frame_axes)) and for empty tuples (returning Base.Bottom e.g. )

fill_range = convert(typeof(first(frame_axes)), Base.OneTo(1))
fill_range = _convert(eltype(prev), Base.OneTo(1))
return (_append_tuple(prev, Val(D-1), fill_range)...,
Base.OneTo(length(A.slices)),
post...)
Expand All @@ -140,6 +140,8 @@ end
end

# utils
_convert(::Type{Base.Bottom}, idx)=idx
_convert(T::Type, idx)=convert(T, idx)

# For type stability
@inline _max(::Val{x}, ::Val{y}) where {x, y} = Val(max(x, y))
Expand Down
Loading