diff --git a/src/antenna/model/phased-array-model.h b/src/antenna/model/phased-array-model.h index d7cba8b81..563bb8b3c 100644 --- a/src/antenna/model/phased-array-model.h +++ b/src/antenna/model/phased-array-model.h @@ -61,7 +61,7 @@ class PhasedArrayModel : public Object * \param complexVector on which to calculate Frobenius norm * \return the Frobenius norm of the complex vector */ - double norm(ComplexVector& complexVector) const + double norm(const ComplexVector& complexVector) const { double norm = 0; for (size_t i = 0; i < complexVector.GetSize(); i++) diff --git a/src/core/model/matrix-array.cc b/src/core/model/matrix-array.cc index 6d63591cf..affa42e6a 100644 --- a/src/core/model/matrix-array.cc +++ b/src/core/model/matrix-array.cc @@ -35,7 +35,9 @@ using ConstEigenMatrix = Eigen::Map MatrixArray::MatrixArray(uint16_t numRows, uint16_t numCols, uint16_t numPages) - : ValArray(numRows, numCols, numPages){}; + : ValArray(numRows, numCols, numPages) +{ +} template MatrixArray::MatrixArray(const std::valarray& values) @@ -57,25 +59,33 @@ MatrixArray::MatrixArray(const std::vector& values) template MatrixArray::MatrixArray(uint16_t numRows, uint16_t numCols, const std::valarray& values) - : ValArray(numRows, numCols, values){}; + : ValArray(numRows, numCols, values) +{ +} template MatrixArray::MatrixArray(uint16_t numRows, uint16_t numCols, std::valarray&& values) - : ValArray(numRows, numCols, std::move(values)){}; + : ValArray(numRows, numCols, std::move(values)) +{ +} template MatrixArray::MatrixArray(uint16_t numRows, uint16_t numCols, uint16_t numPages, const std::valarray& values) - : ValArray(numRows, numCols, numPages, values){}; + : ValArray(numRows, numCols, numPages, values) +{ +} template MatrixArray::MatrixArray(uint16_t numRows, uint16_t numCols, uint16_t numPages, std::valarray&& values) - : ValArray(numRows, numCols, numPages, std::move(values)){}; + : ValArray(numRows, numCols, numPages, std::move(values)) +{ +} template MatrixArray @@ -86,7 +96,7 @@ MatrixArray::operator*(const MatrixArray& rhs) const MatrixArray res{m_numRows, rhs.m_numCols, m_numPages}; - for (auto page = 0; page < res.m_numPages; ++page) + for (uint16_t page = 0; page < res.m_numPages; ++page) { #ifdef HAVE_EIGEN3 // Eigen found and enabled Eigen optimizations @@ -98,9 +108,9 @@ MatrixArray::operator*(const MatrixArray& rhs) const #else // Eigen not found or Eigen optimizations not enabled size_t matrixOffset = page * m_numRows * m_numCols; - for (auto i = 0; i < res.m_numRows; ++i) + for (uint16_t i = 0; i < res.m_numRows; ++i) { - for (auto j = 0; j < res.m_numCols; ++j) + for (uint16_t j = 0; j < res.m_numCols; ++j) { res(i, j, page) = (m_values[std::slice(matrixOffset + i, m_numCols, m_numRows)] * @@ -118,12 +128,11 @@ template MatrixArray MatrixArray::Transpose() const { - MatrixArray res{m_numCols, - m_numRows, - m_numPages}; // create the matrix where m_numRows = this.m_numCols, m_numCols - // = this.m_numRows, m_numPages = this.m_numPages + // Create the matrix where m_numRows = this.m_numCols, m_numCols = this.m_numRows, + // m_numPages = this.m_numPages + MatrixArray res{m_numCols, m_numRows, m_numPages}; - for (auto page = 0; page < m_numPages; ++page) + for (uint16_t page = 0; page < m_numPages; ++page) { #ifdef HAVE_EIGEN3 // Eigen found and Eigen optimizations enabled @@ -134,7 +143,7 @@ MatrixArray::Transpose() const #else // Eigen not found or Eigen optimizations not enabled size_t matrixIndex = page * m_numRows * m_numCols; - for (auto i = 0; i < m_numRows; ++i) + for (uint16_t i = 0; i < m_numRows; ++i) { res.m_values[std::slice(matrixIndex + i * res.m_numRows, res.m_numRows, 1)] = m_values[std::slice(matrixIndex + i, m_numCols, m_numRows)]; @@ -165,7 +174,7 @@ MatrixArray::MultiplyByLeftAndRightMatrix(const MatrixArray& lMatrix, ConstEigenMatrix rMatrixEigen(rMatrix.GetPagePtr(0), rMatrix.m_numRows, rMatrix.m_numCols); #endif - for (auto page = 0; page < m_numPages; ++page) + for (uint16_t page = 0; page < m_numPages; ++page) { #ifdef HAVE_EIGEN3 // Eigen found and Eigen optimizations enabled @@ -177,14 +186,14 @@ MatrixArray::MultiplyByLeftAndRightMatrix(const MatrixArray& lMatrix, #else // Eigen not found or Eigen optimizations not enabled size_t matrixOffset = page * m_numRows * m_numCols; - for (auto resRow = 0; resRow < res.m_numRows; ++resRow) + for (uint16_t resRow = 0; resRow < res.m_numRows; ++resRow) { - for (auto resCol = 0; resCol < res.m_numCols; ++resCol) + for (uint16_t resCol = 0; resCol < res.m_numCols; ++resCol) { // create intermediate row result, a multiply of resRow row of lMatrix and each // column of this matrix std::valarray interRes(m_numCols); - for (auto thisCol = 0; thisCol < m_numCols; ++thisCol) + for (uint16_t thisCol = 0; thisCol < m_numCols; ++thisCol) { interRes[thisCol] = (lMatrix diff --git a/src/core/model/matrix-array.h b/src/core/model/matrix-array.h index b5628d5ae..fac127c77 100644 --- a/src/core/model/matrix-array.h +++ b/src/core/model/matrix-array.h @@ -261,11 +261,14 @@ class MatrixArray : public ValArray using ValArray::m_values; }; -using IntMatrixArray = MatrixArray; //!< Create an alias for MatrixArray using int type -using DoubleMatrixArray = - MatrixArray; //!< Create an alias for MatrixArray using double type -using ComplexMatrixArray = - MatrixArray>; //!< Create an alias for MatrixArray using complex type +/// Create an alias for MatrixArray using int type +using IntMatrixArray = MatrixArray; + +/// Create an alias for MatrixArray using double type +using DoubleMatrixArray = MatrixArray; + +/// Create an alias for MatrixArray using complex type +using ComplexMatrixArray = MatrixArray>; /************************************************* ** Class MatrixArray inline implementations diff --git a/src/core/test/val-array-test-suite.cc b/src/core/test/val-array-test-suite.cc index 77f77c93b..b7e5c5814 100644 --- a/src/core/test/val-array-test-suite.cc +++ b/src/core/test/val-array-test-suite.cc @@ -75,7 +75,6 @@ class ValArrayTestCase : public TestCase */ ValArrayTestCase& operator=(ValArrayTestCase&&) noexcept = default; - protected: private: void DoRun() override; }; @@ -96,9 +95,9 @@ void ValArrayTestCase::DoRun() { ValArray v1 = ValArray(2, 3); - for (auto i = 0; i < v1.GetNumRows(); ++i) + for (uint16_t i = 0; i < v1.GetNumRows(); ++i) { - for (auto j = 0; j < v1.GetNumCols(); ++j) + for (uint16_t j = 0; j < v1.GetNumCols(); ++j) { v1(i, j) = 1; } @@ -109,9 +108,9 @@ ValArrayTestCase::DoRun() NS_TEST_ASSERT_MSG_EQ(v1.GetNumCols(), v2.GetNumCols(), "The number of cols are not equal."); // test copy constructor - for (auto i = 0; i < v1.GetNumRows(); ++i) + for (uint16_t i = 0; i < v1.GetNumRows(); ++i) { - for (auto j = 0; j < v1.GetNumCols(); ++j) + for (uint16_t j = 0; j < v1.GetNumCols(); ++j) { NS_TEST_ASSERT_MSG_EQ(v1(i, j), v2(i, j), "The elements are not equal."); } @@ -121,9 +120,9 @@ ValArrayTestCase::DoRun() ValArray v3 = v1; NS_TEST_ASSERT_MSG_EQ(v1.GetNumRows(), v3.GetNumRows(), "The number of rows are not equal."); NS_TEST_ASSERT_MSG_EQ(v1.GetNumCols(), v3.GetNumCols(), "The number of cols are not equal."); - for (auto i = 0; i < v1.GetNumRows(); ++i) + for (uint16_t i = 0; i < v1.GetNumRows(); ++i) { - for (auto j = 0; j < v1.GetNumCols(); ++j) + for (uint16_t j = 0; j < v1.GetNumCols(); ++j) { NS_TEST_ASSERT_MSG_EQ(v1(i, j), v2(i, j), "The elements are not equal."); } @@ -153,7 +152,7 @@ ValArrayTestCase::DoRun() } ValArray v6 = ValArray(2, 4, valArray1); - // test constructro that moves valArray + // test constructor that moves valArray NS_LOG_INFO("valarray1 size before move: " << valArray1.size()); ValArray v11 = ValArray(2, 4, std::move(valArray1)); NS_LOG_INFO("valarray1 size after move: " << valArray1.size()); @@ -163,9 +162,9 @@ ValArrayTestCase::DoRun() // also in the access operator if we iterate over rows first we should find 0, 2, 4, 6, ... std::valarray initArray2{0, 2, 4, 6, 1, 3, 5, 7}; auto testIndex = 0; - for (auto i = 0; i < v6.GetNumRows(); ++i) + for (uint16_t i = 0; i < v6.GetNumRows(); ++i) { - for (auto j = 0; j < v6.GetNumCols(); ++j) + for (uint16_t j = 0; j < v6.GetNumCols(); ++j) { NS_TEST_ASSERT_MSG_EQ(v6(i, j), static_cast(initArray2[testIndex]), @@ -188,11 +187,11 @@ ValArrayTestCase::DoRun() // if we iterate over rows first we should find 0, 2, 4, 6, ... std::valarray initArray4{0, 2, 4, 6, 1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7}; testIndex = 0; - for (auto p = 0; p < v7.GetNumPages(); ++p) + for (uint16_t p = 0; p < v7.GetNumPages(); ++p) { - for (auto i = 0; i < v7.GetNumRows(); ++i) + for (uint16_t i = 0; i < v7.GetNumRows(); ++i) { - for (auto j = 0; j < v7.GetNumCols(); ++j) + for (uint16_t j = 0; j < v7.GetNumCols(); ++j) { NS_TEST_ASSERT_MSG_EQ(v7(i, j, p), static_cast(initArray4[testIndex]), @@ -204,11 +203,11 @@ ValArrayTestCase::DoRun() // multiplication with a scalar value with 3D array ValArray v8 = v7 * (static_cast(5.0)); - for (auto p = 0; p < v8.GetNumPages(); ++p) + for (uint16_t p = 0; p < v8.GetNumPages(); ++p) { - for (auto i = 0; i < v8.GetNumRows(); ++i) + for (uint16_t i = 0; i < v8.GetNumRows(); ++i) { - for (auto j = 0; j < v8.GetNumCols(); ++j) + for (uint16_t j = 0; j < v8.GetNumCols(); ++j) { NS_TEST_ASSERT_MSG_EQ(v7(i, j, p) * (static_cast(5.0)), v8(i, j, p), @@ -246,7 +245,7 @@ ValArrayTestCase::DoRun() true, "Matrices should be almost equal, but not equal."); - // test the inicialization with std::vector + // test the initialization with std::vector ValArray v12 = ValArray(std::vector({1, 2, 3})); NS_LOG_INFO("v12:" << v12); }