Improve FunctionOperator inverse error#368
Merged
ChrisRackauckas merged 1 commit intoMay 5, 2026
Merged
Conversation
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.
Summary
Closes #251.
This PR improves the error users see when applying inverse operations to a
FunctionOperatorconstructed withoutop_inverse. Instead of falling through to aNothingcallableMethodError, the inverse paths now throw anArgumentErrorthat tells users to provideop_inversewhen constructing the operator.Root Cause
has_ldivalready reported that aFunctionOperatorwithoutop_inversecannot be divided by, but the\andldiv!implementations calledL.op_inversedirectly. Whenop_inverse === nothing, that produced the opaqueobjects of type Nothing are not callablefailure from issue #251.Changes
_assert_has_inverseguard forFunctionOperatorinverse operations.F \ v,ldiv!(w, F, v), andldiv!(F, v).ArgumentErrorand mentionop_inverse.Type Stability / Allocations
The success path keeps the existing public API and inverse dispatch shape. The added guard is a small predicate check before calling the already-stored inverse function; the error message allocation only occurs on the missing-inverse error path.
Validation
julia --project=. -e 'using Pkg; Pkg.test(; test_args=["func.jl"])'passed with823passing tests and2broken tests.