Preserve wrapper array types in LazyBufferCache when size matches#157
Merged
ChrisRackauckas merged 3 commits intoSciML:masterfrom Jan 28, 2026
Merged
Conversation
`similar(u, size(u))` strips wrapper types like ComponentArray, returning a plain Array. Use `similar(u)` when the requested size matches the original array size, which preserves wrapper types. This fixes SciML/SciMLSensitivity.jl#1287 where EnzymeVJP with ComponentArray-based ODEs would crash because LazyBufferCache stripped the ComponentArray wrapper, causing the ODE function to receive a plain Vector instead. Also updates the type assertion to match the new allocation behavior. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Merged
3 tasks
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Jan 28, 2026
Requires PreallocationTools v1.1.1 which preserves wrapper array types in LazyBufferCache (SciML/PreallocationTools.jl#157). Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
This was referenced Jan 28, 2026
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/SciMLSensitivity.jl
that referenced
this pull request
Jan 30, 2026
Requires PreallocationTools v1.1.1 which preserves wrapper array types in LazyBufferCache (SciML/PreallocationTools.jl#157). Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.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
similar(u, size(u))strips wrapper types likeComponentArray, returning a plainArray. This PR usessimilar(u)when the requested size matches the original array size, which preserves wrapper types._buffer_type) to match the new allocation behavior.ComponentArraybehavior.Motivation
Fixes part of SciML/SciMLSensitivity.jl#1287 where
EnzymeVJPwithComponentArray-based ODEs crashes becauseLazyBufferCachestrips theComponentArraywrapper, causing the ODE function to receive a plainVectorinstead.Test plan
🤖 Generated with Claude Code