Skip to content

Commit

Permalink
Fix size check in Model::setStateIsNonNegative (#2332)
Browse files Browse the repository at this point in the history
Previously, the wrong array was checked 🙈:

```python
amici_model.setAllStatesNonNegative()
amici_model.setStateIsNonNegative([])
amici_model.setAllStatesNonNegative()

Traceback (most recent call last):
  File "<ipython-input-22-d7056e8e4e3f>", line 1, in <module>
    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)
```
  • Loading branch information
dweindl authored Mar 4, 2024
1 parent 239ce2c commit 4a065e6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,11 @@ void Model::setStateIsNonNegative(std::vector<bool> const& nonNegative) {
// in case of conservation laws
return;
}
if (state_is_non_negative_.size() != gsl::narrow<unsigned long>(nx_rdata)) {
if (nonNegative.size() != gsl::narrow<unsigned long>(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;
Expand Down

0 comments on commit 4a065e6

Please sign in to comment.