From 4be628ecb487b3fd8575f748ada6f469608f33ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Tue, 3 Aug 2021 21:59:51 +0200 Subject: [PATCH] Fix CRSMatrix::operator-() --- src/algebra/CRSMatrix.hpp | 4 ++-- tests/test_CRSMatrix.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/algebra/CRSMatrix.hpp b/src/algebra/CRSMatrix.hpp index 4b88cd80c..c2df50e45 100644 --- a/src/algebra/CRSMatrix.hpp +++ b/src/algebra/CRSMatrix.hpp @@ -123,12 +123,12 @@ class CRSMatrix ++i_row_B; } else if (A_column_idx < B_column_idx) { column_indices[i_value] = A_column_idx; - values[i_value] = A.m_values[i_row_A]; + values[i_value] = BinOp()(A.m_values[i_row_A], 0); ++i_row_A; } else { Assert(B_column_idx < A_column_idx); column_indices[i_value] = B_column_idx; - values[i_value] = B.m_values[i_row_B]; + values[i_value] = BinOp()(0, B.m_values[i_row_B]); ++i_row_B; } ++i_value; diff --git a/tests/test_CRSMatrix.cpp b/tests/test_CRSMatrix.cpp index f4bce5a42..cf6d65b87 100644 --- a/tests/test_CRSMatrix.cpp +++ b/tests/test_CRSMatrix.cpp @@ -240,8 +240,8 @@ TEST_CASE("CRSMatrix", "[algebra]") std::ostringstream ost; ost << A - B; - std::string ref = R"(0| 0:2 1:2 2:3 -1| 0:-2 1:6 2:3 + std::string ref = R"(0| 0:2 1:2 2:-3 +1| 0:-2 1:6 2:-3 2| 0:2 2:-11 3:12 3| 0:10 3:8 )"; @@ -327,10 +327,10 @@ TEST_CASE("CRSMatrix", "[algebra]") std::ostringstream ost; ost << A - B; - std::string ref = R"(0| 0:2 1:2 2:3 -1| 0:-2 1:6 2:3 + std::string ref = R"(0| 0:2 1:2 2:-3 +1| 0:-2 1:6 2:-3 2| 0:2 2:1 -3| 0:10 1:8 2:16 +3| 0:10 1:-8 2:16 )"; REQUIRE(ost.str() == ref); -- GitLab