From 23549bdc7c265ef593303aa24e290bf9afcfe106 Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Sun, 27 Oct 2024 17:10:05 -1000 Subject: [PATCH 1/3] Fix --- src/vector_of_array.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index 352d4ae4..a9b72e5f 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -906,7 +906,7 @@ for (type, N_expr) in [ unpacked = unpack_voa(bc, i) arr_type = StaticArraysCore.similar_type(dest[:, i]) dest[:, i] = if length(unpacked) == 1 - fill(copy(unpacked), arr_type) + arr_type(unpacked[1]) else arr_type(unpacked[j] for j in eachindex(unpacked)) end From f362c88f9a199cbdeeb1bd8c300b61a07d95c32a Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Sun, 27 Oct 2024 17:30:36 -1000 Subject: [PATCH 2/3] Add test --- test/copy_static_array_test.jl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/copy_static_array_test.jl b/test/copy_static_array_test.jl index 76b9668b..c0aea1d2 100644 --- a/test/copy_static_array_test.jl +++ b/test/copy_static_array_test.jl @@ -82,3 +82,23 @@ b = recursivecopy(a) @test a[1] == b[1] a[1] *= 2 @test a[1] != b[1] + +# Broadcasting when SVector{1} +a = [SVector(0.0) for _ in 1:2] +a_voa = VectorOfArray(a) +b_voa = copy(a_voa) +a_voa[1] = SVector(1.0) +a_voa[2] = SVector(1.0) +@. b_voa = a_voa +@test b_voa[1] == a_voa[1] +@test b_voa[2] == a_voa[2] + +# Broadcasting when SVector{N} where N > 1 +a = [SVector(0.0, 0.0) for _ in 1:2] +a_voa = VectorOfArray(a) +b_voa = copy(a_voa) +a_voa[1] = SVector(1.0, 1.0) +a_voa[2] = SVector(1.0, 1.0) +@. b_voa = a_voa +@test b_voa[1] == a_voa[1] +@test b_voa[2] == a_voa[2] From baa2af98f698ebd0959c36bc5723719a332c4dc8 Mon Sep 17 00:00:00 2001 From: huiyuxie Date: Mon, 28 Oct 2024 10:46:46 -1000 Subject: [PATCH 3/3] Fix again --- src/vector_of_array.jl | 4 +++- test/copy_static_array_test.jl | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/vector_of_array.jl b/src/vector_of_array.jl index a9b72e5f..eef8625f 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -905,8 +905,10 @@ for (type, N_expr) in [ else unpacked = unpack_voa(bc, i) arr_type = StaticArraysCore.similar_type(dest[:, i]) - dest[:, i] = if length(unpacked) == 1 + dest[:, i] = if length(unpacked) == 1 && length(dest[:, i]) == 1 arr_type(unpacked[1]) + elseif length(unpacked) == 1 + fill(copy(unpacked), arr_type) else arr_type(unpacked[j] for j in eachindex(unpacked)) end diff --git a/test/copy_static_array_test.jl b/test/copy_static_array_test.jl index c0aea1d2..ffcfa52c 100644 --- a/test/copy_static_array_test.jl +++ b/test/copy_static_array_test.jl @@ -83,7 +83,7 @@ b = recursivecopy(a) a[1] *= 2 @test a[1] != b[1] -# Broadcasting when SVector{1} +# Broadcasting when SVector{N} where N = 1 a = [SVector(0.0) for _ in 1:2] a_voa = VectorOfArray(a) b_voa = copy(a_voa) @@ -93,6 +93,12 @@ a_voa[2] = SVector(1.0) @test b_voa[1] == a_voa[1] @test b_voa[2] == a_voa[2] +a = [SVector(0.0) for _ in 1:2] +a_voa = VectorOfArray(a) +a_voa .= 1.0 +@test a_voa[1] == SVector(1.0) +@test a_voa[2] == SVector(1.0) + # Broadcasting when SVector{N} where N > 1 a = [SVector(0.0, 0.0) for _ in 1:2] a_voa = VectorOfArray(a) @@ -102,3 +108,9 @@ a_voa[2] = SVector(1.0, 1.0) @. b_voa = a_voa @test b_voa[1] == a_voa[1] @test b_voa[2] == a_voa[2] + +a = [SVector(0.0, 0.0) for _ in 1:2] +a_voa = VectorOfArray(a) +a_voa .= 1.0 +@test a_voa[1] == SVector(1.0, 1.0) +@test a_voa[2] == SVector(1.0, 1.0)