Skip to content

Add precompile workload for Dual and SubArray broadcast operations#858

Merged
ChrisRackauckas merged 2 commits intoSciML:masterfrom
ChrisRackauckas-Claude:precompile-subarray-dual-broadcast
Mar 1, 2026
Merged

Add precompile workload for Dual and SubArray broadcast operations#858
ChrisRackauckas merged 2 commits intoSciML:masterfrom
ChrisRackauckas-Claude:precompile-subarray-dual-broadcast

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

The extension already handled Dual number operations for sensitivity analysis (implicit differentiation via nonlinearsolve_∂f_∂p/nonlinearsolve_∂f_∂u) but had no precompilation workload, causing broadcast compilation overhead at runtime for nonlinear functions using views.

What's precompiled:

  • Scalar Dual operations: arithmetic (+, -, *, /, ^, negation, abs), math functions (exp, log, sin, cos, tan, sqrt, cbrt, asin, acos, atan, sinh, cosh, tanh), comparisons/predicates, min/max, conversion (zero, one, float, ForwardDiff.value, ForwardDiff.partials)
  • Vector{Dual} operations: broadcast (.+, .-, .*, ./, .^), in-place broadcast, reductions (sum, sum(abs2, ...), maximum(abs, ...)), LinearAlgebra (dot, norm), copy, fill!
  • SubArray broadcast patterns (Float64 and Dual): multiple patterns mimicking common nonlinear residual functions (linear combinations of views, subtraction chains with power, scaled power, simple assignment/scaling/element-wise ops/negation)

Test plan

  • Pkg.test("NonlinearSolveBase") passes (all 16 tests)
  • Extension loads and precompiles successfully
  • Runic formatting check passes
  • CI passes

🤖 Generated with Claude Code

Add a `PrecompileTools.@compile_workload` block to
`NonlinearSolveBaseForwardDiffExt` that exercises common scalar, array,
and SubArray operations on ForwardDiff Dual numbers. This mirrors the
approach from DiffEqBase.jl PR #1291.

The extension already handled Dual number operations for sensitivity
analysis but had no precompilation, causing broadcast compilation
overhead at runtime for nonlinear functions using views.

What's precompiled:
- Scalar Dual operations: arithmetic, math functions, comparisons
- Vector{Dual} operations: broadcast, reductions, LinearAlgebra
- SubArray broadcast patterns: common nonlinear residual function
  patterns using views

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
NewtonRaphson on the Generalized Rosenbrock function (problem 1) was
marked as @test_broken but now passes on all platforms and Julia
versions. Remove it from the broken_tests list.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
@ChrisRackauckas ChrisRackauckas merged commit 3256777 into SciML:master Mar 1, 2026
117 of 119 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