From 62179fb563f00b6f0e02e7880dc8d382f9744d88 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Tue, 8 Oct 2024 13:43:01 +0200 Subject: [PATCH] Fix AmiVector::nvec_ for size 0 --- include/amici/vector.h | 3 +-- src/solver.cpp | 2 +- src/vector.cpp | 10 +++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/amici/vector.h b/include/amici/vector.h index 72da7a9230..32c436fbda 100644 --- a/include/amici/vector.h +++ b/include/amici/vector.h @@ -88,8 +88,7 @@ class AmiVector { return; } nvec_ = N_VMake_Serial( - gsl::narrow(vold.vec_.size()), vec_.data(), - vold.nvec_->sunctx + gsl::narrow(vec_.size()), vec_.data(), vold.nvec_->sunctx ); } diff --git a/src/solver.cpp b/src/solver.cpp index c4fcc72399..5c96855d97 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -769,7 +769,7 @@ void Solver::setConstraints(std::vector const& constraints) { if (!any_constraint) { // all-0 must be converted to empty, otherwise sundials will fail - constraints_ = AmiVector(); + constraints_ = AmiVector(0, sunctx_); return; } diff --git a/src/vector.cpp b/src/vector.cpp index 199a50b31b..78b3fe5521 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -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(vec_.size()), vec_.data(), sunctx - ); + if (sunctx) { + nvec_ = N_VMake_Serial( + gsl::narrow(vec_.size()), vec_.data(), sunctx + ); + } } AmiVector::~AmiVector() {