Skip to content

Commit 078a1b1

Browse files
ajwheelermkitti
andauthored
make hessians of scaled interpolants work (#628)
* make hessians of scaled interpolants work, and add a test that would have caught the bug * make the test deterministic * Bump version and news --------- Co-authored-by: Mark Kittisopikul <markkitt@gmail.com>
1 parent ba5b9ec commit 078a1b1

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
For a comprehensive list of changes, see [Releases](https://github.com/JuliaMath/Interpolations.jl/releases).
22

3+
# v0.16.1
4+
5+
Fixes:
6+
- Fix `hessian` with ForwardDiff.jl for scaled interpolants ([#628](https://github.com/JuliaMath/Interpolations.jl/pull/628))
7+
38
# v0.16
49

510
Breaking changes:

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Interpolations"
22
uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
3-
version = "0.16.0"
3+
version = "0.16.1"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

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 = reshape(sin.(1 : (N^2)), 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)