Skip to content

Commit

Permalink
Ensure that the preconditioner is pos def.
Browse files Browse the repository at this point in the history
This doesn't seem to be a great preconditioner, but it does test the precon option.
  • Loading branch information
mpf committed Oct 6, 2024
1 parent 04fe91f commit 116730d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ end
@testset "Preconditioner in Trunk" begin
x0 = [-1.2; 1.0]
nlp = ADNLPModel(x -> 100 * (x[2] - x[1]^2)^2 + (x[1] - 1)^2, x0)
DiagPrecon(x) = Diagonal(inv( [200 + 800 * x[1]^2 - 400 * x[2] 0.0;
0.0 200] ))

function DiagPrecon(x)
H = Matrix(hess(nlp, x))
λmin = minimum(eigvals(H))
Diagonal(H + λmin * I)
end
M = DiagPrecon(x0)
# implement `ldiv!` for `Diagonal` to avoid copying
function LinearAlgebra.ldiv!(y, M::Diagonal, x)
y .= M \ x
end
Expand All @@ -95,5 +96,4 @@ end
end
stats = trunk(nlp, callback=callback, M=M)
@test stats.status == :first_order

end

0 comments on commit 116730d

Please sign in to comment.