Skip to content

ForwardDiff through hessian fails for ND interpolants #213

Closed

Description

@Riarrieta

Hi,

I’m getting a MethodError when differentiating through hessian with ForwardDiff.

MWE:

using FastInterpolations
using ForwardDiff

x = 1.0:5.0
y = 1.0:5.0
data = [sin(i) * cos(j) for i in x, j in y]

itp = linear_interp((x, y), data)

f(q) = hessian(itp, q)

ForwardDiff.jacobian(q -> vec(f(q)), [2.5, 3.5])

This errors with something like:

MethodError: no method matching Float64(::ForwardDiff.Dual{...})

It looks like the allocating hessian creates a Matrix{Float64} based on the stored data/grid types, even though the query becomes Dual under ForwardDiff.

I see the same behavior with linear, cubic, quadratic, and constant ND interpolants.

Thanks.

Activity

  1. Riarrieta commented on Oct 8, 2026

    @Riarrieta
    Author

    Thanks for looking into it!

  2. mgyoo86 commented on Oct 8, 2026

    @mgyoo86
    Member

    Hi @Riarrieta,

    Thanks a lot for reporting this issue!

    This was an unexpected regression introduced in v0.4.17, and it has now been fixed by PR #216.
    I’ll release a new version with this fix shortly!

    Motivated by this issue, I also realized that I had missed implementing the Jacobian operator.
    (Currently, FastInterpolations supports a few common operators, gradient, Laplacian, and Hessian, but not the Jacobian.)

    I’m planning to implement the Jacobian, as well as more generic versions of vector calculus derivative operators if possible.

    I’ll keep you updated! Please let me know if there are any other specific vector calculus operators or features you’d like to see.

    Thanks again! :)

  3. mgyoo86 commented on Oct 14, 2026

    @mgyoo86
    Member

    @Riarrieta
    FYI, the new version (v0.4.20), which fixed this issue, has just been released.
    Please give it a try and let me know if you find any issues.

    Thank you again for raising this issue!

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