Skip to content

Preserve wrapper array types in LazyBufferCache when size matches#157

Merged
ChrisRackauckas merged 3 commits intoSciML:masterfrom
ChrisRackauckas-Claude:fix/lazybuffercache-wrapper-types
Jan 28, 2026
Merged

Preserve wrapper array types in LazyBufferCache when size matches#157
ChrisRackauckas merged 3 commits intoSciML:masterfrom
ChrisRackauckas-Claude:fix/lazybuffercache-wrapper-types

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

  • similar(u, size(u)) strips wrapper types like ComponentArray, returning a plain Array. This PR uses similar(u) when the requested size matches the original array size, which preserves wrapper types.
  • Updates the type assertion helper (_buffer_type) to match the new allocation behavior.
  • Adds a regression test with a custom wrapper array type that mimics ComponentArray behavior.

Motivation

Fixes part of SciML/SciMLSensitivity.jl#1287 where EnzymeVJP with ComponentArray-based ODEs crashes because LazyBufferCache strips the ComponentArray wrapper, causing the ODE function to receive a plain Vector instead.

Test plan

  • All existing PreallocationTools tests pass
  • New regression test verifies wrapper type preservation
  • Verified fix works end-to-end with SciMLSensitivity + ComponentArrays + EnzymeVJP

🤖 Generated with Claude Code

`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>
@ChrisRackauckas ChrisRackauckas merged commit edcd0b6 into SciML:master Jan 28, 2026
12 of 16 checks passed
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>
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>
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.

3 participants