Preserve container type in zero(VectorOfArray) via rewrap#579
Merged
ChrisRackauckas merged 2 commits intoSciML:masterfrom Apr 17, 2026
Merged
Conversation
`[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 <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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 <accounts@chrisrackauckas.com> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Base.zero(VA::AbstractVectorOfArray)uses[zero(u) for u in VA.u]which always produces a plainVector, even whenVA.uis aStructVector. The constructor then fails:Fix: Wrap with
rewrap(VA.u, ...)— same mechanism already used by broadcast. One-line change.Fixes OrdinaryDiffEq.jl v7 CI (LowStorageRK/SSPRK StructArray compat tests).
🤖 Generated with Claude Code