Skip to content

Commit

Permalink
fix: fix broadcasted assignment to VOA of StaticArrays
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Dec 19, 2023
1 parent 6e0aa08 commit 35b32ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/vector_of_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ end
bc = Broadcast.flatten(bc)
N = narrays(bc)
@inbounds for i in 1:N
if dest[:, i] isa AbstractArray
if dest[:, i] isa AbstractArray && !isa(dest[:, i], StaticArraysCore.SArray)

Check warning on line 664 in src/vector_of_array.jl

View check run for this annotation

Codecov / codecov/patch

src/vector_of_array.jl#L664

Added line #L664 was not covered by tests
copyto!(dest[:, i], unpack_voa(bc, i))
else
dest[:, i] = copy(unpack_voa(bc, i))
Expand Down
8 changes: 8 additions & 0 deletions test/interface_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,11 @@ u = VectorOfArray([fill(2, SVector{2, Float64}), ones(SVector{2, Float64})])
@test typeof(zero(u)) <: typeof(u)
resize!(u,3)
@test pointer(u) === pointer(u.u)

# Ensure broadcast (including assignment) works with StaticArrays
x = VectorOfArray([fill(2, SVector{2, Float64}), ones(SVector{2, Float64})])
y = VectorOfArray([fill(2, SVector{2, Float64}), ones(SVector{2, Float64})])
z = VectorOfArray([zeros(SVector{2, Float64}), zeros(SVector{2, Float64})])
z .= x .+ y

@test z == VectorOfArray([fill(4, SVector{2, Float64}), fill(2, SVector{2, Float64})])

0 comments on commit 35b32ac

Please sign in to comment.