From 02501d62cdd2198e83bb736cbf528ca16269e1d5 Mon Sep 17 00:00:00 2001 From: ErikQQY <2283984853@qq.com> Date: Thu, 12 Sep 2024 12:08:00 +0800 Subject: [PATCH] Change to broadcast Signed-off-by: ErikQQY <2283984853@qq.com> --- src/vector_of_array.jl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index a662abf8..f4336df7 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -546,9 +546,7 @@ end function Base.zero(VA::AbstractVectorOfArray) val = copy(VA) - for i in eachindex(VA.u) - val.u[i] = zero(VA.u[i]) - end + val.u = zero.(VA.u) return val end @@ -732,15 +730,15 @@ function Base.similar(vec::VectorOfArray{ end @inline function Base.similar(VA::VectorOfArray, ::Type{T} = eltype(VA)) where {T} - VectorOfArray([similar(VA[:, i], T) for i in eachindex(VA.u)]) + VectorOfArray(similar.(VA.u, T)) end @inline function Base.similar(VA::VectorOfArray, dims::N) where {N <: Number} l = length(VA) if dims <= l - VectorOfArray([similar(VA[:, i]) for i in 1:l]) + VectorOfArray(similar.(VA.u[1:dims])) else - VectorOfArray([[similar(VA[:, i]) for i in 1:l]; [similar(VA.u[end]) for _ in (l+1):dims]]) + VectorOfArray([similar.(VA.u); [similar(VA.u[end]) for _ in (l + 1):dims]]) end end