From 88295d9b7b54eca47e7136d8a14705df0689d8e6 Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Mon, 28 Jun 2021 17:13:48 +0530 Subject: [PATCH 1/2] Fix indexing --- src/vector_of_array.jl | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index b8b39917..4474be82 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -76,23 +76,6 @@ Base.@propagate_inbounds function Base.getindex(A::AbstractDiffEqArray{T, N},sym Base.getindex.(A.u, i) end end -Base.@propagate_inbounds function Base.getindex(A::AbstractDiffEqArray{T, N},sym,args...) where {T, N} - if issymbollike(sym) && A.syms !== nothing - i = findfirst(isequal(Symbol(sym)),A.syms) - else - i = sym - end - - if i === nothing - if issymbollike(i) && A.indepsym !== nothing && Symbol(i) == A.indepsym - A.t[args...] - else - observed(A,sym,args...) - end - else - Base.getindex.(A.u, args...) - end -end Base.@propagate_inbounds Base.getindex(A::AbstractDiffEqArray{T, N}, I::Int...) where {T, N} = A.u[I[end]][Base.front(I)...] Base.@propagate_inbounds Base.getindex(A::AbstractDiffEqArray{T, N}, i::Int) where {T, N} = A.u[i] function observed(A::AbstractDiffEqArray{T, N},sym,i::Int) where {T, N} From 7749ba40e2632efb684e08ec685d8389ff5d7a33 Mon Sep 17 00:00:00 2001 From: Sharan Yalburgi Date: Mon, 28 Jun 2021 17:56:09 +0530 Subject: [PATCH 2/2] Handle ambiguities --- src/vector_of_array.jl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 4474be82..505ac244 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -59,6 +59,13 @@ Base.@propagate_inbounds Base.getindex(VA::AbstractVectorOfArray{T, N}, I::Colon Base.@propagate_inbounds Base.getindex(VA::AbstractDiffEqArray{T, N}, I::Colon) where {T, N} = VA.u[I] Base.@propagate_inbounds Base.getindex(VA::AbstractVectorOfArray{T, N}, I::AbstractArray{Int}) where {T, N} = VectorOfArray(VA.u[I]) Base.@propagate_inbounds Base.getindex(VA::AbstractDiffEqArray{T, N}, I::AbstractArray{Int}) where {T, N} = DiffEqArray(VA.u[I],VA.t[I]) +Base.@propagate_inbounds function Base.getindex(A::AbstractDiffEqArray{T, N}, + I::Union{Int,AbstractArray{Int},CartesianIndex,Colon,BitArray,AbstractArray{Bool}}...) where {T, N} + RecursiveArrayTools.VectorOfArray(A.u)[I...] +end +Base.@propagate_inbounds Base.getindex(A::AbstractDiffEqArray{T, N}, i::Int,::Colon) where {T, N} = [A.u[j][i] for j in 1:length(A)] +Base.@propagate_inbounds Base.getindex(A::AbstractDiffEqArray{T, N}, ::Colon,i::Int) where {T, N} = A.u[i] +Base.@propagate_inbounds Base.getindex(A::AbstractDiffEqArray{T, N}, i::Int,II::AbstractArray{Int}) where {T, N} = [A.u[j][i] for j in II] Base.@propagate_inbounds function Base.getindex(A::AbstractDiffEqArray{T, N},sym) where {T, N} if issymbollike(sym) && A.syms !== nothing i = findfirst(isequal(Symbol(sym)),A.syms) @@ -76,6 +83,23 @@ Base.@propagate_inbounds function Base.getindex(A::AbstractDiffEqArray{T, N},sym Base.getindex.(A.u, i) end end +Base.@propagate_inbounds function Base.getindex(A::AbstractDiffEqArray{T, N},sym,args...) where {T, N} + if issymbollike(sym) && A.syms !== nothing + i = findfirst(isequal(Symbol(sym)),A.syms) + else + i = sym + end + + if i === nothing + if issymbollike(i) && A.indepsym !== nothing && Symbol(i) == A.indepsym + A.t[args...] + else + observed(A,sym,args...) + end + else + Base.getindex.(A.u, i, args...) + end +end Base.@propagate_inbounds Base.getindex(A::AbstractDiffEqArray{T, N}, I::Int...) where {T, N} = A.u[I[end]][Base.front(I)...] Base.@propagate_inbounds Base.getindex(A::AbstractDiffEqArray{T, N}, i::Int) where {T, N} = A.u[i] function observed(A::AbstractDiffEqArray{T, N},sym,i::Int) where {T, N}