A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
matrix-array.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Biljana Bojovic <bbojovic@cttc.es>
18 */
19
20#ifndef MATRIX_ARRAY_H
21#define MATRIX_ARRAY_H
22
23#include "val-array.h"
24
25#include <valarray>
26
27namespace ns3
28{
29
81template <class T>
82class MatrixArray : public ValArray<T>
83{
84 public:
85 // instruct the compiler to generate the default constructor
86 MatrixArray<T>() = default;
95 MatrixArray<T>(size_t numRows, size_t numCols = 1, size_t numPages = 1);
101 explicit MatrixArray<T>(const std::valarray<T>& values);
107 MatrixArray<T>(std::valarray<T>&& values);
113 explicit MatrixArray<T>(const std::vector<T>& values);
121 MatrixArray<T>(size_t numRows, size_t numCols, const std::valarray<T>& values);
129 MatrixArray<T>(size_t numRows, size_t numCols, std::valarray<T>&& values);
138 MatrixArray<T>(size_t numRows, size_t numCols, size_t numPages, const std::valarray<T>& values);
147 MatrixArray<T>(size_t numRows, size_t numCols, size_t numPages, std::valarray<T>&& values);
149 ~MatrixArray<T>() override = default;
151 MatrixArray<T>(const MatrixArray<T>&) = default;
159 MatrixArray<T>(MatrixArray<T>&&) = default;
172 MatrixArray<T> operator*(const T& rhs) const;
178 MatrixArray<T> operator+(const MatrixArray<T>& rhs) const;
184 MatrixArray<T> operator-(const MatrixArray<T>& rhs) const;
201 MatrixArray<T> operator*(const MatrixArray<T>& rhs) const;
232 const MatrixArray<T>& rMatrix) const;
233
234 using ValArray<T>::GetPagePtr;
235 using ValArray<T>::EqualDims;
237
245 template <bool EnableBool = true,
246 typename = typename std::enable_if<(std::is_same<T, std::complex<double>>::value &&
247 EnableBool)>::type>
249
250 protected:
251 // To simplify functions in MatrixArray that are using members from the template base class
252 using ValArray<T>::m_numRows;
253 using ValArray<T>::m_numCols;
254 using ValArray<T>::m_numPages;
255 using ValArray<T>::m_values;
256};
257
260
263
266
267/*************************************************
268 ** Class MatrixArray inline implementations
269 ************************************************/
270template <class T>
271inline MatrixArray<T>
272MatrixArray<T>::operator*(const T& rhs) const
273{
274 return MatrixArray<T>(m_numRows,
275 m_numCols,
276 m_numPages,
277 m_values * std::valarray<T>(rhs, m_numRows * m_numCols * m_numPages));
278}
279
280template <class T>
281inline MatrixArray<T>
283{
284 AssertEqualDims(rhs);
285 return MatrixArray<T>(m_numRows, m_numCols, m_numPages, m_values + rhs.m_values);
286}
287
288template <class T>
289inline MatrixArray<T>
291{
292 AssertEqualDims(rhs);
293 return MatrixArray<T>(m_numRows, m_numCols, m_numPages, m_values - rhs.m_values);
294}
295
296template <class T>
297inline MatrixArray<T>
299{
300 return MatrixArray<T>(m_numRows, m_numCols, m_numPages, -m_values);
301}
302
303} // namespace ns3
304
305#endif // MATRIX_ARRAY_H
MatrixArray class inherits ValArray class and provides additional interfaces to ValArray which enable...
Definition: matrix-array.h:83
MatrixArray< T > & operator=(const MatrixArray< T > &)=default
Copy assignment operator.
MatrixArray< T > & operator=(MatrixArray< T > &&)=default
Move assignment operator.
MatrixArray< T > HermitianTranspose() const
Function that performs the Hermitian transpose of this MatrixArray and returns a new matrix that is t...
MatrixArray< T > operator*(const T &rhs) const
Element-wise multiplication with a scalar value.
Definition: matrix-array.h:272
MatrixArray< T > operator-() const
unary operator- definition for MatrixArray<T>.
Definition: matrix-array.h:298
MatrixArray< T > Transpose() const
This operator interprets the 3D array as an array of matrices, and performs a linear algebra operatio...
MatrixArray< T > MultiplyByLeftAndRightMatrix(const MatrixArray< T > &lMatrix, const MatrixArray< T > &rMatrix) const
Multiply each matrix in the array by the left and the right matrix.
MatrixArray< T > operator+(const MatrixArray< T > &rhs) const
operator+ definition for MatrixArray<T>.
Definition: matrix-array.h:282
ValArray is a class to efficiently store 3D array.
Definition: val-array.h:80
T * GetPagePtr(size_t pageIndex)
Get a data pointer to a specific 2D array for use in linear algebra libraries.
Definition: val-array.h:522
void AssertEqualDims(const ValArray< T > &rhs) const
Function that asserts if the dimensions of lhs and rhs ValArray are not equal and prints a message wi...
Definition: val-array.h:697
size_t m_numCols
The size of the second dimension, i.e., the number of columns of each 2D array.
Definition: val-array.h:367
std::valarray< T > m_values
The data values.
Definition: val-array.h:370
size_t m_numRows
The size of the first dimension, i.e., the number of rows of each 2D array.
Definition: val-array.h:365
bool EqualDims(const ValArray< T > &rhs) const
Checks whether rhs and lhs ValArray objects have the same dimensions.
Definition: val-array.h:538
size_t m_numPages
The size of the third dimension, i.e., the number of 2D arrays.
Definition: val-array.h:369
Every class exported by the ns3 library is enclosed in the ns3 namespace.