Skip to content

Preserve container type in zero(VectorOfArray) via rewrap#579

Merged
ChrisRackauckas merged 2 commits intoSciML:masterfrom
ChrisRackauckas-Claude:fix-zero-structarray
Apr 17, 2026
Merged

Preserve container type in zero(VectorOfArray) via rewrap#579
ChrisRackauckas merged 2 commits intoSciML:masterfrom
ChrisRackauckas-Claude:fix-zero-structarray

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown
Contributor

Summary

Base.zero(VA::AbstractVectorOfArray) uses [zero(u) for u in VA.u] which always produces a plain Vector, even when VA.u is a StructVector. The constructor then fails:

MethodError: Cannot convert Vector{SVector{1,Float64}} to StructVector{...}

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

ChrisRackauckas and others added 2 commits April 17, 2026 09:44
`[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>
@ChrisRackauckas ChrisRackauckas merged commit fea7a20 into SciML:master Apr 17, 2026
33 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants