Skip to content

Commit 0463e08

Browse files
Merge branch 'master' into patch-1
2 parents be9ce44 + 37a62f2 commit 0463e08

File tree

5 files changed

+52
-20
lines changed

5 files changed

+52
-20
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "NonlinearSolve"
22
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
33
authors = ["SciML"]
4-
version = "2.6.0"
4+
version = "2.6.1"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/NonlinearSolve.jl

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_m
55
end
66

77
import Reexport: @reexport
8-
import PrecompileTools
8+
import PrecompileTools: @recompile_invalidations, @compile_workload, @setup_workload
99

10-
PrecompileTools.@recompile_invalidations begin
10+
@recompile_invalidations begin
1111
using DiffEqBase, LinearAlgebra, LinearSolve, SparseArrays, SparseDiffTools
1212
using FastBroadcast: @..
1313
import ArrayInterface: restructure
@@ -95,17 +95,49 @@ include("jacobian.jl")
9595
include("ad.jl")
9696
include("default.jl")
9797

98-
PrecompileTools.@compile_workload begin
99-
for T in (Float32, Float64)
100-
probs = (NonlinearProblem{false}((u, p) -> u .* u .- p, T(0.1), T(2)),
101-
NonlinearProblem{false}((u, p) -> u .* u .- p, T[0.1], T[2]),
102-
NonlinearProblem{true}((du, u, p) -> du .= u .* u .- p, T[0.1], T[2]))
98+
@setup_workload begin
99+
nlfuncs = ((NonlinearFunction{false}((u, p) -> u .* u .- p), 0.1),
100+
(NonlinearFunction{false}((u, p) -> u .* u .- p), [0.1]),
101+
(NonlinearFunction{true}((du, u, p) -> du .= u .* u .- p), [0.1]))
102+
probs_nls = NonlinearProblem[]
103+
for T in (Float32, Float64), (fn, u0) in nlfuncs
104+
push!(probs_nls, NonlinearProblem(fn, T.(u0), T(2)))
105+
end
103106

104-
precompile_algs = (NewtonRaphson(), TrustRegion(), LevenbergMarquardt(),
105-
PseudoTransient(), GeneralBroyden(), GeneralKlement(), DFSane(), nothing)
107+
nls_algs = (NewtonRaphson(), TrustRegion(), LevenbergMarquardt(), PseudoTransient(),
108+
GeneralBroyden(), GeneralKlement(), DFSane(), nothing)
109+
110+
probs_nlls = NonlinearLeastSquaresProblem[]
111+
nlfuncs = ((NonlinearFunction{false}((u, p) -> (u .^ 2 .- p)[1:1]), [0.1, 0.0]),
112+
(NonlinearFunction{false}((u, p) -> vcat(u .* u .- p, u .* u .- p)), [0.1, 0.1]),
113+
(NonlinearFunction{true}((du, u, p) -> du[1] = u[1] * u[1] - p,
114+
resid_prototype = zeros(1)), [0.1, 0.0]),
115+
(NonlinearFunction{true}((du, u, p) -> du .= vcat(u .* u .- p, u .* u .- p),
116+
resid_prototype = zeros(4)), [0.1, 0.1]))
117+
for (fn, u0) in nlfuncs
118+
push!(probs_nlls, NonlinearLeastSquaresProblem(fn, u0, 2.0))
119+
end
120+
nlfuncs = ((NonlinearFunction{false}((u, p) -> (u .^ 2 .- p)[1:1]), Float32[0.1, 0.0]),
121+
(NonlinearFunction{false}((u, p) -> vcat(u .* u .- p, u .* u .- p)),
122+
Float32[0.1, 0.1]),
123+
(NonlinearFunction{true}((du, u, p) -> du[1] = u[1] * u[1] - p,
124+
resid_prototype = zeros(Float32, 1)), Float32[0.1, 0.0]),
125+
(NonlinearFunction{true}((du, u, p) -> du .= vcat(u .* u .- p, u .* u .- p),
126+
resid_prototype = zeros(Float32, 4)), Float32[0.1, 0.1]))
127+
for (fn, u0) in nlfuncs
128+
push!(probs_nlls, NonlinearLeastSquaresProblem(fn, u0, 2.0f0))
129+
end
106130

