Skip to content

Commit

Permalink
Use NaNMath in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 24, 2023
1 parent 8e8fc82 commit 5e7610a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LeastSquaresOptim = "0fc2ff8b-aaa3-5acd-a817-1944a5e08891"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
NonlinearProblemLibrary = "b7050fa9-e91f-4b37-bcee-a89a063da141"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -76,4 +77,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Enzyme", "BenchmarkTools", "SafeTestsets", "Pkg", "Test", "ForwardDiff", "StaticArrays", "Symbolics", "LinearSolve", "Random", "LinearAlgebra", "Zygote", "SparseDiffTools", "NonlinearProblemLibrary", "LeastSquaresOptim", "FastLevenbergMarquardt"]
test = ["Enzyme", "BenchmarkTools", "SafeTestsets", "Pkg", "Test", "ForwardDiff", "StaticArrays", "Symbolics", "LinearSolve", "Random", "LinearAlgebra", "Zygote", "SparseDiffTools", "NonlinearProblemLibrary", "LeastSquaresOptim", "FastLevenbergMarquardt", "NaNMath"]
4 changes: 2 additions & 2 deletions src/levenberg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function SciMLBase.__init(prob::Union{NonlinearProblem{uType, iip},
else
uf, linsolve, J, fu2, jac_cache, du = jacobian_caches(alg, f, u, p, Val(iip);

Check warning on line 178 in src/levenberg.jl

View check run for this annotation

Codecov / codecov/patch

src/levenberg.jl#L178

Added line #L178 was not covered by tests
linsolve_kwargs, linsolve_with_JᵀJ)
JᵀJ = similar(u)
JᵀJ = similar(_vec(u))
= similar(J)
v = similar(du)

Check warning on line 182 in src/levenberg.jl

View check run for this annotation

Codecov / codecov/patch

src/levenberg.jl#L180-L182

Added lines #L180 - L182 were not covered by tests
end
Expand Down Expand Up @@ -214,7 +214,7 @@ function SciMLBase.__init(prob::Union{NonlinearProblem{uType, iip},
# Preserve Types
mat_tmp = vcat(J, DᵀD)
fill!(mat_tmp, zero(eltype(u)))
rhs_tmp = vcat(fu1, u)
rhs_tmp = vcat(_vec(fu1), _vec(u))
fill!(rhs_tmp, zero(eltype(u)))
linsolve = __setup_linsolve(mat_tmp, rhs_tmp, u, p, alg)

Check warning on line 219 in src/levenberg.jl

View check run for this annotation

Codecov / codecov/patch

src/levenberg.jl#L215-L219

Added lines #L215 - L219 were not covered by tests
end
Expand Down
7 changes: 4 additions & 3 deletions test/polyalgs.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using NonlinearSolve, Test
using NonlinearSolve, Test, NaNMath

f(u, p) = u .* u .- 2
u0 = [1.0, 1.0]
Expand Down Expand Up @@ -38,7 +38,8 @@ sol = solve(prob)
@test SciMLBase.successful_retcode(sol)

# https://github.com/SciML/NonlinearSolve.jl/issues/187
ff(u, p) = 0.5 / 1.5 * log.(u ./ (1.0 .- u)) .- 2.0 * u .+ 1.0
# If we use a General Nonlinear Solver the solution might go out of the domain!
ff(u, p) = 0.5 / 1.5 * NaNMath.log.(u ./ (1.0 .- u)) .- 2.0 * u .+ 1.0

uspan = (0.02, 0.1)
prob = IntervalNonlinearProblem(ff, uspan)
Expand All @@ -48,5 +49,5 @@ sol = solve(prob)
u0 = 0.06
p = 2.0
prob = NonlinearProblem(ff, u0, p)
solver = solve(prob)
sol = solve(prob)
@test SciMLBase.successful_retcode(sol)

0 comments on commit 5e7610a

Please sign in to comment.