Improve ForwardDiff Dual N=0 handling with clear ArgumentError and regression test#927
Open
AJ0070 wants to merge 3 commits intoSciML:mainfrom
Open
Improve ForwardDiff Dual N=0 handling with clear ArgumentError and regression test#927AJ0070 wants to merge 3 commits intoSciML:mainfrom
AJ0070 wants to merge 3 commits intoSciML:mainfrom
Conversation
devmotion
reviewed
Mar 26, 2026
ext/LinearSolveForwardDiffExt.jl
Outdated
| if nA === 0 || nb === 0 | ||
| throw(ArgumentError( | ||
| "LinearSolve does not support ForwardDiff.Dual values with zero partials (N = 0). " * | ||
| "Use primal values with ForwardDiff.value(...) or construct Dual numbers with at least one partial." |
Member
There was a problem hiding this comment.
ForwardDiff.value is internal, but more importantly it's also generally unsafe and hence usually one should use ForwardDiff.value(T, x) instead (which is internal as well though, so I don't think it belongs into a user-facing error message).
Contributor
Author
There was a problem hiding this comment.
Then I’ll just replace it with a note advising not to use non-Dual numbers.
Member
There was a problem hiding this comment.
Yeah I don't think we should ever tell users to use ForwardDiff.value 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 😅 that's just asking for punishment.
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.
Checklist
What changed
ArgumentErrormessage to make the failure mode explicit and actionable.Additional context
This follows discussion on #914: zero-partial Duals are ill-formed for the intended AD path, but users should still get a clear error instead of an internal failure.
AI Disclosure: Used codex