Skip to content

Commit e8233a5

Browse files
committed
fix test
1 parent a1278ad commit e8233a5

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

test/interface/sparsediff_tests.jl

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,15 @@ for f in [f_oop, f_ip]
8585
end
8686
end
8787

88+
# test for https://github.com/SciML/OrdinaryDiffEq.jl/issues/2653#issuecomment-2778430025
89+
8890
function sparse_f!(du, u, p, t)
8991
du[1] = u[1] + u[2]
9092
du[2] = u[3]^2
9193
return du[3] = u[1]^2
9294
end
9395

94-
backend_allow = AutoSparse(
95-
AutoForwardDiff();
96-
sparsity_detector = TracerSparsityDetector(),
97-
coloring_algorithm = GreedyColoringAlgorithm(; allow_denser = true)
98-
)
99-
100-
backend_no_allow = AutoSparse(
96+
backend = AutoSparse(
10197
AutoForwardDiff();
10298
sparsity_detector = TracerSparsityDetector(),
10399
coloring_algorithm = GreedyColoringAlgorithm()
@@ -107,33 +103,19 @@ u = ones(3)
107103
du = zero(u)
108104
p = t = nothing
109105

110-
prep_allow = DI.prepare_jacobian(
111-
sparse_f!, du, backend_allow, u, DI.Constant(p), DI.Constant(t))
112-
prep_no_allow = DI.prepare_jacobian(
113-
sparse_f!, du, backend_no_allow, u, DI.Constant(p), DI.Constant(t))
106+
prep = DI.prepare_jacobian(
107+
sparse_f!, du, backend, u, DI.Constant(p), DI.Constant(t))
114108
# this is what the user may typically provide to the ODE problem
115109

116-
function inplace_jac_allow!(J, u, p, t)
110+
function inplace_jac!(J, u, p, t)
117111
return DI.jacobian!(
118-
sparse_f!, zeros(3), J, prep_allow, backend_allow, u, DI.Constant(p), DI.Constant(t))
112+
sparse_f!, zeros(3), J, prep, backend, u, DI.Constant(p), DI.Constant(t))
119113
end
120114

121-
function inplace_jac_no_allow!(J, u, p, t)
122-
return DI.jacobian!(
123-
sparse_f!, zeros(3), J, prep_no_allow, backend_no_allow, u, DI.Constant(p), DI.Constant(t))
124-
end
125-
126-
jac_prototype = similar(sparsity_pattern(prep_allow), eltype(u))
127-
128-
ode_f_allow = ODEFunction(
129-
sparse_f!, jac = inplace_jac_allow!, jac_prototype = jac_prototype)
130-
prob_allow = ODEProblem(ode_f_allow, [1, 1, 1], (0.0, 1.0))
131-
132-
ode_f_no_allow = ODEFunction(
133-
sparse_f!, jac = inplace_jac_no_allow!, jac_prototype = jac_prototype)
134-
prob_no_allow = ODEProblem(ode_f_no_allow, [1, 1, 1], (0.0, 1.0))
115+
jac_prototype = similar(sparsity_pattern(prep), eltype(u))
135116

136-
sol = solve(prob_allow, Rodas5())
117+
ode_f = ODEFunction(sparse_f!, jac = inplace_jac!, jac_prototype = jac_prototype)
118+
prob = ODEProblem(ode_f, [1, 1, 1], (0.0, 1.0))
137119

138-
@test_throws DimensionMismatch sol=solve(prob_no_allow, Rodas5())
120+
@test_no_warn sol = solve(prob, Rodas5())
139121

0 commit comments

Comments
 (0)