Skip to content

Commit 7e84b9c

Browse files
Merge pull request #869 from Keno/kf/emptymm
Allow empty mass matrix for empty u0
2 parents 2456c53 + 351fef5 commit 7e84b9c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/solve.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,10 +1125,11 @@ function get_concrete_u0(prob, isadapt, t0, kwargs)
11251125
throw(IncompatibleInitialConditionError())
11261126
end
11271127

1128+
nu0 = length(something(_u0, ()))
11281129
if isdefined(prob.f, :mass_matrix) && prob.f.mass_matrix !== nothing &&
11291130
prob.f.mass_matrix isa AbstractArray &&
1130-
size(prob.f.mass_matrix, 1) !== length(_u0)
1131-
throw(IncompatibleMassMatrixError(size(prob.f.mass_matrix, 1), length(_u0)))
1131+
size(prob.f.mass_matrix, 1) !== nu0
1132+
throw(IncompatibleMassMatrixError(size(prob.f.mass_matrix, 1), nu0))
11321133
end
11331134

11341135
if _u0 isa Tuple

test/downstream/solve_error_handling.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ prob = ODEProblem{false}(f, (1.0, 1.0f0), tspan)
3737
prob = ODEProblem{false}(f, u0, (0.0 + im, 1.0))
3838
@test_throws DiffEqBase.ComplexTspanError solve(prob, Tsit5())
3939

40-
u0 = [0.0, 0.0]
41-
fmm = ODEFunction(f, mass_matrix = zeros(3, 3))
42-
prob = ODEProblem(fmm, u0, (0.0, 1.0))
43-
@test_throws DiffEqBase.IncompatibleMassMatrixError solve(prob, Tsit5())
40+
for u0 in ([0.0, 0.0], nothing)
41+
fmm = ODEFunction(f, mass_matrix = zeros(3, 3))
42+
prob = ODEProblem(fmm, u0, (0.0, 1.0))
43+
@test_throws DiffEqBase.IncompatibleMassMatrixError solve(prob, Tsit5())
44+
end
45+
46+
# Allow empty mass matrix for empty u0
47+
fmm = ODEFunction((du, u, t)->nothing, mass_matrix = zeros(0, 0))
48+
prob = ODEProblem(fmm, nothing, (0., 1.))
49+
sol = solve(prob, Tsit5())
50+
@test isa(sol, DiffEqBase.ODESolution)

0 commit comments

Comments
 (0)