107-
for prob in probs, alg in precompile_algs
108-
solve(prob, alg, abstol = T(1e-2))
131+
nlls_algs = (LevenbergMarquardt(), GaussNewton(),
132+
LevenbergMarquardt(; linsolve = LUFactorization()),
133+
GaussNewton(; linsolve = LUFactorization()))
134+
135+
@compile_workload begin
136+
for prob in probs_nls, alg in nls_algs
137+
solve(prob, alg, abstol = 1e-2)
138+
end
139+
for prob in probs_nlls, alg in nlls_algs
140+
solve(prob, alg, abstol = 1e-2)
109141
end
110142
end
111143
end

src/levenberg.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function perform_step!(cache::LevenbergMarquardtCache{true, fastls}) where {fast
260260
# Usual Levenberg-Marquardt step ("velocity").
261261
# The following lines do: cache.v = -cache.mat_tmp \ cache.u_tmp
262262
if fastls
263-
cache.mat_tmp[1:length(fu1), :] .= cache.J
263+
copyto!(@view(cache.mat_tmp[1:length(fu1), :]), cache.J)
264264
cache.mat_tmp[(length(fu1) + 1):end, :] .= λ .* cache.DᵀD
265265
cache.rhs_tmp[1:length(fu1)] .= _vec(fu1)
266266
linres = dolinsolve(alg.precs, linsolve; A = cache.mat_tmp,
@@ -299,8 +299,8 @@ function perform_step!(cache::LevenbergMarquardtCache{true, fastls}) where {fast
299299
cache.stats.nfactors += 2
300300

301301
# Require acceptable steps to satisfy the following condition.
302-
norm_v = norm(v)
303-
if 2 * norm(cache.a) α_geodesic * norm_v
302+
norm_v = cache.internalnorm(v)
303+
if 2 * cache.internalnorm(cache.a) α_geodesic * norm_v
304304
_vec(cache.δ) .= _vec(v) .+ _vec(cache.a) ./ 2
305305
@unpack δ, loss_old, norm_v_old, v_old, b_uphill = cache
306306
f(cache.fu_tmp, u .+ δ, p)
@@ -392,8 +392,8 @@ function perform_step!(cache::LevenbergMarquardtCache{false, fastls}) where {fas
392392
cache.stats.nfactors += 1
393393

394394
# Require acceptable steps to satisfy the following condition.
395-
norm_v = norm(v)
396-
if 2 * norm(cache.a) α_geodesic * norm_v
395+
norm_v = cache.internalnorm(v)
396+
if 2 * cache.internalnorm(cache.a) α_geodesic * norm_v
397397
cache.δ = _restructure(cache.δ, _vec(v) .+ _vec(cache.a) ./ 2)
398398
@unpack δ, loss_old, norm_v_old, v_old, b_uphill = cache
399399
fu_new = f(u .+ δ, p)

test/23_test_problems.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ end
6868
broken_tests = Dict(alg => Int[] for alg in alg_ops)
6969
broken_tests[alg_ops[1]] = [3, 6, 17, 21]
7070
broken_tests[alg_ops[2]] = [3, 6, 17, 21]
71-
broken_tests[alg_ops[3]] = [6, 11, 21]
71+
broken_tests[alg_ops[3]] = [6, 11, 17, 21]
7272

7373
test_on_library(problems, dicts, alg_ops, broken_tests)
7474
end

test/basictests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ end
390390
@testset "Keyword Arguments" begin
391391
damping_initial = [0.5, 2.0, 5.0]
392392
damping_increase_factor = [1.5, 3.0, 10.0]
393-
damping_decrease_factor = Float64[2, 5, 12]
393+
damping_decrease_factor = Float64[2, 5, 10.0]
394394
finite_diff_step_geodesic = [0.02, 0.2, 0.3]
395395
α_geodesic = [0.6, 0.8, 0.9]
396396
b_uphill = Float64[0, 1, 2]
@@ -408,7 +408,7 @@ end
408408
b_uphill = options[6], min_damping_D = options[7])
409409

410410
probN = NonlinearProblem{false}(quadratic_f, [1.0, 1.0], 2.0)
411-
sol = solve(probN, alg, abstol = 1e-12)
411+
sol = solve(probN, alg; abstol = 1e-13, maxiters = 10000)
412412
@test all(abs.(quadratic_f(sol.u, 2.0)) .< 1e-10)
413413
end
414414
end

0 commit comments

Comments
 (0)