From 4a065e62f8a73a813fb464b00bc5d6cee64c1d09 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 4 Mar 2024 07:46:27 +0100 Subject: [PATCH] Fix size check in `Model::setStateIsNonNegative` (#2332) Previously, the wrong array was checked :see_no_evil:: ```python amici_model.setAllStatesNonNegative() amici_model.setStateIsNonNegative([]) amici_model.setAllStatesNonNegative() Traceback (most recent call last): File "", line 1, in amici_model.setAllStatesNonNegative() File "python/sdist/amici/amici.py", line 2243, in setAllStatesNonNegative return _amici.ModelPtr_setAllStatesNonNegative(self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: Dimension of input stateIsNonNegative (0) does not agree with number of state variables (2) ``` --- src/model.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/model.cpp b/src/model.cpp index 54363d8d1b..b671de3c73 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -883,11 +883,11 @@ void Model::setStateIsNonNegative(std::vector const& nonNegative) { // in case of conservation laws return; } - if (state_is_non_negative_.size() != gsl::narrow(nx_rdata)) { + if (nonNegative.size() != gsl::narrow(nx_rdata)) { throw AmiException( "Dimension of input stateIsNonNegative (%u) does " "not agree with number of state variables (%d)", - state_is_non_negative_.size(), nx_rdata + nonNegative.size(), nx_rdata ); } state_is_non_negative_ = nonNegative;