Repository navigation
Skip O(length) sentinel scans over constant numeric array values - #5312
Merged
AayushSabharwal merged 2 commits intoOct 28, 2026
Merged
Conversation
build_operating_point, AtomicArrayDictSubstitutionWrapper lookups and narrow_buffer_type walked every element of constant numeric arrays (e.g. a SparseMatrixCSC parameter) through symbolic getindex or dense iteration, which is O(length) and quadratic for an NxN matrix. Constant arrays of plain numbers cannot hold the sentinel, so they are now skipped; arrays that can hold it behave as before. Agent-Harness: Claude Code 2.1.310 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
An empty array contributes no elements to promotion in the original loop, so the concrete-eltype shortcut must not let its eltype widen the result. Agent-Harness: Claude Code 2.1.310 Agent-Model: claude-sonnet-5-5 Agent-Session: de59b94f-0227-49ea-adb5-b158639dad0b Agent-Review: unreviewed Co-authored-by: Claude Code <agent@noreply.juliahub.com>
AayushSabharwal
approved these changes
Oct 27, 2026
ChrisRackauckas
referenced
this pull request
Oct 30, 2026
Hold signals disconnected by loop openings at their loop-closed values
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.
Large constant numeric array values, for example a
SparseMatrixCSCparameter withtunable = false, made problem construction quadratic in the matrix dimension. Three places walked every element of such values:build_operating_pointandAtomicArrayDictSubstitutionWrapperlookups scanned them through symbolicgetindex, andnarrow_buffer_typefor a vector of arrays iterated them densely, so an N x N sparse matrix cost N^2 steps.COMMON_SENTINELorCOMMON_NOTHING, so a new helperis_numeric_const_arraylets both sentinel scans skip it.narrow_buffer_typeuseseltype(arr)directly when the array is non-empty and the eltype is concrete. This gives the same promoted type, sincetypeof(x) == eltype(arr)for every element of a concretely typed array. Empty arrays still take the original loop so they contribute nothing to promotion.Anyarrays) take the unchanged path.Benchmark (
DAEProblemconstruction with a tridiagonalSparseMatrixCSC{Float64,Int}non-tunable parameter, a denseFp[1:N]parameter andFp ~ D(u) + Kp*u; median of 3 after warm-up):This is the "operating-point sentinel scan" item of the FiniteElementMethod.jl upstream-blocker list (quadratic scan of opaque/sparse parameters). It is independent of #5121 (array
D(u)binding in implicit DAE codegen) and #5190 (evaluate_varmap!).Tests: new testsets in
lib/ModelingToolkitBase/test/initial_values.jlcheck that constant sparse and dense values pass throughbuild_operating_pointunchanged, that sentinels inside symbolic array values are still replaced withCOMMON_NOTHING, and thatnarrow_buffer_typeignores empty arrays when promoting. Initialization group passes; InterfaceI has one failure,components.jl:446"Causal connections generate causal equations", which also fails on master.Codex review (two rounds) approved. One minor remaining note: the
AADSubWrappershortcut does not consultdd.default, so a wrapper deliberately constructed with a numeric default such asConst(0.0)would no longer treat an array containing that value as "contains the default". No in-repo caller constructs one that way (all use the default sentinel).🤖 Posted by an AI agent · harness: Claude Code 2.1.310 · model: claude-sonnet-5-5
Review: unreviewed
Session: de59b94f-0227-49ea-adb5-b158639dad0b