Skip to content

Commit c4bde4d

Browse files
committed
Fix tests
1 parent 0a96e2f commit c4bde4d

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/klement.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ function perform_step!(cache::GeneralKlementCache{iip, IJ}) where {iip, IJ}
174174
cache.J_cache = jacobian!!(cache.J_cache, cache)
175175
cache.J = __get_diagonal!!(cache.J, cache.J_cache)
176176
end
177-
ill_conditioned = __is_ill_conditioned(cache.J)
177+
ill_conditioned = __is_ill_conditioned(_vec(cache.J))
178178
elseif IJ === :identity
179-
ill_conditioned = __is_ill_conditioned(cache.J)
179+
ill_conditioned = __is_ill_conditioned(_vec(cache.J))
180180
end
181181

182182
if ill_conditioned
@@ -228,7 +228,7 @@ function perform_step!(cache::GeneralKlementCache{iip, IJ}) where {iip, IJ}
228228
@bb @. cache.J += ((cache.fu - cache.fu_cache_2 - cache.J * cache.du) /
229229
ifelse(iszero(cache.Jdu), T(1e-5), cache.Jdu)) * cache.du *
230230
(cache.J^2)
231-
else
231+
elseif IJ === :true_jacobian
232232
# Klement Updates to the Full Jacobian don't work for most problems, we should
233233
# probably be using the Broyden Update Rule here
234234
@bb @. cache.J_cache = cache.J'^2
@@ -241,6 +241,8 @@ function perform_step!(cache::GeneralKlementCache{iip, IJ}) where {iip, IJ}
241241
@bb @. cache.J_cache *= cache.J
242242
@bb cache.J_cache_2 = cache.J_cache × cache.J
243243
@bb cache.J .+= cache.J_cache_2
244+
else
245+
error("Invalid `init_jacobian` value")
244246
end
245247

246248
@bb copyto!(cache.fu_cache_2, cache.fu)

src/utils.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,9 @@ end
551551
end
552552
return J
553553
end
554+
@inline function __get_diagonal!!(J::AbstractArray, J_full::AbstractMatrix)
555+
return _restructure(J, __get_diagonal!!(_vec(J), J_full))
556+
end
554557
@inline __get_diagonal!!(J::Number, J_full::Number) = J_full
555558

556559
@inline __diag(x::AbstractMatrix) = diag(x)

test/matrix_resizing.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using NonlinearSolve, Test
1+
using NonlinearSolve, Test, StableRNGs
22

33
ff(u, p) = u .* u .- p
4-
u0 = rand(2, 2)
4+
u0 = rand(StableRNG(0), 2, 2)
55
p = 2.0
66
vecprob = NonlinearProblem(ff, vec(u0), p)
77
prob = NonlinearProblem(ff, u0, p)
@@ -13,7 +13,7 @@ for alg in (NewtonRaphson(), TrustRegion(), LevenbergMarquardt(), PseudoTransien
1313
end
1414

1515
fiip(du, u, p) = (du .= u .* u .- p)
16-
u0 = rand(2, 2)
16+
u0 = rand(StableRNG(0), 2, 2)
1717
p = 2.0
1818
vecprob = NonlinearProblem(fiip, vec(u0), p)
1919
prob = NonlinearProblem(fiip, u0, p)

0 commit comments

Comments
 (0)