Skip to content

Commit 9c49c99

Browse files
Merge pull request #310 from AayushSabharwal/as/scalar-broadcast
fix: allow setting VoA of SArray using scalars
2 parents 9b152ff + 2939bc3 commit 9c49c99

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/vector_of_array.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,12 @@ end
681681
copyto!(dest[:, i], unpack_voa(bc, i))
682682
else
683683
unpacked = unpack_voa(bc, i)
684-
dest[:, i] = unpacked.f(unpacked.args...)
684+
value = unpacked.f(unpacked.args...)
685+
dest[:, i] = if value isa Number && dest[:, i] isa AbstractArray
686+
fill(value, StaticArraysCore.similar_type(dest[:, i]))
687+
else
688+
value
689+
end
685690
end
686691
end
687692
dest

test/interface_tests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,12 @@ function f!(z,zz)
149149
end
150150
f!(z,zz)
151151
@test (@allocated f!(z,zz)) == 0
152+
153+
z .= 0.1
154+
@test z == VectorOfArray([fill(0.1, SVector{2, Float64}), fill(0.1, SVector{2, Float64})])
155+
156+
function f2!(z)
157+
z .= 0.1
158+
end
159+
f2!(z)
160+
@test (@allocated f2!(z)) == 0

0 commit comments

Comments
 (0)