From 2f75132b1e1ce9ac04b0555e30c7391e84ad25f6 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Wed, 12 Jul 2023 13:36:41 -0400 Subject: [PATCH 1/5] make A[:, end] error for ragged AbstractVectorOfArray when the lengths are not equal --- src/vector_of_array.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 752d7722..3a0e694f 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -544,3 +544,10 @@ end end unpack_args_voa(i, args::Tuple{Any}) = (unpack_voa(args[1], i),) unpack_args_voa(::Any, args::Tuple{}) = () + +function Base.lastindex(A::AbstractVectorOfArray, i=1) + i == 1 && return length(A) + len1 = lastindex(A[1], i-1) + all(x->isequal(lastindex(x, i-1), len1), A) && return len1 + throw(ArgumentError("Can not get lastindex of an AbstractVectorOfArray for dimensions other than 1")) +end From 068b31347a8ed65a676d84a8fc031787f36c727a Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 12 Jul 2023 14:13:39 -0400 Subject: [PATCH 2/5] Update src/vector_of_array.jl --- src/vector_of_array.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 3a0e694f..e75fb132 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -549,5 +549,7 @@ function Base.lastindex(A::AbstractVectorOfArray, i=1) i == 1 && return length(A) len1 = lastindex(A[1], i-1) all(x->isequal(lastindex(x, i-1), len1), A) && return len1 - throw(ArgumentError("Can not get lastindex of an AbstractVectorOfArray for dimensions other than 1")) + throw(ArgumentError("`end` is not defined for AbstractVectorOfArray types when the arrays have different sizes. Either enforce that the arrays are all similarly sized or directly define the index value. + +Note that a common reason for this error in the SciMLSolution context comes from adaptively sized models. Using arguments like `saveat` can enforce that an ensemble of solutions are all saved at the same time points and thus all have the same size. Similarly, if an ODE is solved with adaptivity in the size of the system (such as for adaptive grids) then this error can refer to the changing size of the ODE through the time series.")) end From 5d997dfeaea60fc095b8236abcc9e93267010e6a Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Wed, 12 Jul 2023 14:18:27 -0400 Subject: [PATCH 3/5] fixup --- src/vector_of_array.jl | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index e75fb132..cf4c8794 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -70,8 +70,8 @@ Base.@pure __parameterless_type(T) = Base.typename(T).wrapper x <: Union{Symbol, AllObserved} && return quote true end ss = ["Operation", "Variable", "Sym", "Num", "Term"] s = string(Symbol(__parameterless_type(x))) - bool = any(x -> occursin(x, s), ss) - quote + bool = any(x -> occursin(x, s), ss) + quote $bool end end @@ -161,8 +161,12 @@ end # Interface for the linear indexing. This is just a view of the underlying nested structure @inline Base.firstindex(VA::AbstractVectorOfArray) = firstindex(VA.u) -@inline Base.lastindex(VA::AbstractVectorOfArray) = lastindex(VA.u) - +function Base.lastindex(A::AbstractVectorOfArray, i=1) + i == 1 && return length(A) + len1 = lastindex(A[1], i-1) + all(x->isequal(lastindex(x, i-1), len1), A) && return len1 + throw(ArgumentError("`end` is not defined for AbstractVectorOfArray types when the arrays have different sizes. Either enforce that the arrays are all similarly sized or directly define the index value. +Note that a common reason for this error in the SciMLSolution context comes from adaptively sized models. Using arguments like `saveat` can enforce that an ensemble of solutions are all saved at the same time points and thus all have the same size. Similarly, if an ODE is solved with adaptivity in the size of the system (such as for adaptive grids) then this error can refer to the changing size of the ODE through the time series.")) @inline Base.length(VA::AbstractVectorOfArray) = length(VA.u) @inline Base.eachindex(VA::AbstractVectorOfArray) = Base.OneTo(length(VA.u)) @inline Base.IteratorSize(VA::AbstractVectorOfArray) = Base.HasLength() @@ -544,12 +548,4 @@ end end unpack_args_voa(i, args::Tuple{Any}) = (unpack_voa(args[1], i),) unpack_args_voa(::Any, args::Tuple{}) = () - -function Base.lastindex(A::AbstractVectorOfArray, i=1) - i == 1 && return length(A) - len1 = lastindex(A[1], i-1) - all(x->isequal(lastindex(x, i-1), len1), A) && return len1 - throw(ArgumentError("`end` is not defined for AbstractVectorOfArray types when the arrays have different sizes. Either enforce that the arrays are all similarly sized or directly define the index value. - -Note that a common reason for this error in the SciMLSolution context comes from adaptively sized models. Using arguments like `saveat` can enforce that an ensemble of solutions are all saved at the same time points and thus all have the same size. Similarly, if an ODE is solved with adaptivity in the size of the system (such as for adaptive grids) then this error can refer to the changing size of the ODE through the time series.")) end From 4d8559a6c4db1a711885be4a85cfd2c0b7c73173 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Wed, 12 Jul 2023 14:19:05 -0400 Subject: [PATCH 4/5] typo --- src/vector_of_array.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index cf4c8794..b6a537b6 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -167,6 +167,7 @@ function Base.lastindex(A::AbstractVectorOfArray, i=1) all(x->isequal(lastindex(x, i-1), len1), A) && return len1 throw(ArgumentError("`end` is not defined for AbstractVectorOfArray types when the arrays have different sizes. Either enforce that the arrays are all similarly sized or directly define the index value. Note that a common reason for this error in the SciMLSolution context comes from adaptively sized models. Using arguments like `saveat` can enforce that an ensemble of solutions are all saved at the same time points and thus all have the same size. Similarly, if an ODE is solved with adaptivity in the size of the system (such as for adaptive grids) then this error can refer to the changing size of the ODE through the time series.")) +end @inline Base.length(VA::AbstractVectorOfArray) = length(VA.u) @inline Base.eachindex(VA::AbstractVectorOfArray) = Base.OneTo(length(VA.u)) @inline Base.IteratorSize(VA::AbstractVectorOfArray) = Base.HasLength() @@ -548,4 +549,3 @@ end end unpack_args_voa(i, args::Tuple{Any}) = (unpack_voa(args[1], i),) unpack_args_voa(::Any, args::Tuple{}) = () -end From 212b772c0ac03a0ebf53a3e949d127bf4fcc0858 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Wed, 12 Jul 2023 16:36:41 -0400 Subject: [PATCH 5/5] fix --- src/vector_of_array.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index b6a537b6..7ffb4033 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -164,7 +164,7 @@ end function Base.lastindex(A::AbstractVectorOfArray, i=1) i == 1 && return length(A) len1 = lastindex(A[1], i-1) - all(x->isequal(lastindex(x, i-1), len1), A) && return len1 + all(x->isequal(lastindex(x, i-1), len1), A.u) && return len1 throw(ArgumentError("`end` is not defined for AbstractVectorOfArray types when the arrays have different sizes. Either enforce that the arrays are all similarly sized or directly define the index value. Note that a common reason for this error in the SciMLSolution context comes from adaptively sized models. Using arguments like `saveat` can enforce that an ensemble of solutions are all saved at the same time points and thus all have the same size. Similarly, if an ODE is solved with adaptivity in the size of the system (such as for adaptive grids) then this error can refer to the changing size of the ODE through the time series.")) end