Skip to content

Commit 516c095

Browse files
committed
Use NaNMath in tests
1 parent 6b5c602 commit 516c095

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
6565
LeastSquaresOptim = "0fc2ff8b-aaa3-5acd-a817-1944a5e08891"
6666
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
6767
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
68+
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
6869
NonlinearProblemLibrary = "b7050fa9-e91f-4b37-bcee-a89a063da141"
6970
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
7071
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -76,4 +77,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7677
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
7778

7879
[targets]
79-
test = ["Enzyme", "BenchmarkTools", "SafeTestsets", "Pkg", "Test", "ForwardDiff", "StaticArrays", "Symbolics", "LinearSolve", "Random", "LinearAlgebra", "Zygote", "SparseDiffTools", "NonlinearProblemLibrary", "LeastSquaresOptim", "FastLevenbergMarquardt"]
80+
test = ["Enzyme", "BenchmarkTools", "SafeTestsets", "Pkg", "Test", "ForwardDiff", "StaticArrays", "Symbolics", "LinearSolve", "Random", "LinearAlgebra", "Zygote", "SparseDiffTools", "NonlinearProblemLibrary", "LeastSquaresOptim", "FastLevenbergMarquardt", "NaNMath"]

src/levenberg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function SciMLBase.__init(prob::Union{NonlinearProblem{uType, iip},
177177
else
178178
uf, linsolve, J, fu2, jac_cache, du = jacobian_caches(alg, f, u, p, Val(iip);
179179
linsolve_kwargs, linsolve_with_JᵀJ)
180-
JᵀJ = similar(u)
180+
JᵀJ = similar(_vec(u))
181181
= similar(J)
182182
v = similar(du)
183183
end
@@ -214,7 +214,7 @@ function SciMLBase.__init(prob::Union{NonlinearProblem{uType, iip},
214214
# Preserve Types
215215
mat_tmp = vcat(J, DᵀD)
216216
fill!(mat_tmp, zero(eltype(u)))
217-
rhs_tmp = vcat(fu1, u)
217+
rhs_tmp = vcat(_vec(fu1), _vec(u))
218218
fill!(rhs_tmp, zero(eltype(u)))
219219
linsolve = __setup_linsolve(mat_tmp, rhs_tmp, u, p, alg)
220220
end

test/polyalgs.jl

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

33
f(u, p) = u .* u .- 2
44
u0 = [1.0, 1.0]
@@ -38,7 +38,8 @@ sol = solve(prob)
3838
@test SciMLBase.successful_retcode(sol)
3939

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

4344
uspan = (0.02, 0.1)
4445
prob = IntervalNonlinearProblem(ff, uspan)
@@ -48,5 +49,5 @@ sol = solve(prob)
4849
u0 = 0.06
4950
p = 2.0
5051
prob = NonlinearProblem(ff, u0, p)
51-
solver = solve(prob)
52+
sol = solve(prob)
5253
@test SciMLBase.successful_retcode(sol)

0 commit comments

Comments
 (0)