Skip to content

Commit 06b779c

Browse files
authored
Unexport gradient, hessian (#623)
* Unexport gradient, hessian; Fix #605 * Do not export gradient and hessian
1 parent cba98e8 commit 06b779c

File tree

4 files changed

+60
-62
lines changed

4 files changed

+60
-62
lines changed

src/Interpolations.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export
3535
# extrapolation/extrapolation.jl
3636
# monotonic/monotonic.jl
3737
# scaling/scaling.jl
38+
# hermite/cubic.jl
3839

3940
using LinearAlgebra, SparseArrays
4041
using StaticArrays, WoodburyMatrices, Ratios, AxisAlgorithms, OffsetArrays

src/hermite/cubic.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export CubicHermite
2+
13
"""
24
CubicHermite
35
@@ -148,8 +150,3 @@ function hessian(ch::CubicHermite, x::Float64)::Float64
148150
d2 = 2 * (3x - 2x1 - x2) / (h * h)
149151
c1 * (y1 - y2) + d1 * dydx1 + d2 * dydx2
150152
end
151-
152-
153-
export CubicHermite
154-
export gradient
155-
export hessian

test/cubic_hermite.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ function cubic_hermite_test()
2525
for i = 1:length(xs)-1
2626
x = Float64(i)
2727
@test ch(x) == 1.0
28-
@test gradient(ch, x) == 0.0
29-
@test hessian(ch, x) == 0.0
28+
@test Interpolations.gradient(ch, x) == 0.0
29+
@test Interpolations.hessian(ch, x) == 0.0
3030
x = x + 0.25
3131
@test ch(x) == 1.0
32-
@test gradient(ch, x) == 0.0
33-
@test hessian(ch, x) == 0.0
32+
@test Interpolations.gradient(ch, x) == 0.0
33+
@test Interpolations.hessian(ch, x) == 0.0
3434
x = x + 0.25
3535
@test ch(x) == 1.0
36-
@test gradient(ch, x) == 0.0
37-
@test hessian(ch, x) == 0.0
36+
@test Interpolations.gradient(ch, x) == 0.0
37+
@test Interpolations.hessian(ch, x) == 0.0
3838
x = x + 0.25
3939
@test ch(x) == 1.0
40-
@test gradient(ch, x) == 0.0
41-
@test hessian(ch, x) == 0.0
40+
@test Interpolations.gradient(ch, x) == 0.0
41+
@test Interpolations.hessian(ch, x) == 0.0
4242
end
4343
# Ensure that the ight endpoint query doesn't read past the end of the array:
4444
@test ch(5.0) == 1.0
45-
@test gradient(ch, 5.0) == 0.0
46-
@test hessian(ch, 5.0) == 0.0
45+
@test Interpolations.gradient(ch, 5.0) == 0.0
46+
@test Interpolations.hessian(ch, 5.0) == 0.0
4747

4848
# Now linear functions:
4949
a = 7.2
@@ -56,24 +56,24 @@ function cubic_hermite_test()
5656
for i = 1:length(xs)-1
5757
x = Float64(i)
5858
@test ch(x) a * x + b
59-
@test gradient(ch, x) a
60-
@test abs(hessian(ch, x)) < 3e-14
59+
@test Interpolations.gradient(ch, x) a
60+
@test abs(Interpolations.hessian(ch, x)) < 3e-14
6161
x = x + 0.25
6262
@test ch(x) a * x + b
63-
@test gradient(ch, x) a
64-
@test abs(hessian(ch, x)) < 3e-14
63+
@test Interpolations.gradient(ch, x) a
64+
@test abs(Interpolations.hessian(ch, x)) < 3e-14
6565
x = x + 0.25
6666
@test ch(x) a * x + b
67-
@test gradient(ch, x) a
68-
@test abs(hessian(ch, x)) < 3e-14
67+
@test Interpolations.gradient(ch, x) a
68+
@test abs(Interpolations.hessian(ch, x)) < 3e-14
6969
x = x + 0.25
7070
@test ch(x) a * x + b
71-
@test gradient(ch, x) a
72-
@test abs(hessian(ch, x)) < 3e-14
71+
@test Interpolations.gradient(ch, x) a
72+
@test abs(Interpolations.hessian(ch, x)) < 3e-14
7373
end
7474
@test ch(last(xs)) a * last(xs) + b
75-
@test gradient(ch, last(xs)) a
76-
@test abs(hessian(ch, last(xs))) < 3e-14
75+
@test Interpolations.gradient(ch, last(xs)) a
76+
@test abs(Interpolations.hessian(ch, last(xs))) < 3e-14
7777

7878
# Now the interpolation condition:
7979
xs = zeros(50)
@@ -92,7 +92,7 @@ function cubic_hermite_test()
9292

9393
for i = 1:50
9494
@test ch(xs[i]) ys[i]
95-
@test gradient(ch, xs[i]) dydxs[i]
95+
@test Interpolations.gradient(ch, xs[i]) dydxs[i]
9696
end
9797

9898
# Now quadratics:
@@ -107,13 +107,13 @@ function cubic_hermite_test()
107107
for i = 1:200
108108
x = rand() * last(xs)
109109
@test ch(x) a * x * x + b * x + c
110-
@test gradient(ch, x) 2 * a * x + b
111-
@test hessian(ch, x) 2 * a
110+
@test Interpolations.gradient(ch, x) 2 * a * x + b
111+
@test Interpolations.hessian(ch, x) 2 * a
112112
end
113113
x = last(xs)
114114
@test ch(x) a * x * x + b * x + c
115-
@test gradient(ch, x) 2 * x * a + b
116-
@test hessian(ch, x) 2 * a
115+
@test Interpolations.gradient(ch, x) 2 * x * a + b
116+
@test Interpolations.hessian(ch, x) 2 * a
117117
# Cannot extrapolate:
118118
@test_throws DomainError ch(x + 0.1)
119119
@test_throws DomainError ch(xs[1] - 0.1)

test/gpu_support.jl

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,37 @@ JLArrays.allowscalar(false)
99
idx = 2.0:0.17:19.0
1010
jlidx = jl(collect(idx))
1111
@test itp.(idx) == collect(jlitp.(idx)) == collect(jlitp.(jlidx))
12-
@test gradient.(Ref(itp), idx) ==
13-
collect(gradient.(Ref(jlitp), idx)) ==
14-
collect(gradient.(Ref(jlitp), jlidx))
12+
@test Interpolations.gradient.(Ref(itp), idx) ==
13+
collect(Interpolations.gradient.(Ref(jlitp), idx)) ==
14+
collect(Interpolations.gradient.(Ref(jlitp), jlidx))
1515

1616
sitp = scale(itp, A_x)
1717
jlsitp = jl(sitp)
1818
idx = 1.0:0.4:39.0
1919
jlidx = jl(collect(idx))
2020
@test sitp.(idx) == collect(jlsitp.(idx)) == collect(jlsitp.(jlidx))
21-
@test gradient.(Ref(sitp), idx) ==
22-
collect(gradient.(Ref(jlsitp), idx)) ==
23-
collect(gradient.(Ref(jlsitp), jlidx))
21+
@test Interpolations.gradient.(Ref(sitp), idx) ==
22+
collect(Interpolations.gradient.(Ref(jlsitp), idx)) ==
23+
collect(Interpolations.gradient.(Ref(jlsitp), jlidx))
2424

2525

2626
esitp = extrapolate(sitp, Flat())
2727
jlesitp = jl(esitp)
2828
idx = -1.0:0.84:41.0
2929
jlidx = jl(collect(idx))
3030
@test esitp.(idx) == collect(jlesitp.(idx)) == collect(jlesitp.(jlidx))
31-
@test gradient.(Ref(esitp), idx) ==
32-
collect(gradient.(Ref(jlesitp), idx)) ==
33-
collect(gradient.(Ref(jlesitp), jlidx))
31+
@test Interpolations.gradient.(Ref(esitp), idx) ==
32+
collect(Interpolations.gradient.(Ref(jlesitp), idx)) ==
33+
collect(Interpolations.gradient.(Ref(jlesitp), jlidx))
3434

3535
esitp = extrapolate(sitp, 0.0)
3636
jlesitp = jl(esitp)
3737
idx = -1.0:0.84:41.0
3838
jlidx = jl(collect(idx))
3939
@test esitp.(idx) == collect(jlesitp.(idx)) == collect(jlesitp.(jlidx))
40-
@test gradient.(Ref(esitp), idx) ==
41-
collect(gradient.(Ref(jlesitp), idx)) ==
42-
collect(gradient.(Ref(jlesitp), jlidx))
40+
@test Interpolations.gradient.(Ref(esitp), idx) ==
41+
collect(Interpolations.gradient.(Ref(jlesitp), idx)) ==
42+
collect(Interpolations.gradient.(Ref(jlesitp), jlidx))
4343
end
4444

4545
@testset "2d GPU Interpolation" begin
@@ -50,44 +50,44 @@ end
5050
idx = 2.0:0.17:19.0
5151
jlidx = jl(collect(idx))
5252
@test itp.(idx, idx') == collect(jlitp.(idx, idx')) == collect(jlitp.(jlidx, jlidx'))
53-
@test gradient.(Ref(itp), idx, idx') ==
54-
collect(gradient.(Ref(jlitp), idx, idx')) ==
55-
collect(gradient.(Ref(jlitp), jlidx, jlidx'))
56-
@test hessian.(Ref(itp), idx, idx') ==
57-
collect(hessian.(Ref(jlitp), idx, idx')) ==
58-
collect(hessian.(Ref(jlitp), jlidx, jlidx'))
53+
@test Interpolations.gradient.(Ref(itp), idx, idx') ==
54+
collect(Interpolations.gradient.(Ref(jlitp), idx, idx')) ==
55+
collect(Interpolations.gradient.(Ref(jlitp), jlidx, jlidx'))
56+
@test Interpolations.hessian.(Ref(itp), idx, idx') ==
57+
collect(Interpolations.hessian.(Ref(jlitp), idx, idx')) ==
58+
collect(Interpolations.hessian.(Ref(jlitp), jlidx, jlidx'))
5959

6060
sitp = scale(itp, A_x, A_x)
6161
jlsitp = jl(sitp)
6262
idx = 1.0:0.4:39.0
6363
jlidx = jl(collect(idx))
6464
@test sitp.(idx, idx') == collect(jlsitp.(idx, idx')) == collect(jlsitp.(jlidx, jlidx'))
65-
@test gradient.(Ref(sitp), idx, idx') ==
66-
collect(gradient.(Ref(jlsitp), idx, idx')) ==
67-
collect(gradient.(Ref(jlsitp), jlidx, jlidx'))
68-
@test hessian.(Ref(sitp), idx, idx') ==
69-
collect(hessian.(Ref(jlsitp), idx, idx')) ==
70-
collect(hessian.(Ref(jlsitp), jlidx, jlidx'))
65+
@test Interpolations.gradient.(Ref(sitp), idx, idx') ==
66+
collect(Interpolations.gradient.(Ref(jlsitp), idx, idx')) ==
67+
collect(Interpolations.gradient.(Ref(jlsitp), jlidx, jlidx'))
68+
@test Interpolations.hessian.(Ref(sitp), idx, idx') ==
69+
collect(Interpolations.hessian.(Ref(jlsitp), idx, idx')) ==
70+
collect(Interpolations.hessian.(Ref(jlsitp), jlidx, jlidx'))
7171

7272
esitp = extrapolate(sitp, Flat())
7373
jlesitp = jl(esitp)
7474
idx = -1.0:0.84:41.0
7575
jlidx = jl(collect(idx))
7676
@test esitp.(idx, idx') == collect(jlesitp.(idx, idx')) == collect(jlesitp.(jlidx, jlidx'))
77-
# gradient for `extrapolation` is currently broken under CUDA
78-
@test gradient.(Ref(esitp), idx, idx') ==
79-
collect(gradient.(Ref(jlesitp), idx, idx')) ==
80-
collect(gradient.(Ref(jlesitp), jlidx, jlidx'))
77+
# Interpolations.gradient for `extrapolation` is currently broken under CUDA
78+
@test Interpolations.gradient.(Ref(esitp), idx, idx') ==
79+
collect(Interpolations.gradient.(Ref(jlesitp), idx, idx')) ==
80+
collect(Interpolations.gradient.(Ref(jlesitp), jlidx, jlidx'))
8181

8282
esitp = extrapolate(sitp, 0.0)
8383
jlesitp = jl(esitp)
8484
idx = -1.0:0.84:41.0
8585
jlidx = jl(collect(idx))
8686
@test esitp.(idx, idx') == collect(jlesitp.(idx, idx')) == collect(jlesitp.(jlidx, jlidx'))
87-
# gradient for `extrapolation` is currently broken under CUDA
88-
@test gradient.(Ref(esitp), idx, idx') ==
89-
collect(gradient.(Ref(jlesitp), idx, idx')) ==
90-
collect(gradient.(Ref(jlesitp), jlidx, jlidx'))
87+
# Interpolations.gradient for `extrapolation` is currently broken under CUDA
88+
@test Interpolations.gradient.(Ref(esitp), idx, idx') ==
89+
collect(Interpolations.gradient.(Ref(jlesitp), idx, idx')) ==
90+
collect(Interpolations.gradient.(Ref(jlesitp), jlidx, jlidx'))
9191
end
9292

9393
@testset "Lanczos on gpu" begin

0 commit comments

Comments
 (0)