From 0b93c513fb4beb48d13c3ee68745e12c75629465 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Sun, 5 May 2024 15:50:25 -0500 Subject: [PATCH 01/11] fix some comments in multi-dim VoA --- src/vector_of_array.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 7a402c0f..60541b87 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -28,8 +28,12 @@ the `VectorOfArray` into a matrix/tensor. Also, `vecarr_to_vectors(VA::AbstractV returns a vector of the series for each component, that is, `A[i,:]` for each `i`. A plot recipe is provided, which plots the `A[i,:]` series. +<<<<<<< Updated upstream There is also support for `VectorOfArray` with constructed from multi-dimensional arrays +======= +There is also support for `VectorOfArray` constructed from multi-dimensional arrays +>>>>>>> Stashed changes ```julia VectorOfArray(u::AbstractArray{AT}) where {T, N, AT <: AbstractArray{T, N}} ``` @@ -37,7 +41,7 @@ VectorOfArray(u::AbstractArray{AT}) where {T, N, AT <: AbstractArray{T, N}} where `IndexStyle(typeof(u)) isa IndexLinear`. """ mutable struct VectorOfArray{T, N, A} <: AbstractVectorOfArray{T, N, A} - u::A # A <: AbstractVector{<: AbstractArray{T, N - 1}} + u::A # A <: AbstractArray{<: AbstractArray{T, N - 1}} end # VectorOfArray with an added series for time From 67da0572c56fe85a2fc7afa09fef612af00fdf92 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Sun, 5 May 2024 15:50:48 -0500 Subject: [PATCH 02/11] unify Base.similar implementation for vector/multi-dim arrays the previous implementation for VoA with Vector parent arrays was `VectorOfArray([similar(VA[:, i], T) for i in eachindex(VA.u)])`. This creates a VoA by calling `similar` on each entry of `VA`, but necessitated a different implementation for VoA with multi-dimensional parent arrays. Creating a new VoA by broadcasting `similar` over the parent array is (I believe) equivalent to previous implementations for VoA with both Vector and Array parents. --- src/vector_of_array.jl | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 60541b87..adbaabaa 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -717,19 +717,7 @@ Base.eltype(::Type{<:AbstractVectorOfArray{T}}) where {T} = T end end @inline function Base.similar(VA::VectorOfArray, ::Type{T} = eltype(VA)) where {T} - VectorOfArray([similar(VA[:, i], T) for i in eachindex(VA.u)]) -end - -# for VectorOfArray with multi-dimensional parent arrays of arrays where all elements are the same type -function Base.similar(vec::VectorOfArray{ - T, N, AT}) where {T, N, AT <: AbstractArray{<:AbstractArray{T}}} - return VectorOfArray(similar(Base.parent(vec))) -end - -# special-case when the multi-dimensional parent array is just an AbstractVector (call the old method) -function Base.similar(vec::VectorOfArray{ - T, N, AT}) where {T, N, AT <: AbstractVector{<:AbstractArray{T}}} - return Base.similar(vec, eltype(vec)) + VectorOfArray(similar.(Base.parent(VA), T)) end # fill! From 864a4635dfbae23d3fd53516e4ed0a740bd334e1 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Sun, 5 May 2024 15:50:48 -0500 Subject: [PATCH 03/11] unify Base.similar implementation for vector/multi-dim arrays the previous implementation for VoA with Vector parent arrays was `VectorOfArray([similar(VA[:, i], T) for i in eachindex(VA.u)])`. This creates a VoA by calling `similar` on each entry of `VA`, but necessitated a different implementation for VoA with multi-dimensional parent arrays. Creating a new VoA by broadcasting `similar` over the parent array is (I believe) equivalent to previous implementations for VoA with both Vector and Array parents. --- src/vector_of_array.jl | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 60541b87..adbaabaa 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -717,19 +717,7 @@ Base.eltype(::Type{<:AbstractVectorOfArray{T}}) where {T} = T end end @inline function Base.similar(VA::VectorOfArray, ::Type{T} = eltype(VA)) where {T} - VectorOfArray([similar(VA[:, i], T) for i in eachindex(VA.u)]) -end - -# for VectorOfArray with multi-dimensional parent arrays of arrays where all elements are the same type -function Base.similar(vec::VectorOfArray{ - T, N, AT}) where {T, N, AT <: AbstractArray{<:AbstractArray{T}}} - return VectorOfArray(similar(Base.parent(vec))) -end - -# special-case when the multi-dimensional parent array is just an AbstractVector (call the old method) -function Base.similar(vec::VectorOfArray{ - T, N, AT}) where {T, N, AT <: AbstractVector{<:AbstractArray{T}}} - return Base.similar(vec, eltype(vec)) + VectorOfArray(similar.(Base.parent(VA), T)) end # fill! From b9a6f233f8cbea96f3a257f6f37317ca60567645 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 6 May 2024 00:28:30 -0500 Subject: [PATCH 04/11] fix comments --- src/vector_of_array.jl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index adbaabaa..38f60f1c 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -28,12 +28,7 @@ the `VectorOfArray` into a matrix/tensor. Also, `vecarr_to_vectors(VA::AbstractV returns a vector of the series for each component, that is, `A[i,:]` for each `i`. A plot recipe is provided, which plots the `A[i,:]` series. -<<<<<<< Updated upstream -There is also support for `VectorOfArray` with constructed from multi-dimensional arrays - -======= There is also support for `VectorOfArray` constructed from multi-dimensional arrays ->>>>>>> Stashed changes ```julia VectorOfArray(u::AbstractArray{AT}) where {T, N, AT <: AbstractArray{T, N}} ``` From af17d479969e6aac787b00de55ba156e5e76acc4 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 6 May 2024 00:30:27 -0500 Subject: [PATCH 05/11] fix test - previous version had memory from `fill(::Vector, ...)` --- test/basic_indexing.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/basic_indexing.jl b/test/basic_indexing.jl index c301dd6f..a08a7e61 100644 --- a/test/basic_indexing.jl +++ b/test/basic_indexing.jl @@ -238,8 +238,8 @@ a[[1, 3, 8]] # multidimensional array of arrays #################################################################### -u_matrix = VectorOfArray(fill([1, 2], 2, 3)) -u_vector = VectorOfArray(vec(u_matrix.u)) +u_matrix = VectorOfArray([[1, 2] for i in 1:2, j in 1:3]) +u_vector = VectorOfArray([[1, 2] for i in 1:6]) # test broadcasting function foo!(u) @@ -248,7 +248,8 @@ function foo!(u) end foo!(u_matrix) foo!(u_vector) -@test u_matrix ≈ u_vector +@test all(u_matrix .== [3, 10]) +@test all(vec(u_matrix) .≈ vec(u_vector)) # test that, for VectorOfArray with multi-dimensional parent arrays, # `similar` preserves the structure of the parent array From fd61439b5cbd95d81eb164f411f0920fca6fbf6a Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 6 May 2024 00:31:13 -0500 Subject: [PATCH 06/11] test that broadcast retains parent axes for multidim VoA --- test/basic_indexing.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/basic_indexing.jl b/test/basic_indexing.jl index a08a7e61..c2053159 100644 --- a/test/basic_indexing.jl +++ b/test/basic_indexing.jl @@ -252,8 +252,9 @@ foo!(u_vector) @test all(vec(u_matrix) .≈ vec(u_vector)) # test that, for VectorOfArray with multi-dimensional parent arrays, -# `similar` preserves the structure of the parent array +# broadcast and `similar` preserve the structure of the parent array @test typeof(parent(similar(u_matrix))) == typeof(parent(u_matrix)) +@test typeof(parent((x->x).(u_matrix))) == typeof(parent(u_matrix)) # test efficiency num_allocs = @allocations foo!(u_matrix) From 2973fc61ec938f1a027027874a1060999382e601 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 6 May 2024 00:33:06 -0500 Subject: [PATCH 07/11] restore Base.similar behavior --- src/vector_of_array.jl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 38f60f1c..d5b8ea72 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -712,9 +712,22 @@ Base.eltype(::Type{<:AbstractVectorOfArray{T}}) where {T} = T end end @inline function Base.similar(VA::VectorOfArray, ::Type{T} = eltype(VA)) where {T} - VectorOfArray(similar.(Base.parent(VA), T)) + VectorOfArray([similar(VA[:, i], T) for i in eachindex(VA.u)]) end +# for VectorOfArray with multi-dimensional parent arrays of arrays where all elements are the same type +function Base.similar(vec::VectorOfArray{ + T, N, AT}) where {T, N, AT <: AbstractArray{<:AbstractArray{T}}} + return VectorOfArray(similar.(Base.parent(vec))) +end + +# special-case when the multi-dimensional parent array is just an AbstractVector (call the old method) +function Base.similar(vec::VectorOfArray{ + T, N, AT}) where {T, N, AT <: AbstractVector{<:AbstractArray{T}}} + return Base.similar(vec, eltype(vec)) +end + + # fill! # For DiffEqArray it ignores ts and fills only u function Base.fill!(VA::AbstractVectorOfArray, x) From 6549aaa1afba6a3a82203c06c1d2f3f89f2eb87e Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 6 May 2024 00:33:22 -0500 Subject: [PATCH 08/11] add broadcast capabilities for multdim VoA --- src/vector_of_array.jl | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index d5b8ea72..ebb022cd 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -840,12 +840,37 @@ end # make vectorofarrays broadcastable so they aren't collected Broadcast.broadcastable(x::AbstractVectorOfArray) = x +# recurse through broadcast arguments and return a parent array for +# the first VoA or DiffEqArray in the bc arguments +function find_VoA_parent(args) + arg = Base.first(args) + if arg isa AbstractDiffEqArray + # if first(args) is a DiffEqArray, use the underlying + # field `u` of DiffEqArray as a parent array. + return arg.u + elseif arg isa AbstractVectorOfArray + return parent(arg) + else + return find_VoA_parent(Base.tail(args)) + end +end + @inline function Base.copy(bc::Broadcast.Broadcasted{<:VectorOfArrayStyle}) bc = Broadcast.flatten(bc) - N = narrays(bc) - VectorOfArray(map(1:N) do i - copy(unpack_voa(bc, i)) - end) + + parent = find_VoA_parent(bc.args) + + if parent isa AbstractVector + # this is the default behavior in v3.15.0 + N = narrays(bc) + return VectorOfArray(map(1:N) do i + copy(unpack_voa(bc, i)) + end) + else # if parent isa AbstractArray + return VectorOfArray(map(enumerate(Iterators.product(axes(parent)...))) do (i, _) + copy(unpack_voa(bc, i)) + end) + end end for (type, N_expr) in [ From f4675f20e941e502a7d3499d287ddbc55c4fc943 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 6 May 2024 00:36:44 -0500 Subject: [PATCH 09/11] formatting --- src/vector_of_array.jl | 72 +++++++++++++++++++++++------------------- test/basic_indexing.jl | 4 +-- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 2a4ad355..ff2e44c3 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -29,6 +29,7 @@ returns a vector of the series for each component, that is, `A[i,:]` for each `i A plot recipe is provided, which plots the `A[i,:]` series. There is also support for `VectorOfArray` constructed from multi-dimensional arrays + ```julia VectorOfArray(u::AbstractArray{AT}) where {T, N, AT <: AbstractArray{T, N}} ``` @@ -351,48 +352,53 @@ Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::NotSymboli end struct ParameterIndexingError <: Exception - sym + sym::Any end function Base.showerror(io::IO, pie::ParameterIndexingError) - print(io, "Indexing with parameters is deprecated. Use `getp(A, $(pie.sym))` for parameter indexing.") + print(io, + "Indexing with parameters is deprecated. Use `getp(A, $(pie.sym))` for parameter indexing.") end # Symbolic Indexing Methods for (symtype, elsymtype, valtype, errcheck) in [ - (ScalarSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, Any, :(is_parameter(A, sym))), - (ArraySymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, Any, :(is_parameter(A, sym))), - (NotSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, Union{<:Tuple, <:AbstractArray}, - :(all(x -> is_parameter(A, x), sym))), + (ScalarSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, + Any, :(is_parameter(A, sym))), + (ArraySymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, + Any, :(is_parameter(A, sym))), + (NotSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, + Union{<:Tuple, <:AbstractArray}, + :(all(x -> is_parameter(A, x), sym))) ] -@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, - ::$elsymtype, sym::$valtype) - if $errcheck - throw(ParameterIndexingError(sym)) + @eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, + ::$elsymtype, sym::$valtype) + if $errcheck + throw(ParameterIndexingError(sym)) + end + getu(A, sym)(A) end - getu(A, sym)(A) -end -@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, - ::$elsymtype, sym::$valtype, arg) - if $errcheck - throw(ParameterIndexingError(sym)) + @eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, + ::$elsymtype, sym::$valtype, arg) + if $errcheck + throw(ParameterIndexingError(sym)) + end + getu(A, sym)(A, arg) end - getu(A, sym)(A, arg) -end -@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, - ::$elsymtype, sym::$valtype, arg::Union{AbstractArray{Int}, AbstractArray{Bool}}) - if $errcheck - throw(ParameterIndexingError(sym)) + @eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, + ::$elsymtype, sym::$valtype, arg::Union{ + AbstractArray{Int}, AbstractArray{Bool}}) + if $errcheck + throw(ParameterIndexingError(sym)) + end + getu(A, sym).((A,), arg) end - getu(A, sym).((A,), arg) -end -@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, - ::$elsymtype, sym::$valtype, ::Colon) - if $errcheck - throw(ParameterIndexingError(sym)) + @eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, + ::$elsymtype, sym::$valtype, ::Colon) + if $errcheck + throw(ParameterIndexingError(sym)) + end + getu(A, sym)(A) end - getu(A, sym)(A) -end end Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::ScalarSymbolic, @@ -410,8 +416,9 @@ Base.@propagate_inbounds function Base.getindex(A::AbstractVectorOfArray, _arg, elsymtype = symbolic_type(eltype(_arg)) if symtype == NotSymbolic() && elsymtype == NotSymbolic() - if _arg isa Union{Tuple, AbstractArray} && any(x -> symbolic_type(x) != NotSymbolic(), _arg) - _getindex(A, symtype, elsymtype, _arg, args...) + if _arg isa Union{Tuple, AbstractArray} && + any(x -> symbolic_type(x) != NotSymbolic(), _arg) + _getindex(A, symtype, elsymtype, _arg, args...) else _getindex(A, symtype, _arg, args...) end @@ -727,7 +734,6 @@ function Base.similar(vec::VectorOfArray{ return Base.similar(vec, eltype(vec)) end - # fill! # For DiffEqArray it ignores ts and fills only u function Base.fill!(VA::AbstractVectorOfArray, x) diff --git a/test/basic_indexing.jl b/test/basic_indexing.jl index c2053159..a71100b3 100644 --- a/test/basic_indexing.jl +++ b/test/basic_indexing.jl @@ -248,13 +248,13 @@ function foo!(u) end foo!(u_matrix) foo!(u_vector) -@test all(u_matrix .== [3, 10]) +@test all(u_matrix .== [3, 10]) @test all(vec(u_matrix) .≈ vec(u_vector)) # test that, for VectorOfArray with multi-dimensional parent arrays, # broadcast and `similar` preserve the structure of the parent array @test typeof(parent(similar(u_matrix))) == typeof(parent(u_matrix)) -@test typeof(parent((x->x).(u_matrix))) == typeof(parent(u_matrix)) +@test typeof(parent((x -> x).(u_matrix))) == typeof(parent(u_matrix)) # test efficiency num_allocs = @allocations foo!(u_matrix) From a0770e436dd3492abfb790ed2ddecd32577ffada Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 6 May 2024 00:39:37 -0500 Subject: [PATCH 10/11] Revert "formatting" This reverts commit f4675f20e941e502a7d3499d287ddbc55c4fc943. --- src/vector_of_array.jl | 72 +++++++++++++++++++----------------------- test/basic_indexing.jl | 4 +-- 2 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index ff2e44c3..2a4ad355 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -29,7 +29,6 @@ returns a vector of the series for each component, that is, `A[i,:]` for each `i A plot recipe is provided, which plots the `A[i,:]` series. There is also support for `VectorOfArray` constructed from multi-dimensional arrays - ```julia VectorOfArray(u::AbstractArray{AT}) where {T, N, AT <: AbstractArray{T, N}} ``` @@ -352,53 +351,48 @@ Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::NotSymboli end struct ParameterIndexingError <: Exception - sym::Any + sym end function Base.showerror(io::IO, pie::ParameterIndexingError) - print(io, - "Indexing with parameters is deprecated. Use `getp(A, $(pie.sym))` for parameter indexing.") + print(io, "Indexing with parameters is deprecated. Use `getp(A, $(pie.sym))` for parameter indexing.") end # Symbolic Indexing Methods for (symtype, elsymtype, valtype, errcheck) in [ - (ScalarSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, - Any, :(is_parameter(A, sym))), - (ArraySymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, - Any, :(is_parameter(A, sym))), - (NotSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, - Union{<:Tuple, <:AbstractArray}, - :(all(x -> is_parameter(A, x), sym))) + (ScalarSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, Any, :(is_parameter(A, sym))), + (ArraySymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, Any, :(is_parameter(A, sym))), + (NotSymbolic, SymbolicIndexingInterface.SymbolicTypeTrait, Union{<:Tuple, <:AbstractArray}, + :(all(x -> is_parameter(A, x), sym))), ] - @eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, - ::$elsymtype, sym::$valtype) - if $errcheck - throw(ParameterIndexingError(sym)) - end - getu(A, sym)(A) +@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, + ::$elsymtype, sym::$valtype) + if $errcheck + throw(ParameterIndexingError(sym)) end - @eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, - ::$elsymtype, sym::$valtype, arg) - if $errcheck - throw(ParameterIndexingError(sym)) - end - getu(A, sym)(A, arg) + getu(A, sym)(A) +end +@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, + ::$elsymtype, sym::$valtype, arg) + if $errcheck + throw(ParameterIndexingError(sym)) end - @eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, - ::$elsymtype, sym::$valtype, arg::Union{ - AbstractArray{Int}, AbstractArray{Bool}}) - if $errcheck - throw(ParameterIndexingError(sym)) - end - getu(A, sym).((A,), arg) + getu(A, sym)(A, arg) +end +@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, + ::$elsymtype, sym::$valtype, arg::Union{AbstractArray{Int}, AbstractArray{Bool}}) + if $errcheck + throw(ParameterIndexingError(sym)) end - @eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, - ::$elsymtype, sym::$valtype, ::Colon) - if $errcheck - throw(ParameterIndexingError(sym)) - end - getu(A, sym)(A) + getu(A, sym).((A,), arg) +end +@eval Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::$symtype, + ::$elsymtype, sym::$valtype, ::Colon) + if $errcheck + throw(ParameterIndexingError(sym)) end + getu(A, sym)(A) +end end Base.@propagate_inbounds function _getindex(A::AbstractDiffEqArray, ::ScalarSymbolic, @@ -416,9 +410,8 @@ Base.@propagate_inbounds function Base.getindex(A::AbstractVectorOfArray, _arg, elsymtype = symbolic_type(eltype(_arg)) if symtype == NotSymbolic() && elsymtype == NotSymbolic() - if _arg isa Union{Tuple, AbstractArray} && - any(x -> symbolic_type(x) != NotSymbolic(), _arg) - _getindex(A, symtype, elsymtype, _arg, args...) + if _arg isa Union{Tuple, AbstractArray} && any(x -> symbolic_type(x) != NotSymbolic(), _arg) + _getindex(A, symtype, elsymtype, _arg, args...) else _getindex(A, symtype, _arg, args...) end @@ -734,6 +727,7 @@ function Base.similar(vec::VectorOfArray{ return Base.similar(vec, eltype(vec)) end + # fill! # For DiffEqArray it ignores ts and fills only u function Base.fill!(VA::AbstractVectorOfArray, x) diff --git a/test/basic_indexing.jl b/test/basic_indexing.jl index a71100b3..c2053159 100644 --- a/test/basic_indexing.jl +++ b/test/basic_indexing.jl @@ -248,13 +248,13 @@ function foo!(u) end foo!(u_matrix) foo!(u_vector) -@test all(u_matrix .== [3, 10]) +@test all(u_matrix .== [3, 10]) @test all(vec(u_matrix) .≈ vec(u_vector)) # test that, for VectorOfArray with multi-dimensional parent arrays, # broadcast and `similar` preserve the structure of the parent array @test typeof(parent(similar(u_matrix))) == typeof(parent(u_matrix)) -@test typeof(parent((x -> x).(u_matrix))) == typeof(parent(u_matrix)) +@test typeof(parent((x->x).(u_matrix))) == typeof(parent(u_matrix)) # test efficiency num_allocs = @allocations foo!(u_matrix) From b7f9c84e6935e68e93cf0d0b1533383dfbf52256 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Mon, 6 May 2024 00:40:16 -0500 Subject: [PATCH 11/11] revert to old Base.similar behavior --- 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 2a4ad355..ebb022cd 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -712,7 +712,7 @@ Base.eltype(::Type{<:AbstractVectorOfArray{T}}) where {T} = T end end @inline function Base.similar(VA::VectorOfArray, ::Type{T} = eltype(VA)) where {T} - VectorOfArray(similar.(Base.parent(VA), T)) + VectorOfArray([similar(VA[:, i], T) for i in eachindex(VA.u)]) end # for VectorOfArray with multi-dimensional parent arrays of arrays where all elements are the same type