Skip to content

Commit

Permalink
Fix AmiVector::nvec_ for size 0
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Oct 9, 2024
1 parent 2784887 commit 62179fb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions include/amici/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ class AmiVector {
return;
}
nvec_ = N_VMake_Serial(
gsl::narrow<long int>(vold.vec_.size()), vec_.data(),
vold.nvec_->sunctx
gsl::narrow<long int>(vec_.size()), vec_.data(), vold.nvec_->sunctx
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ void Solver::setConstraints(std::vector<realtype> const& constraints) {

if (!any_constraint) {
// all-0 must be converted to empty, otherwise sundials will fail
constraints_ = AmiVector();
constraints_ = AmiVector(0, sunctx_);
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ void AmiVector::copy(AmiVector const& other) {
void AmiVector::synchroniseNVector(SUNContext sunctx) {
if (nvec_)
N_VDestroy_Serial(nvec_);
nvec_ = vec_.empty()
? nullptr
: N_VMake_Serial(
gsl::narrow<long int>(vec_.size()), vec_.data(), sunctx
);
if (sunctx) {
nvec_ = N_VMake_Serial(
gsl::narrow<long int>(vec_.size()), vec_.data(), sunctx
);
}
}

AmiVector::~AmiVector() {
Expand Down

0 comments on commit 62179fb

Please sign in to comment.