From 1fc5cd10dcbe40d53bc28903a85222e06dd476a2 Mon Sep 17 00:00:00 2001 From: Lorenzo Van Munoz <66997677+lxvm@users.noreply.github.com> Date: Mon, 19 Feb 2024 12:59:35 -0500 Subject: [PATCH 1/4] Update vector_of_array.jl Fix #354 --- src/vector_of_array.jl | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index cc335297..cc083d18 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -296,13 +296,7 @@ __parameterless_type(T) = Base.typename(T).wrapper Base.@propagate_inbounds function _getindex(A::AbstractVectorOfArray{T, N}, ::NotSymbolic, I::Colon...) where {T, N} @assert length(I) == ndims(A.u[1]) + 1 - vecs = if N == 1 - A.u - else - vec.(A.u) - end - return Adapt.adapt(__parameterless_type(T), - reshape(reduce(hcat, vecs), size(A.u[1])..., length(A.u))) + return Array(A) end Base.@propagate_inbounds function _getindex(A::AbstractVectorOfArray{T, N}, From 6aea2ab5c296bfa9fb742c27381ae6f4b640429b Mon Sep 17 00:00:00 2001 From: Lorenzo Van Munoz <66997677+lxvm@users.noreply.github.com> Date: Mon, 19 Feb 2024 13:12:09 -0500 Subject: [PATCH 2/4] Update basic_indexing.jl add test --- test/basic_indexing.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/basic_indexing.jl b/test/basic_indexing.jl index 749f7419..c301dd6f 100644 --- a/test/basic_indexing.jl +++ b/test/basic_indexing.jl @@ -257,3 +257,6 @@ foo!(u_vector) # test efficiency num_allocs = @allocations foo!(u_matrix) @test num_allocs == 0 + +# issue 354 +@test VectorOfArray(ones(1))[:] == ones(1) From 458d900b8d73bf331d5bea33ca229fc4c48d43bd Mon Sep 17 00:00:00 2001 From: lxvm Date: Mon, 26 Feb 2024 22:58:33 -0500 Subject: [PATCH 3/4] Revert "Update vector_of_array.jl" This reverts commit 49d67427c5cfa94de80ad5231f6d930d4d4bc434. --- src/vector_of_array.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index cc083d18..cc335297 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -296,7 +296,13 @@ __parameterless_type(T) = Base.typename(T).wrapper Base.@propagate_inbounds function _getindex(A::AbstractVectorOfArray{T, N}, ::NotSymbolic, I::Colon...) where {T, N} @assert length(I) == ndims(A.u[1]) + 1 - return Array(A) + vecs = if N == 1 + A.u + else + vec.(A.u) + end + return Adapt.adapt(__parameterless_type(T), + reshape(reduce(hcat, vecs), size(A.u[1])..., length(A.u))) end Base.@propagate_inbounds function _getindex(A::AbstractVectorOfArray{T, N}, From d06b8a6932860badd8a05aa404b2769ea3285f6e Mon Sep 17 00:00:00 2001 From: lxvm Date: Mon, 26 Feb 2024 23:18:16 -0500 Subject: [PATCH 4/4] add getindex slice method for vector of numbers --- src/vector_of_array.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index cc335297..7c3a1c75 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -304,6 +304,11 @@ Base.@propagate_inbounds function _getindex(A::AbstractVectorOfArray{T, N}, return Adapt.adapt(__parameterless_type(T), reshape(reduce(hcat, vecs), size(A.u[1])..., length(A.u))) end +Base.@propagate_inbounds function _getindex(A::AbstractVectorOfArray{T, N}, + ::NotSymbolic, I::Colon...) where {T <: Number, N} + @assert length(I) == ndims(A.u) + return A.u[I...] +end Base.@propagate_inbounds function _getindex(A::AbstractVectorOfArray{T, N}, ::NotSymbolic, I::AbstractArray{Bool},