Skip to content

Commit 92a7a9a

Browse files
committed
Fix crash for models without state variables
Previously, `nx_solver=0` would have in a crash when calling `amici::SUNMatrixWrapper::capacity` on 0-sized `SUNMatrixWrapper`. Unrelated: Replace some unnecessary `std::vector::at` calls.
1 parent 9ea6aef commit 92a7a9a

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/model.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,25 +2875,26 @@ void Model::fdwdp(realtype const t, realtype const* x, bool include_static) {
28752875
}
28762876

28772877
void Model::fdwdx(realtype const t, realtype const* x, bool include_static) {
2878-
if (!nw)
2878+
if (!nw || !nx_solver)
28792879
return;
28802880

28812881
fw(t, x, include_static);
28822882

28832883
derived_state_.dwdx_.zero();
28842884
if (pythonGenerated) {
2885-
if (!derived_state_.dwdx_hierarchical_.at(0).capacity())
2885+
auto dwdx_hierarchical_0 = derived_state_.dwdx_hierarchical_.at(0);
2886+
if (!dwdx_hierarchical_0.capacity())
28862887
return;
28872888

28882889
fdwdw(t, x, include_static);
28892890

28902891
if (include_static) {
2891-
derived_state_.dwdx_hierarchical_.at(0).zero();
2892-
fdwdx_colptrs(derived_state_.dwdx_hierarchical_.at(0));
2893-
fdwdx_rowvals(derived_state_.dwdx_hierarchical_.at(0));
2892+
dwdx_hierarchical_0.zero();
2893+
fdwdx_colptrs(dwdx_hierarchical_0);
2894+
fdwdx_rowvals(dwdx_hierarchical_0);
28942895
}
28952896
fdwdx(
2896-
derived_state_.dwdx_hierarchical_.at(0).data(), t, x,
2897+
dwdx_hierarchical_0.data(), t, x,
28972898
state_.unscaledParameters.data(), state_.fixedParameters.data(),
28982899
state_.h.data(), derived_state_.w_.data(), state_.total_cl.data(),
28992900
derived_state_.spl_.data(), include_static

0 commit comments

Comments
 (0)