Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Dec 7, 2023
1 parent 0a96e2f commit c4bde4d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/klement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ function perform_step!(cache::GeneralKlementCache{iip, IJ}) where {iip, IJ}
cache.J_cache = jacobian!!(cache.J_cache, cache)
cache.J = __get_diagonal!!(cache.J, cache.J_cache)
end
ill_conditioned = __is_ill_conditioned(cache.J)
ill_conditioned = __is_ill_conditioned(_vec(cache.J))
elseif IJ === :identity
ill_conditioned = __is_ill_conditioned(cache.J)
ill_conditioned = __is_ill_conditioned(_vec(cache.J))
end

if ill_conditioned
Expand Down Expand Up @@ -228,7 +228,7 @@ function perform_step!(cache::GeneralKlementCache{iip, IJ}) where {iip, IJ}
@bb @. cache.J += ((cache.fu - cache.fu_cache_2 - cache.J * cache.du) /
ifelse(iszero(cache.Jdu), T(1e-5), cache.Jdu)) * cache.du *
(cache.J^2)
else
elseif IJ === :true_jacobian
# Klement Updates to the Full Jacobian don't work for most problems, we should
# probably be using the Broyden Update Rule here
@bb @. cache.J_cache = cache.J'^2
Expand All @@ -241,6 +241,8 @@ function perform_step!(cache::GeneralKlementCache{iip, IJ}) where {iip, IJ}
@bb @. cache.J_cache *= cache.J
@bb cache.J_cache_2 = cache.J_cache × cache.J
@bb cache.J .+= cache.J_cache_2
else
error("Invalid `init_jacobian` value")

Check warning on line 245 in src/klement.jl

View check run for this annotation

Codecov / codecov/patch

src/klement.jl#L245

Added line #L245 was not covered by tests
end

@bb copyto!(cache.fu_cache_2, cache.fu)
Expand Down
3 changes: 3 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ end
end
return J
end
@inline function __get_diagonal!!(J::AbstractArray, J_full::AbstractMatrix)
return _restructure(J, __get_diagonal!!(_vec(J), J_full))

Check warning on line 555 in src/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils.jl#L554-L555

Added lines #L554 - L555 were not covered by tests
end
@inline __get_diagonal!!(J::Number, J_full::Number) = J_full

@inline __diag(x::AbstractMatrix) = diag(x)
Expand Down
6 changes: 3 additions & 3 deletions test/matrix_resizing.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using NonlinearSolve, Test
using NonlinearSolve, Test, StableRNGs

ff(u, p) = u .* u .- p
u0 = rand(2, 2)
u0 = rand(StableRNG(0), 2, 2)
p = 2.0
vecprob = NonlinearProblem(ff, vec(u0), p)
prob = NonlinearProblem(ff, u0, p)
Expand All @@ -13,7 +13,7 @@ for alg in (NewtonRaphson(), TrustRegion(), LevenbergMarquardt(), PseudoTransien
end

fiip(du, u, p) = (du .= u .* u .- p)
u0 = rand(2, 2)
u0 = rand(StableRNG(0), 2, 2)
p = 2.0
vecprob = NonlinearProblem(fiip, vec(u0), p)
prob = NonlinearProblem(fiip, u0, p)
Expand Down

0 comments on commit c4bde4d

Please sign in to comment.