Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 78f1ea4

Browse files
committed
Fix DFSane tests and Klement allocations
1 parent 58f41f7 commit 78f1ea4

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/nlsolve/klement.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleKlement, args...;
4444
# Singularity test
4545
if !issuccess(F_)
4646
J = __init_identity_jacobian!!(J)
47+
@bb copyto!(F, J)
4748
if setindex_trait(J) === CanSetindex()
48-
lu!(J; check = false)
49+
F_ = lu!(F; check = false)
4950
else
50-
J = lu(J; check = false)
51+
F_ = lu(F; check = false)
5152
end
5253
end
5354
end
@@ -66,7 +67,7 @@ function SciMLBase.__solve(prob::NonlinearProblem, alg::SimpleKlement, args...;
6667
tc_sol !== nothing && return tc_sol
6768

6869
@bb δx .*= -1
69-
@bb J_cache .= J' .^ 2
70+
@bb J_cache .= transpose(J) .^ 2
7071
@bb @. δx² = δx^2
7172
@bb d = J_cache × vec(δx²)
7273
@bb δx² = J × vec(δx)

test/basictests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ end
198198
res = benchmark_nlsolve_oop(quadratic_f, @SVector[1.0, 1.0], p)
199199

200200
if any(x -> isnan(x) || x <= 1e-5 || x >= 1e5, res)
201-
@test_broken all(res .≈ sqrt(p))
201+
@test_broken all(abs.(res) .≈ sqrt(p))
202202
@test_broken abs.(ForwardDiff.derivative(p -> benchmark_nlsolve_oop(quadratic_f,
203203
@SVector[1.0, 1.0], p).u[end], p)) 1 / (2 * sqrt(p))
204204
else
205-
@test all(res .≈ sqrt(p))
205+
@test all(abs.(res) .≈ sqrt(p))
206206
@test isapprox(abs.(ForwardDiff.derivative(p -> benchmark_nlsolve_oop(quadratic_f,
207207
@SVector[1.0, 1.0], p).u[end], p)), 1 / (2 * sqrt(p)))
208208
end
@@ -213,12 +213,12 @@ end
213213
for p in 1.0:0.1:100.0
214214
res = benchmark_nlsolve_oop(quadratic_f, 1.0, p)
215215

216-
if any(x -> isnan(x) || x <= 1e-5 || x >= 1e5, res)
217-
@test_broken all(res . sqrt(p))
216+
if any(x -> isnan(x), res)
217+
@test_broken abs(res.u) sqrt(p)
218218
@test_broken abs.(ForwardDiff.derivative(p -> benchmark_nlsolve_oop(quadratic_f,
219219
1.0, p).u, p)) 1 / (2 * sqrt(p))
220220
else
221-
@test all(res . sqrt(p))
221+
@test abs(res.u) sqrt(p)
222222
@test isapprox(abs.(ForwardDiff.derivative(p -> benchmark_nlsolve_oop(quadratic_f,
223223
1.0, p).u, p)), 1 / (2 * sqrt(p)))
224224
end

0 commit comments

Comments
 (0)