13#if defined(__GNUC__) && !defined(__clang__)
14#pragma GCC diagnostic push
15#pragma GCC diagnostic ignored "-Wclass-memaccess"
16#pragma GCC diagnostic ignored "-Wunused-variable"
21#if defined(__GNUC__) && !defined(__clang__)
22#pragma GCC diagnostic pop
31using EigenMatrix = Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>>;
33using ConstEigenMatrix = Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>>;
38 :
ValArray<T>(numRows, numCols, numPages)
62 :
ValArray<T>(numRows, numCols, values)
76 const std::valarray<T>& values)
77 :
ValArray<T>(numRows, numCols, numPages, values)
85 std::valarray<T>&& values)
86 :
ValArray<T>(numRows, numCols, numPages,
std::move(values))
99 for (
size_t page = 0; page < res.m_numPages; ++page)
103 ConstEigenMatrix<T> lhsEigenMatrix(GetPagePtr(page), m_numRows, m_numCols);
105 EigenMatrix<T> resEigenMatrix(res.GetPagePtr(page), res.m_numRows, res.m_numCols);
106 resEigenMatrix = lhsEigenMatrix * rhsEigenMatrix;
110 size_t matrixOffset = page * m_numRows * m_numCols;
112 for (
size_t i = 0; i < res.m_numRows; ++i)
114 for (
size_t j = 0; j < res.m_numCols; ++j)
116 res(i, j, page) = (m_values[std::slice(matrixOffset + i, m_numCols, m_numRows)] *
137 for (
size_t page = 0; page < m_numPages; ++page)
141 ConstEigenMatrix<T> thisMatrix(GetPagePtr(page), m_numRows, m_numCols);
142 EigenMatrix<T> resEigenMatrix(res.GetPagePtr(page), res.m_numRows, res.m_numCols);
143 resEigenMatrix = thisMatrix.transpose();
147 size_t matrixIndex = page * m_numRows * m_numCols;
148 for (
size_t i = 0; i < m_numRows; ++i)
150 res.m_values[std::slice(matrixIndex + i * res.m_numRows, res.m_numRows, 1)] =
151 m_values[std::slice(matrixIndex + i, m_numCols, m_numRows)];
164 NS_ASSERT_MSG(m_numRows == m_numCols,
"Matrix is not square");
171 for (
size_t page = 0; page < m_numPages; ++page)
174 auto pageValues = GetPagePtr(page);
179 res(0, 0, page) = pageValues[0] * pageValues[3] - pageValues[1] * pageValues[2];
182 for (
size_t detN = 0; detN < m_numRows; detN++)
184 auto partDetP = T{0} + 1.0;
185 auto partDetN = T{0} + 1.0;
186 for (
size_t row = 0; row < m_numRows; row++)
190 size_t col = (row + detN) % m_numCols;
191 partDetP *= pageValues[row * m_numCols + col];
194 col = m_numCols - 1 - (row + detN) % m_numCols;
195 partDetN *= pageValues[row * m_numCols + col];
197 res(0, 0, page) += partDetP - partDetN;
208 for (
size_t page = 0; page < m_numPages; ++page)
212 auto pagePtr = this->GetPagePtr(page);
213 for (
size_t i = 0; i < m_numRows * m_numCols; i++)
215 auto absVal = std::abs(pagePtr[i]);
216 res[page] += absVal * absVal;
218 res[page] = sqrt(res[page]);
229 "The left and right MatrixArray should have only one page.");
231 "Left vector numCols and this MatrixArray numRows mismatch.");
233 "Right vector numRows and this MatrixArray numCols mismatch.");
235 MatrixArray<T> res{lMatrix.m_numRows, rMatrix.m_numCols, m_numPages};
239 ConstEigenMatrix<T> lMatrixEigen(lMatrix.GetPagePtr(0), lMatrix.m_numRows, lMatrix.m_numCols);
240 ConstEigenMatrix<T> rMatrixEigen(rMatrix.GetPagePtr(0), rMatrix.m_numRows, rMatrix.m_numCols);
243 for (
size_t page = 0; page < m_numPages; ++page)
247 ConstEigenMatrix<T> matrixEigen(GetPagePtr(page), m_numRows, m_numCols);
248 EigenMatrix<T> resEigenMap(res.GetPagePtr(page), res.m_numRows, res.m_numCols);
250 resEigenMap = lMatrixEigen * matrixEigen * rMatrixEigen;
254 size_t matrixOffset = page * m_numRows * m_numCols;
255 for (
size_t resRow = 0; resRow < res.m_numRows; ++resRow)
257 for (
size_t resCol = 0; resCol < res.m_numCols; ++resCol)
261 std::valarray<T> interRes(m_numCols);
262 for (
size_t thisCol = 0; thisCol < m_numCols; ++thisCol)
266 .m_values[std::slice(resRow, lMatrix.m_numCols, lMatrix.m_numRows)] *
267 m_values[std::slice(matrixOffset + thisCol * m_numRows, m_numRows, 1)])
271 res(resRow, resCol, page) =
273 rMatrix.m_values[std::slice(resCol * rMatrix.m_numRows, rMatrix.m_numRows, 1)])
283template <
bool EnableBool,
typename>
289 for (
size_t index = 0; index < this->
GetSize(); ++index)
300 NS_ASSERT_MSG(m_numPages == 1,
"The MatrixArray should have only one page to be copied.");
301 auto copiedMatrix =
MatrixArray<T>{m_numRows, m_numCols, nCopies};
302 for (
size_t copy = 0; copy < nCopies; copy++)
304 for (
size_t i = 0; i < m_numRows * m_numCols; i++)
306 copiedMatrix.GetPagePtr(copy)[i] = m_values[i];
316 NS_ASSERT_MSG(page < m_numPages,
"The page to extract from the MatrixArray is out of bounds.");
319 for (
size_t i = 0; i < m_numRows * m_numCols; ++i)
321 extractedPage.
m_values[i] = GetPagePtr(page)[i];
323 return extractedPage;
332 for (
size_t page = 0; page < jointMatrix.GetNumPages(); page++)
334 NS_ASSERT_MSG(pages[page].GetNumRows() == jointMatrix.GetNumRows(),
335 "All page matrices should have the same number of rows");
336 NS_ASSERT_MSG(pages[page].GetNumCols() == jointMatrix.GetNumCols(),
337 "All page matrices should have the same number of columns");
339 "All page matrices should have a single page");
342 for (
auto a : pages[page].GetValues())
344 jointMatrix.GetPagePtr(page)[i] = a;
356 for (std::size_t page = 0; page < pages; page++)
358 for (std::size_t i = 0; i < size; i++)
360 identityMatrix(i, i, page) = 1.0;
363 return identityMatrix;
MatrixArray class inherits ValArray class and provides additional interfaces to ValArray which enable...
MatrixArray< T > HermitianTranspose() const
Function that performs the Hermitian transpose of this MatrixArray and returns a new matrix that is t...
MatrixArray operator*(const T &rhs) const
Element-wise multiplication with a scalar value.
MatrixArray Determinant() const
This operator calculates a vector o determinants, one for each page.
static MatrixArray< T > IdentityMatrix(const size_t size, const size_t pages=1)
Function produces an identity MatrixArray with the specified size.
static MatrixArray< T > JoinPages(const std::vector< MatrixArray< T > > &pages)
Function joins multiple pages into a single MatrixArray.
MatrixArray Transpose() const
This operator interprets the 3D array as an array of matrices, and performs a linear algebra operatio...
MatrixArray< T > MakeNCopies(size_t nCopies) const
Function that copies the current 1-page matrix into a new matrix with n copies of the original matrix...
MatrixArray< T > ExtractPage(size_t page) const
Function extracts a page from a MatrixArray.
MatrixArray MultiplyByLeftAndRightMatrix(const MatrixArray< T > &lMatrix, const MatrixArray< T > &rMatrix) const
Multiply each matrix in the array by the left and the right matrix.
MatrixArray FrobeniusNorm() const
This operator calculates a vector of Frobenius norm, one for each page.
ValArray is a class to efficiently store 3D array.
T * GetPagePtr(size_t pageIndex)
Get a data pointer to a specific 2D array for use in linear algebra libraries.
size_t GetNumPages() const
size_t m_numCols
The size of the second dimension, i.e., the number of columns of each 2D array.
std::valarray< T > m_values
The data values.
size_t GetNumRows() const
size_t m_numRows
The size of the first dimension, i.e., the number of rows of each 2D array.
size_t GetNumCols() const
size_t m_numPages
The size of the third dimension, i.e., the number of 2D arrays.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetSize(Ptr< const Packet > packet, const WifiMacHeader *hdr, bool isAmpdu)
Return the total size of the packet after WifiMacHeader and FCS trailer have been added.