From 987e0404fde8e63e753a81d4b47db8de1326d4a1 Mon Sep 17 00:00:00 2001 From: tiemvanderdeure Date: Thu, 28 Nov 2024 10:08:25 +0100 Subject: [PATCH] fix indexing --- src/array/indexing.jl | 6 +----- src/stack/indexing.jl | 17 ++++++----------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/array/indexing.jl b/src/array/indexing.jl index df48dd91d..9d30017a2 100644 --- a/src/array/indexing.jl +++ b/src/array/indexing.jl @@ -264,8 +264,4 @@ Base.@assume_effects :foldable @inline _simplify_dim_indices() = () @propagate_inbounds Base.maybeview(A::AbstractDimArray, args...; kw...) = view(A, args...; kw...) @propagate_inbounds Base.maybeview(A::AbstractDimArray, args::Vararg{Union{Number,Base.AbstractCartesianIndex}}; kw...) = - view(A, args...; kw...) -@propagate_inbounds Base.maybeview(A::AbstractDimStack, args...; kw...) = - view(A, args...; kw...) -@propagate_inbounds Base.maybeview(A::AbstractDimStack, args::Vararg{Union{Number,Base.AbstractCartesianIndex}}; kw...) = - view(A, args...; kw...) + view(A, args...; kw...) \ No newline at end of file diff --git a/src/stack/indexing.jl b/src/stack/indexing.jl index 80fc7af1c..acc3f19e5 100644 --- a/src/stack/indexing.jl +++ b/src/stack/indexing.jl @@ -49,11 +49,6 @@ for f in (:getindex, :view, :dotview) I = to_indices(CartesianIndices(s), Lookups._construct_types(i1, i2, Is...)) # Check we have the right number of dimensions if length(dims(s)) > length(I) - @propagate_inbounds function $_dim_f( - A::AbstractDimStack, a1::Union{Dimension,DimensionIndsArrays}, args::Union{Dimension,DimensionIndsArrays}... - ) - return merge_and_index(Base.$f, A, (a1, args...)) - end throw(BoundsError(dims(s), I)) elseif length(dims(s)) < length(I) # Allow trailing ones @@ -78,11 +73,6 @@ for f in (:getindex, :view, :dotview) $_dim_f(s, _simplify_dim_indices(i)...) end - @propagate_inbounds function $_dim_f( - A::AbstractDimStack, a1::Union{Dimension,DimensionIndsArrays}, args::Union{Dimension,DimensionIndsArrays}... - ) - return merge_and_index($_dim_f, A, (a1, args...)) - end # Handle zero-argument getindex, this will error unless all layers are zero dimensional @propagate_inbounds function $_dim_f(s::AbstractDimStack) map(Base.$f, data(s)) @@ -129,7 +119,7 @@ end map((A, x) -> setindex!(A, x, I...; kw...), layers(s), xs) end -_map_setindex!(s, xs, i) = map((A, x) -> setindex!(A, x, i...; kw...), layers(s), xs) +_map_setindex!(s, xs, i; kw...) = map((A, x) -> setindex!(A, x, i...; kw...), layers(s), xs) _setindex_mixed!(s::AbstractDimStack, x, i::AbstractArray) = map(A -> setindex!(A, x, DimIndices(dims(s))[i]), layers(s)) @@ -160,3 +150,8 @@ function merge_and_index(f, s::AbstractDimStack, ds) end return rebuild_from_arrays(s, newlayers) end + +@propagate_inbounds Base.maybeview(A::AbstractDimStack, args...; kw...) = + view(A, args...; kw...) +@propagate_inbounds Base.maybeview(A::AbstractDimStack, args::Vararg{Union{Number,Base.AbstractCartesianIndex}}; kw...) = + view(A, args...; kw...)