Skip to content

Commit 67da057

Browse files
committed
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.
1 parent 0b93c51 commit 67da057

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

src/vector_of_array.jl

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -717,19 +717,7 @@ Base.eltype(::Type{<:AbstractVectorOfArray{T}}) where {T} = T
717717
end
718718
end
719719
@inline function Base.similar(VA::VectorOfArray, ::Type{T} = eltype(VA)) where {T}
720-
VectorOfArray([similar(VA[:, i], T) for i in eachindex(VA.u)])
721-
end
722-
723-
# for VectorOfArray with multi-dimensional parent arrays of arrays where all elements are the same type
724-
function Base.similar(vec::VectorOfArray{
725-
T, N, AT}) where {T, N, AT <: AbstractArray{<:AbstractArray{T}}}
726-
return VectorOfArray(similar(Base.parent(vec)))
727-
end
728-
729-
# special-case when the multi-dimensional parent array is just an AbstractVector (call the old method)
730-
function Base.similar(vec::VectorOfArray{
731-
T, N, AT}) where {T, N, AT <: AbstractVector{<:AbstractArray{T}}}
732-
return Base.similar(vec, eltype(vec))
720+
VectorOfArray(similar.(Base.parent(VA), T))
733721
end
734722

735723
# fill!

0 commit comments

Comments
 (0)