Repository navigation
Fix SplitFunction _func_cache aliasing u0 - #1520
Merged
ChrisRackauckas merged 1 commit intoAug 26, 2026
Merged
Conversation
This was referenced Aug 26, 2026
Closed
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.
Fixes #1519.
SplitODEProblemand the bareODEProblem(::SplitFunction, ...)path build the in-place scratch cache asDiffCache(u0), and DiffCache keeps the passed array as its primary buffer, so any direct combined callf(du, u, p, t)evaluatesf1intoprob.u0's memory. Withu === u0the result itself is wrong (f2reads the statef1just overwrote); with any otheruthe result is right but the stored initial condition is silently replaced. Details and history in #1519.The change is
DiffCache(copy(u0))at both construction sites, pluscopy(u0)in the non-number-array fallback, which was handing outu0itself as the buffer. Only the buffer's identity changes, so the dual-cache path that #1106 added for OrdinaryDiffEq#2719 is untouched.Test added to problem_building_test.jl: the cache must not alias
u0, the combined call atu0returnsf1 + f2correctly, andu0is bit-identical after combined calls atu0and at a different state, for both construction paths. The new test fails on master (du == [4.0, 8.0]instead of[3.0, 6.0],u0mutated) and passes with the fix. Also re-verified the #2719 downstream case (Rodas5P on a split problem, ForwardDiff Jacobian through the cache) and solve-path equivalence against the joined problem.AI Disclosure
Claude assisted with this work.