@@ -277,67 +277,24 @@ struct InterpGetindex{N,A<:AbstractArray{<:Any,N}}
277277 InterpGetindex (A:: AbstractArray ) = new {ndims(A),typeof(A)} (A)
278278end
279279@inline Base. getindex (A:: InterpGetindex{N} , I:: Vararg{Union{Int,WeightedIndex},N} ) where {N} =
280- interp_getindex (A. coeffs, I, ntuple (d-> 0 , Val (N))... )
281-
282- # The non-generated version is currently disabled due to https://github.com/JuliaLang/julia/issues/29117
283- # # This follows a "move processed indexes to the back" strategy, so J contains the yet-to-be-processed
284- # # indexes and I all the processed indexes.
285- # interp_getindex(A::AbstractArray{T,N}, J::Tuple{Int,Vararg{Any,L}}, I::Vararg{Int,M}) where {T,N,L,M} =
286- # interp_getindex(A, Base.tail(J), I..., J[1])
287- # function interp_getindex(A::AbstractArray{T,N}, J::Tuple{WeightedIndex,Vararg{Any,L}}, I::Vararg{Int,M}) where {T,N,L,M}
288- # wi = J[1]
289- # interp_getindex1(A, indexes(wi), weights(wi), Base.tail(J), I...)
290- # end
291- # interp_getindex(A::AbstractArray{T,N}, ::Tuple{}, I::Vararg{Int,N}) where {T,N} = # termination
292- # @inbounds A[I...] # all bounds-checks have already happened
293- #
294- # ## Handle expansion of a single dimension
295- # # version for WeightedAdjIndex
296- # @inline interp_getindex1(A, i::Int, weights::NTuple{K,Any}, rest, I::Vararg{Int,M}) where {M,K} =
297- # weights[1] * interp_getindex(A, rest, I..., i) + interp_getindex1(A, i+1, Base.tail(weights), rest, I...)
298- # @inline interp_getindex1(A, i::Int, weights::Tuple{Any}, rest, I::Vararg{Int,M}) where M =
299- # weights[1] * interp_getindex(A, rest, I..., i)
300- # interp_getindex1(A, i::Int, weights::Tuple{}, rest, I::Vararg{Int,M}) where M =
301- # error("exhausted the weights, this should never happen")
302- #
303- # # version for WeightedArbIndex
304- # @inline interp_getindex1(A, indexes::NTuple{K,Int}, weights::NTuple{K,Any}, rest, I::Vararg{Int,M}) where {M,K} =
305- # weights[1] * interp_getindex(A, rest, I..., indexes[1]) + interp_getindex1(A, Base.tail(indexes), Base.tail(weights), rest, I...)
306- # @inline interp_getindex1(A, indexes::Tuple{Int}, weights::Tuple{Any}, rest, I::Vararg{Int,M}) where M =
307- # weights[1] * interp_getindex(A, rest, I..., indexes[1])
308- # interp_getindex1(A, indexes::Tuple{}, weights::Tuple{}, rest, I::Vararg{Int,M}) where M =
309- # error("exhausted the weights and indexes, this should never happen")
310-
311- @inline interp_getindex (A:: AbstractArray{T,N} , J:: Tuple{Int,Vararg{Any,K}} , I:: Vararg{Int,N} ) where {T,N,K} =
312- interp_getindex (A, Base. tail (J), Base. tail (I)... , J[1 ])
313- @generated function interp_getindex (A:: AbstractArray{T,N} , J:: Tuple{WeightedAdjIndex{L,W},Vararg{Any,K}} , I:: Vararg{Int,N} ) where {T,N,K,L,W}
314- ex = :(w[1 ]* interp_getindex (A, Jtail, Itail... , j))
315- for l = 2 : L
316- ex = :(w[$ l]* interp_getindex (A, Jtail, Itail... , j+ $ (l- 1 )) + $ ex)
317- end
318- quote
319- $ (Expr (:meta , :inline ))
320- Jtail = Base. tail (J)
321- Itail = Base. tail (I)
322- j, w = J[1 ]. istart, J[1 ]. weights
323- $ ex
324- end
325- end
326- @generated function interp_getindex (A:: AbstractArray{T,N} , J:: Tuple{WeightedArbIndex{L,W},Vararg{Any,K}} , I:: Vararg{Int,N} ) where {T,N,K,L,W}
327- ex = :(w[1 ]* interp_getindex (A, Jtail, Itail... , ij[1 ]))
328- for l = 2 : L
329- ex = :(w[$ l]* interp_getindex (A, Jtail, Itail... , ij[$ l]) + $ ex)
330- end
331- quote
332- $ (Expr (:meta , :inline ))
333- Jtail = Base. tail (J)
334- Itail = Base. tail (I)
335- ij, w = J[1 ]. indexes, J[1 ]. weights
336- $ ex
337- end
338- end
339- @inline interp_getindex (A:: AbstractArray{T,N} , :: Tuple{} , I:: Vararg{Int,N} ) where {T,N} = # termination
340- @inbounds A[I... ] # all bounds-checks have already happened
280+ interp_getindex (A. coeffs, ntuple (_ -> 0 , Val (N)), map (indexflag, I)... )
281+ indexflag (I:: Int ) = I
282+ @inline indexflag (I:: WeightedIndex ) = indextuple (I), weights (I)
283+
284+ # A recursion-based `interp_getindex`, which follows a "move processed indexes to the back" strategy
285+ # `I` contains the processed index, and (wi1, wis...) contains the yet-to-be-processed indexes
286+ # Here we meet a no-interp dim, just append the index to `I`'s end.
287+ @inline interp_getindex (A, I, wi1:: Int , wis... ) =
288+ interp_getindex (A, (Base. tail (I)... , wi1), wis... )
289+ # Here we handle the expansion of a single dimension.
290+ @inline interp_getindex (A, I, wi1:: NTuple{2,Tuple{Any,Vararg{Any,N}}} , wis... ) where {N} =
291+ wi1[2 ][end ] * interp_getindex (A, (Base. tail (I)... , wi1[1 ][end ]), wis... ) +
292+ interp_getindex (A, I, map (Base. front, wi1), wis... )
293+ @inline interp_getindex (A, I, wi1:: NTuple{2,Tuple{Any}} , wis... ) =
294+ wi1[2 ][1 ] * interp_getindex (A, (Base. tail (I)... , wi1[1 ][1 ]), wis... )
295+ # Termination
296+ @inline interp_getindex (A:: AbstractArray{T,N} , I:: Dims{N} ) where {T,N} =
297+ @inbounds A[I... ] # all bounds-checks have already happened
341298
342299"""
343300 w = value_weights(degree, δx)
0 commit comments