From 273a06565fa2ac48a60ed7cbb9fe0da098cb5daf Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Fri, 17 Apr 2026 09:44:05 -0400 Subject: [PATCH 1/2] Preserve container type in `zero(VectorOfArray)` via `rewrap` `[zero(u) for u in VA.u]` always produces a plain `Vector`, even when `VA.u` is a `StructVector` (from StructArrays.jl). The constructor then fails with `MethodError: Cannot convert Vector{SVector{1,Float64}} to StructVector{...}` because the type parameter `A` is locked to the original container type. Use the existing `rewrap(parent, u)` mechanism (already used by broadcast) to convert the comprehension result back to the original container type. The `StructArrays` extension defines `rewrap(::StructArray, u) = StructArray(u)`, and the fallback is `convert(typeof(parent), u)`. Fixes OrdinaryDiffEq.jl v7 CI failures in OrdinaryDiffEqLowStorageRK and OrdinaryDiffEqSSPRK "VectorOfArray/StructArray compatibility" tests. Co-Authored-By: Chris Rackauckas Co-Authored-By: Claude Opus 4.6 (1M context) --- 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 be0041d5..191a5eb2 100644 --- a/src/vector_of_array.jl +++ b/src/vector_of_array.jl @@ -945,7 +945,7 @@ end function Base.zero(VA::AbstractVectorOfArray) T = typeof(VA) - u_zero = [zero(u) for u in VA.u] + u_zero = rewrap(VA.u, [zero(u) for u in VA.u]) fields = [fname == :u ? u_zero : _copyfield(VA, fname) for fname in fieldnames(T)] return T(fields...) end From 5ddceee8a16106f2a7fb161c29ba724184218bf1 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Fri, 17 Apr 2026 11:05:01 -0400 Subject: [PATCH 2/2] Add test for zero(VectorOfArray) preserving StructArray container type Verifies that the rewrap-based fix correctly returns a VectorOfArray whose .u field is still a StructArray (not a plain Vector) and that all values are zeroed. Co-Authored-By: Chris Rackauckas Co-Authored-By: Claude Sonnet 4.6 --- test/copy_static_array_test.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/copy_static_array_test.jl b/test/copy_static_array_test.jl index 5969c714..5fd42ffe 100644 --- a/test/copy_static_array_test.jl +++ b/test/copy_static_array_test.jl @@ -131,3 +131,13 @@ x_immutablefv = [ImmutableFV(1.0, 2.0)] for vec in [x_staticvector, x_structarray, x_mutablefv, x_immutablefv] @test typeof(similar(VectorOfArray(vec))) === typeof(VectorOfArray(vec)) end + +# Test that zero(VectorOfArray) preserves StructArray container type (via rewrap) +let + sa = StructArray{SVector{2, Float64}}((Float64[1.0, 2.0], Float64[3.0, 4.0])) + voa = VectorOfArray(sa) + z = zero(voa) + @test z.u isa StructArray + @test all(iszero, z.u[1]) + @test all(iszero, z.u[2]) +end