Skip to content

Commit 06186c0

Browse files
committed
Generic _axpy!
1 parent 026a600 commit 06186c0

File tree

8 files changed

+20
-11
lines changed

8 files changed

+20
-11
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
test:
1515
runs-on: ubuntu-latest
1616
strategy:
17+
fail-fast: false
1718
matrix:
1819
group:
1920
- All

src/broyden.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function perform_step!(cache::GeneralBroydenCache{true})
7878

7979
mul!(_vec(du), J⁻¹, -_vec(fu))
8080
α = perform_linesearch!(cache.lscache, u, du)
81-
axpy!(α, du, u)
81+
_axpy!(α, du, u)
8282
f(fu2, u, p)
8383

8484
cache.internalnorm(fu2) < cache.abstol && (cache.force_stop = true)

src/klement.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function perform_step!(cache::GeneralKlementCache{true})
115115

116116
# Line Search
117117
α = perform_linesearch!(cache.lscache, u, du)
118-
axpy!(α, du, u)
118+
_axpy!(α, du, u)
119119
f(cache.fu2, u, p)
120120

121121
cache.internalnorm(cache.fu2) < cache.abstol && (cache.force_stop = true)

src/lbroyden.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function perform_step!(cache::LimitedMemoryBroydenCache{true})
9393
T = eltype(u)
9494

9595
α = perform_linesearch!(cache.lscache, u, du)
96-
axpy!(α, du, u)
96+
_axpy!(α, du, u)
9797
f(cache.fu2, u, p)
9898

9999
cache.internalnorm(cache.fu2) < cache.abstol && (cache.force_stop = true)

src/raphson.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function perform_step!(cache::NewtonRaphsonCache{true})
9797

9898
# Line Search
9999
α = perform_linesearch!(cache.lscache, u, du)
100-
axpy!(-α, du, u)
100+
_axpy!(-α, du, u)
101101
f(cache.fu1, u, p)
102102

103103
cache.internalnorm(fu1) < cache.abstol && (cache.force_stop = true)

src/utils.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,13 @@ _try_factorize_and_check_singular!(::Nothing, x) = _issingular(x), false
260260
_reshape(x, args...) = reshape(x, args...)
261261
_reshape(x::Number, args...) = x
262262

263+
@generated function _axpy!(α, x, y)
264+
hasmethod(axpy!, Tuple{α, x, y}) && return :(axpy!(α, x, y))
265+
return :(@. y += α * x)
266+
end
267+
263268
# Needs Square Matrix
269+
# FIXME: Remove once https://github.com/SciML/LinearSolve.jl/pull/400 is merged and tagged
264270
"""
265271
needs_square_A(alg)
266272

test/23_test_problems.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ end
8686
GeneralBroyden(; linesearch = BackTracking()))
8787

8888
broken_tests = Dict(alg => Int[] for alg in alg_ops)
89-
broken_tests[alg_ops[1]] = [1, 3, 4, 5, 6, 11, 12, 13, 14, 21]
90-
broken_tests[alg_ops[2]] = [1, 2, 3, 4, 5, 6, 9, 11, 13, 22]
89+
broken_tests[alg_ops[1]] = [1, 3, 4, 5, 6, 11, 12, 13, 14]
90+
broken_tests[alg_ops[2]] = [1, 2, 3, 4, 5, 6, 9, 11, 13, 15, 16, 21, 22]
9191
broken_tests[alg_ops[3]] = [1, 2, 4, 5, 6, 11, 12, 13, 14, 21]
9292

9393
test_on_library(problems, dicts, alg_ops, broken_tests)
@@ -100,8 +100,8 @@ end
100100

101101
broken_tests = Dict(alg => Int[] for alg in alg_ops)
102102
broken_tests[alg_ops[1]] = [1, 2, 4, 5, 6, 7, 11, 13, 22]
103-
broken_tests[alg_ops[2]] = [1, 2, 4, 5, 6, 7, 11, 12, 13, 22]
104-
broken_tests[alg_ops[3]] = [1, 2, 4, 5, 6, 8, 11, 12, 13, 22]
103+
broken_tests[alg_ops[2]] = [1, 2, 4, 5, 6, 7, 11, 13, 22]
104+
broken_tests[alg_ops[3]] = [1, 2, 5, 6, 11, 12, 13, 22]
105105

106106
test_on_library(problems, dicts, alg_ops, broken_tests)
107107
end

test/nonlinear_least_squares.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ prob_iip = NonlinearLeastSquaresProblem(NonlinearFunction(loss_function;
2929
nlls_problems = [prob_oop, prob_iip]
3030
solvers = [
3131
GaussNewton(),
32-
GaussNewton(; linsolve = CholeskyFactorization()),
33-
LevenbergMarquardt(),
34-
LevenbergMarquardt(; linsolve = CholeskyFactorization()),
32+
GaussNewton(; linsolve = LUFactorization()),
3533
LeastSquaresOptimJL(:lm),
3634
LeastSquaresOptimJL(:dogleg),
3735
]
3836

37+
# Compile time on v"1.9" is too high!
38+
VERSION v"1.10-" && append!(solvers,
39+
[LevenbergMarquardt(), LevenbergMarquardt(; linsolve = LUFactorization())])
40+
3941
for prob in nlls_problems, solver in solvers
4042
@time sol = solve(prob, solver; maxiters = 10000, abstol = 1e-8)
4143
@test SciMLBase.successful_retcode(sol)

0 commit comments

Comments
 (0)