From 4018157049f0c6e06a589b43ff6081d13cd9e521 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Thu, 9 Feb 2017 09:51:00 +0100
Subject: [PATCH] [MaL] EigenMatrix: set/add values even if 0.

Under certain circumstances the sparsity pattern will be destroyed and
adding/setting values would then result in an expensive reallocation.

Assume that in the first global iteration only one half of the values is
set to non-zero. Before the linear solver is called the sparse matrix is
compressed thus reducing the allocated space in each row. In the
subsequent iterations, which might add or set the other half of the
matrix values reallocations would be necessary.
---
 MathLib/LinAlg/Eigen/EigenMatrix.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MathLib/LinAlg/Eigen/EigenMatrix.h b/MathLib/LinAlg/Eigen/EigenMatrix.h
index 7e0dd62a669..22d523efd1e 100644
--- a/MathLib/LinAlg/Eigen/EigenMatrix.h
+++ b/MathLib/LinAlg/Eigen/EigenMatrix.h
@@ -71,7 +71,7 @@ public:
     int setValue(IndexType row, IndexType col, double val)
     {
         assert(row < (IndexType) getNumberOfRows() && col < (IndexType) getNumberOfColumns());
-        if (val != 0.0) _mat.coeffRef(row, col) = val;
+        _mat.coeffRef(row, col) = val;
         return 0;
     }
 
@@ -79,7 +79,7 @@ public:
     /// inserted.
     int add(IndexType row, IndexType col, double val)
     {
-        if (val != 0.0) _mat.coeffRef(row, col) += val;
+        _mat.coeffRef(row, col) += val;
         return 0;
     }
 
-- 
GitLab