Skip to content

Commit 55ad935

Browse files
committed
make hessians of scaled interpolants work, and add a test that would have caught the bug
1 parent ba5b9ec commit 55ad935

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

ext/InterpolationsForwardDiffExt.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ end
1414

1515
# apply partials from arbitrarily nested ForwardDiff.Dual to a value
1616
# used in maybe_clamp, above
17-
function apply_partials(x_dual::D, val::Number) where D <: ForwardDiff.Dual
18-
∂s = ForwardDiff.partials(x_dual)
19-
apply_partials(ForwardDiff.value(x_dual), D(val, ∂s))
17+
function apply_partials(dual_number::D, x::Number) where D <: ForwardDiff.Dual
18+
∂s = ForwardDiff.partials(dual_number)
19+
val = ForwardDiff.value(dual_number)
20+
D(apply_partials(val, x) , ∂s)
2021
end
21-
apply_partials(_::Number, val::Number) = val
22+
apply_partials(_::Number, x::Number) = x
2223

2324
end

test/hessian.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,21 @@ using Test, Interpolations, LinearAlgebra, ForwardDiff
7272
end
7373
end
7474
end
75+
76+
@testset "scaled interpolators / convienience constructors (issue 627)" begin
77+
N = 11
78+
x = range(1.0, 3.0, N)
79+
y = range(-3.0, 3.0, N)
80+
u = rand(N, N)
81+
82+
for uitp in [
83+
Interpolations.linear_interpolation((x, y), u),
84+
Interpolations.cubic_spline_interpolation((x, y), u),
85+
]
86+
f = x -> uitp(x[1], x[2])
87+
x =/3, -π/2]
88+
89+
@test ForwardDiff.hessian(f, x) Interpolations.hessian(uitp, x[1], x[2])
90+
end
91+
end
7592
end

0 commit comments

Comments
 (0)