Skip to content

Commit

Permalink
Change to broadcast
Browse files Browse the repository at this point in the history
Signed-off-by: ErikQQY <[email protected]>
  • Loading branch information
ErikQQY committed Sep 12, 2024
1 parent c4e0076 commit 02501d6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/vector_of_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 02501d6

Please sign in to comment.