From 56b2c36e997bec0a4bc1fc50505cc2246be1a219 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Tue, 24 Jun 2025 11:10:26 -0400 Subject: [PATCH] avoid using at-generated for SubArray reindexing The tuple specialization for indexing with UnitRanges (with up to 10 values) is highly optimized and type stable for statically known values like these. --- base/subarray.jl | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/base/subarray.jl b/base/subarray.jl index eacaddc068f1f..51e92432b4017 100644 --- a/base/subarray.jl +++ b/base/subarray.jl @@ -298,15 +298,8 @@ reindex(idxs::Tuple{AbstractMatrix, Vararg{Any}}, subidxs::Tuple{Any, Any, Varar (@_propagate_inbounds_meta; (idxs[1][subidxs[1], subidxs[2]], reindex(tail(idxs), tail(tail(subidxs)))...)) # In general, we index N-dimensional parent arrays with N indices -@generated function reindex(idxs::Tuple{AbstractArray{T,N}, Vararg{Any}}, subidxs::Tuple{Vararg{Any}}) where {T,N} - if length(subidxs.parameters) >= N - subs = [:(subidxs[$d]) for d in 1:N] - tail = [:(subidxs[$d]) for d in N+1:length(subidxs.parameters)] - :(@_propagate_inbounds_meta; (idxs[1][$(subs...)], reindex(tail(idxs), ($(tail...),))...)) - else - :(throw(ArgumentError("cannot re-index SubArray with fewer indices than dimensions\nThis should not occur; please submit a bug report."))) - end -end +reindex(idxs::Tuple{AbstractArray{<:Any,N}, Vararg{Any}}, subidxs::Tuple{Vararg{Any}}) where {N} = + (@_propagate_inbounds_meta; (idxs[1][subidxs[1:N]...], reindex(tail(idxs), subidxs[N+1:end])...)) # In general, we simply re-index the parent indices by the provided ones SlowSubArray{T,N,P,I} = SubArray{T,N,P,I,false}