Skip to content

Commit 92fc778

Browse files
refactor: fix VectorOfArray arithmetic
1 parent 7996890 commit 92fc778

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/vector_of_array.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,17 @@ function Base.isapprox(A::AbstractArray, B::AbstractVectorOfArray; kwargs...)
476476
end
477477

478478
for op in [:(Base.:-), :(Base.:+)]
479-
@eval function ($op)(A::AbstractVectorOfArray,
480-
B::Union{AbstractVectorOfArray, AbstractArray})
479+
@eval function ($op)(A::AbstractVectorOfArray, B::AbstractVectorOfArray)
481480
($op).(A, B)
482481
end
483-
@eval function ($op)(A::AbstractArray, B::AbstractVectorOfArray)
484-
($op).(A, B)
482+
@eval Base.@propagate_inbounds function ($op)(A::AbstractVectorOfArray,
483+
B::AbstractArray)
484+
@boundscheck length(A) == length(B)
485+
VectorOfArray([($op).(a, b) for (a, b) in zip(A, B)])
486+
end
487+
@eval Base.@propagate_inbounds function ($op)(A::AbstractArray, B::AbstractVectorOfArray)
488+
@boundscheck length(A) == length(B)
489+
VectorOfArray([($op).(a, b) for (a, b) in zip(A, B)])
485490
end
486491
end
487492

@@ -503,6 +508,7 @@ end
503508

504509
# Tools for creating similar objects
505510
Base.eltype(::VectorOfArray{T}) where {T} = T
511+
# TODO: Is there a better way to do this?
506512
@inline function Base.similar(VA::VectorOfArray, args...)
507513
return Base.similar(ones(eltype(VA)), args...)
508514
end

0 commit comments

Comments
 (0)