Skip to content

Commit 1a2a805

Browse files
committed
Calculate derivatives using Jacobian-vector products
1 parent 07963b7 commit 1a2a805

File tree

5 files changed

+10
-67
lines changed

5 files changed

+10
-67
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ jobs:
2020
with:
2121
version: ${{ matrix.julia-version }}
2222
- uses: julia-actions/cache@v2
23-
- uses: julia-actions/julia-buildpkg@v1
2423
- uses: julia-actions/julia-runtest@v1
2524
with:
2625
annotate: true

Project.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ DoubleFloats = "1"
1414
ExplicitImports = "1.14"
1515
JET = "0.9, 0.10"
1616
LinearAlgebra = "<0.0.1, 1"
17-
NLSolversBase = "7"
17+
NLSolversBase = "8"
1818
NaNMath = "1"
19-
Optim = "1"
2019
OptimTestProblems = "2"
2120
Printf = "<0.0.1, 1"
2221
Test = "<0.0.1, 1"
@@ -27,9 +26,11 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
2726
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78"
2827
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
2928
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
30-
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
3129
OptimTestProblems = "cec144fc-5a64-5bc6-99fb-dde8f63e154c"
3230
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3331

3432
[targets]
35-
test = ["Aqua", "ExplicitImports", "JET", "Test", "OptimTestProblems", "Optim", "DoubleFloats"]
33+
test = ["Aqua", "ExplicitImports", "JET", "Test", "OptimTestProblems", "DoubleFloats"]
34+
35+
[sources]
36+
NLSolversBase = { url = "https://github.com/devmotion/NLSolversBase.jl.git", rev = "dmw/jvp" }

src/LineSearches.jl

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module LineSearches
22

33
using Printf: @sprintf
4-
using LinearAlgebra: dot, norm
4+
using LinearAlgebra: norm
55
using NaNMath: NaNMath
66
using NLSolversBase: NLSolversBase, AbstractObjective
77

@@ -28,11 +28,8 @@ function make_ϕdϕ(df, x_new, x, s)
2828
# Move a distance of alpha in the direction of s
2929
x_new .= x .+ α.*s
3030

31-
# Evaluate ∇f(x+α*s)
32-
NLSolversBase.value_gradient!(df, x_new)
33-
3431
# Calculate ϕ(a_i), ϕ'(a_i)
35-
NLSolversBase.value(df), real(dot(NLSolversBase.gradient(df), s))
32+
return NLSolversBase.value_jvp!(df, x_new, s)
3633
end
3734
ϕdϕ
3835
end
@@ -41,49 +38,16 @@ function make_ϕ_dϕ(df, x_new, x, s)
4138
# Move a distance of alpha in the direction of s
4239
x_new .= x .+ α.*s
4340

44-
# Evaluate ∇f(x+α*s)
45-
NLSolversBase.gradient!(df, x_new)
46-
4741
# Calculate ϕ'(a_i)
48-
real(dot(NLSolversBase.gradient(df), s))
42+
return NLSolversBase.jvp!(df, x_new, s)
4943
end
5044
make_ϕ(df, x_new, x, s), dϕ
5145
end
5246
function make_ϕ_dϕ_ϕdϕ(df, x_new, x, s)
53-
function (α)
54-
# Move a distance of alpha in the direction of s
55-
x_new .= x .+ α.*s
56-
57-
# Evaluate f(x+α*s) and ∇f(x+α*s)
58-
NLSolversBase.gradient!(df, x_new)
59-
60-
# Calculate ϕ'(a_i)
61-
real(dot(NLSolversBase.gradient(df), s))
62-
end
63-
function ϕdϕ(α)
64-
# Move a distance of alpha in the direction of s
65-
x_new .= x .+ α.*s
66-
67-
# Evaluate ∇f(x+α*s)
68-
NLSolversBase.value_gradient!(df, x_new)
69-
70-
# Calculate ϕ'(a_i)
71-
NLSolversBase.value(df), real(dot(NLSolversBase.gradient(df), s))
72-
end
73-
make_ϕ(df, x_new, x, s), dϕ, ϕdϕ
47+
make_ϕ_dϕ(df, x_new, x, s)..., make_ϕdϕ(df, x_new, x, s)
7448
end
7549
function make_ϕ_ϕdϕ(df, x_new, x, s)
76-
function ϕdϕ(α)
77-
# Move a distance of alpha in the direction of s
78-
x_new .= x .+ α.*s
79-
80-
# Evaluate ∇f(x+α*s)
81-
NLSolversBase.value_gradient!(df, x_new)
82-
83-
# Calculate ϕ'(a_i)
84-
NLSolversBase.value(df), real(dot(NLSolversBase.gradient(df), s))
85-
end
86-
make_ϕ(df, x_new, x, s), ϕdϕ
50+
make_ϕ(df, x_new, x, s), make_ϕdϕ(df, x_new, x, s)
8751
end
8852

8953
include("types.jl")

test/examples.jl

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ my_tests = [
1414
"initial.jl",
1515
"alphacalc.jl",
1616
"arbitrary_precision.jl",
17-
"examples.jl",
1817
"captured.jl",
1918
"issues.jl",
2019
"qa.jl",

0 commit comments

Comments
 (0)