From 3e4a22f553d5c3b3f4feea1e423fc3809041ae13 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Fri, 22 Dec 2023 15:44:35 +0530 Subject: [PATCH 1/2] fix: allow setting VoA of SArray using scalars --- src/vector_of_array.jl | 7 ++++++- test/interface_tests.jl | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 933c542d..b05c646b 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -681,7 +681,12 @@ end copyto!(dest[:, i], unpack_voa(bc, i)) else unpacked = unpack_voa(bc, i) - dest[:, i] = unpacked.f(unpacked.args...) + value = unpacked.f(unpacked.args...) + dest[:, i] = if value isa Number && dest[:, i] isa AbstractArray + fill(value, StaticArraysCore.similar_type(dest[:, i])) + else + value + end end end dest diff --git a/test/interface_tests.jl b/test/interface_tests.jl index cba4727a..4b2a9e35 100644 --- a/test/interface_tests.jl +++ b/test/interface_tests.jl @@ -149,3 +149,6 @@ function f!(z,zz) end f!(z,zz) @test (@allocated f!(z,zz)) == 0 + +z .= 0.1 +@test z == VectorOfArray([fill(0.1, SVector{2, Float64}), fill(0.1, SVector{2, Float64})]) From 2939bc3bef80fd464a66fd17a5083099a2b9847e Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Fri, 22 Dec 2023 08:18:28 -0500 Subject: [PATCH 2/2] Update interface_tests.jl --- test/interface_tests.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/interface_tests.jl b/test/interface_tests.jl index 4b2a9e35..985de004 100644 --- a/test/interface_tests.jl +++ b/test/interface_tests.jl @@ -152,3 +152,9 @@ f!(z,zz) z .= 0.1 @test z == VectorOfArray([fill(0.1, SVector{2, Float64}), fill(0.1, SVector{2, Float64})]) + +function f2!(z) + z .= 0.1 +end +f2!(z) +@test (@allocated f2!(z)) == 0