Skip to content

Domain check rejects ForwardDiff 1.x Duals at the interval bounds #42

Open

Description

@weymouth

Since ForwardDiff 1.0, comparisons on Dual numbers break ties in value using the partials (JuliaDiff/ForwardDiff.jl#481). The domain check in (::ChebPoly)(x), chebgradient and chebjacobian, all(lb .≤ x .≤ ub), therefore throws when x sits exactly on a bound and its derivative points outward. It worked with ForwardDiff 0.10.

using FastChebInterp, ForwardDiff
c = chebinterp(chebpoints(8, 0, 1).^2, 0, 1)   # interpolate x² on [0,1]
ForwardDiff.derivative(c, 0.5)  # 1.0
ForwardDiff.derivative(c, 1.0)  # 2.0 on ForwardDiff 0.10.39 / FastChebInterp 1.2.0
                                # ForwardDiff 1.4.8 / FastChebInterp 1.3.1:
                                # ArgumentError: Dual{…}[Dual{…}(1.0,1.0)] not in domain [0] to [1]

For a gradient, the tie is decided by the first non-zero partial in lexicographic order. That can be pure round-off. In our case (a 3D table in spherical coordinates), a point on the upper bound of one coordinate was rejected because of a ∂/∂y partial of 1.9e-16.

The same pattern hit Interpolations.jl and DataInterpolations.jl at their end knots (JuliaDiff/ForwardDiff.jl#868, JuliaDiff/ForwardDiff.jl#742); ForwardDiff treats the tie-breaking as intended.

Possible fixes:

  • do the domain check on values only, e.g. through a ForwardDiff package extension that defines a _value(x::Dual) = ForwardDiff.value(x) used by the check; or
  • expose an unchecked evaluation (e.g. c(x; check=false)) for callers that already guarantee x is in the domain.

We currently work around it by calling the internal FastChebInterp.evaluate directly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions