From aa284365ccd13a0b8fcc3a26dc44030ea07b27cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Del=20Pino?= <stephane.delpino44@gmail.com> Date: Thu, 24 Jun 2021 17:03:11 +0200 Subject: [PATCH] Fix DenseMatrix API --- src/algebra/DenseMatrix.hpp | 32 +++++++++++++++++--------------- src/algebra/PETScUtils.hpp | 4 +++- tests/test_DenseMatrix.cpp | 4 ++-- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/algebra/DenseMatrix.hpp b/src/algebra/DenseMatrix.hpp index 8c1078faa..a48dc1871 100644 --- a/src/algebra/DenseMatrix.hpp +++ b/src/algebra/DenseMatrix.hpp @@ -81,12 +81,12 @@ class DenseMatrix // LCOV_EXCL_LINE PUGS_INLINE DenseMatrix<std::remove_const_t<DataType2>> operator*(const DenseMatrix<DataType2>& B) const { - Assert(m_nb_columns == B.nbRows()); + Assert(m_nb_columns == B.numberOfRows()); const DenseMatrix& A = *this; - DenseMatrix<std::remove_const_t<DataType>> AB{m_nb_rows, B.nbColumns()}; + DenseMatrix<std::remove_const_t<DataType>> AB{m_nb_rows, B.numberOfColumns()}; for (size_t i = 0; i < m_nb_rows; ++i) { - for (size_t j = 0; j < B.nbColumns(); ++j) { + for (size_t j = 0; j < B.numberOfColumns(); ++j) { DataType2 ABij = 0; for (size_t k = 0; k < m_nb_columns; ++k) { ABij += A(i, k) * B(k, j); @@ -118,8 +118,8 @@ class DenseMatrix // LCOV_EXCL_LINE PUGS_INLINE DenseMatrix& operator-=(const DenseMatrix<DataType2>& B) { - Assert(m_nb_rows == B.nbRows()); - Assert(m_nb_columns == B.nbColumns()); + Assert(m_nb_rows == B.numberOfRows()); + Assert(m_nb_columns == B.numberOfColumns()); parallel_for( m_values.size(), PUGS_LAMBDA(index_type i) { m_values[i] -= B.m_values[i]; }); @@ -130,8 +130,8 @@ class DenseMatrix // LCOV_EXCL_LINE PUGS_INLINE DenseMatrix& operator+=(const DenseMatrix<DataType2>& B) { - Assert(m_nb_rows == B.nbRows()); - Assert(m_nb_columns == B.nbColumns()); + Assert(m_nb_rows == B.numberOfRows()); + Assert(m_nb_columns == B.numberOfColumns()); parallel_for( m_values.size(), PUGS_LAMBDA(index_type i) { m_values[i] += B.m_values[i]; }); @@ -142,9 +142,9 @@ class DenseMatrix // LCOV_EXCL_LINE PUGS_INLINE DenseMatrix<std::remove_const_t<DataType>> operator+(const DenseMatrix<DataType2>& B) const { - Assert(m_nb_rows == B.nbRows()); - Assert(m_nb_columns == B.nbColumns()); - DenseMatrix<std::remove_const_t<DataType>> sum{B.nbRows(), B.nbColumns()}; + Assert(m_nb_rows == B.numberOfRows()); + Assert(m_nb_columns == B.numberOfColumns()); + DenseMatrix<std::remove_const_t<DataType>> sum{B.numberOfRows(), B.numberOfColumns()}; parallel_for( m_values.size(), PUGS_LAMBDA(index_type i) { sum.m_values[i] = m_values[i] + B.m_values[i]; }); @@ -156,9 +156,9 @@ class DenseMatrix // LCOV_EXCL_LINE PUGS_INLINE DenseMatrix<std::remove_const_t<DataType>> operator-(const DenseMatrix<DataType2>& B) const { - Assert(m_nb_rows == B.nbRows()); - Assert(m_nb_columns == B.nbColumns()); - DenseMatrix<std::remove_const_t<DataType>> difference{B.nbRows(), B.nbColumns()}; + Assert(m_nb_rows == B.numberOfRows()); + Assert(m_nb_columns == B.numberOfColumns()); + DenseMatrix<std::remove_const_t<DataType>> difference{B.numberOfRows(), B.numberOfColumns()}; parallel_for( m_values.size(), PUGS_LAMBDA(index_type i) { difference.m_values[i] = m_values[i] - B.m_values[i]; }); @@ -176,14 +176,14 @@ class DenseMatrix // LCOV_EXCL_LINE PUGS_INLINE size_t - nbRows() const noexcept + numberOfRows() const noexcept { return m_nb_rows; } PUGS_INLINE size_t - nbColumns() const noexcept + numberOfColumns() const noexcept { return m_nb_columns; } @@ -268,6 +268,8 @@ class DenseMatrix // LCOV_EXCL_LINE }); } + DenseMatrix() noexcept : m_nb_rows{0}, m_nb_columns{0} {} + private: DenseMatrix(size_t nb_rows, size_t nb_columns, const Array<DataType> values) noexcept(NO_ASSERT) : m_nb_rows{nb_rows}, m_nb_columns{nb_columns}, m_values{values} diff --git a/src/algebra/PETScUtils.hpp b/src/algebra/PETScUtils.hpp index cdb092545..68748c02f 100644 --- a/src/algebra/PETScUtils.hpp +++ b/src/algebra/PETScUtils.hpp @@ -53,7 +53,9 @@ class PETScAijMatrixEmbedder PETScAijMatrixEmbedder(const TinyMatrix<N>& A) : PETScAijMatrixEmbedder{N, N, &A(0, 0)} {} - PETScAijMatrixEmbedder(const DenseMatrix<double>& A) : PETScAijMatrixEmbedder{A.nbRows(), A.nbColumns(), &A(0, 0)} {} + PETScAijMatrixEmbedder(const DenseMatrix<double>& A) + : PETScAijMatrixEmbedder{A.numberOfRows(), A.numberOfColumns(), &A(0, 0)} + {} PETScAijMatrixEmbedder(const CRSMatrix<double, size_t>& A); diff --git a/tests/test_DenseMatrix.cpp b/tests/test_DenseMatrix.cpp index 7fcf8059e..6e2470fa0 100644 --- a/tests/test_DenseMatrix.cpp +++ b/tests/test_DenseMatrix.cpp @@ -16,8 +16,8 @@ TEST_CASE("DenseMatrix", "[algebra]") SECTION("size") { DenseMatrix<int> A{2, 3}; - REQUIRE(A.nbRows() == 2); - REQUIRE(A.nbColumns() == 3); + REQUIRE(A.numberOfRows() == 2); + REQUIRE(A.numberOfColumns() == 3); } SECTION("write access") -- GitLab