Skip to content

Improve FunctionOperator inverse error#368

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
AshtonSBradley:function-operator-inverse-error
May 5, 2026
Merged

Improve FunctionOperator inverse error#368
ChrisRackauckas merged 1 commit into
SciML:masterfrom
AshtonSBradley:function-operator-inverse-error

Conversation

@AshtonSBradley
Copy link
Copy Markdown
Contributor

Summary

Closes #251.

This PR improves the error users see when applying inverse operations to a FunctionOperator constructed without op_inverse. Instead of falling through to a Nothing callable MethodError, the inverse paths now throw an ArgumentError that tells users to provide op_inverse when constructing the operator.

Root Cause

has_ldiv already reported that a FunctionOperator without op_inverse cannot be divided by, but the \ and ldiv! implementations called L.op_inverse directly. When op_inverse === nothing, that produced the opaque objects of type Nothing are not callable failure from issue #251.

Changes

  • Add an internal _assert_has_inverse guard for FunctionOperator inverse operations.
  • Apply the guard to both out-of-place and in-place inverse paths: F \ v, ldiv!(w, F, v), and ldiv!(F, v).
  • Add regression tests confirming missing inverses throw ArgumentError and mention op_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 with 823 passing tests and 2 broken tests.

@AshtonSBradley AshtonSBradley marked this pull request as ready for review May 5, 2026 07:54
@ChrisRackauckas ChrisRackauckas merged commit cbc7312 into SciML:master May 5, 2026
14 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.

Better error report for dividing by FunctionOperator with no inverse

2 participants