A Discrete-Event Network Simulator
API
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 
27 namespace ns3
28 {
29 
81 template <class T>
82 class MatrixArray : public ValArray<T>
83 {
84  public:
85  // instruct the compiler to generate the default constructor
86  MatrixArray() = default;
95  MatrixArray(size_t numRows, size_t numCols = 1, size_t numPages = 1);
101  explicit MatrixArray(const std::valarray<T>& values);
107  MatrixArray(std::valarray<T>&& values);
113  explicit MatrixArray(const std::vector<T>& values);
121  MatrixArray(size_t numRows, size_t numCols, const std::valarray<T>& values);
129  MatrixArray(size_t numRows, size_t numCols, std::valarray<T>&& values);
138  MatrixArray(size_t numRows, size_t numCols, size_t numPages, const std::valarray<T>& values);
147  MatrixArray(size_t numRows, size_t numCols, size_t numPages, std::valarray<T>&& values);
148 
155  MatrixArray operator*(const T& rhs) const;
161  MatrixArray operator+(const MatrixArray<T>& rhs) const;
167  MatrixArray operator-(const MatrixArray<T>& rhs) const;
172  MatrixArray operator-() const;
184  MatrixArray operator*(const MatrixArray<T>& rhs) const;
191  MatrixArray Transpose() const;
215  const MatrixArray<T>& rMatrix) const;
216 
220 
228  template <bool EnableBool = true,
229  typename = std::enable_if_t<(std::is_same_v<T, std::complex<double>> && EnableBool)>>
231 
232  protected:
233  // To simplify functions in MatrixArray that are using members from the template base class
237  using ValArray<T>::m_values;
238 };
239 
242 
245 
248 
249 /*************************************************
250  ** Class MatrixArray inline implementations
251  ************************************************/
252 template <class T>
253 inline MatrixArray<T>
254 MatrixArray<T>::operator*(const T& rhs) const
255 {
256  return MatrixArray<T>(m_numRows,
257  m_numCols,
258  m_numPages,
259  m_values * std::valarray<T>(rhs, m_numRows * m_numCols * m_numPages));
260 }
261 
262 template <class T>
263 inline MatrixArray<T>
265 {
266  AssertEqualDims(rhs);
267  return MatrixArray<T>(m_numRows, m_numCols, m_numPages, m_values + rhs.m_values);
268 }
269 
270 template <class T>
271 inline MatrixArray<T>
273 {
274  AssertEqualDims(rhs);
275  return MatrixArray<T>(m_numRows, m_numCols, m_numPages, m_values - rhs.m_values);
276 }
277 
278 template <class T>
279 inline MatrixArray<T>
281 {
282  return MatrixArray<T>(m_numRows, m_numCols, m_numPages, -m_values);
283 }
284 
285 } // namespace ns3
286 
287 #endif // MATRIX_ARRAY_H
MatrixArray class inherits ValArray class and provides additional interfaces to ValArray which enable...
Definition: matrix-array.h:83
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.
Definition: matrix-array.h:254
MatrixArray operator-() const
unary operator- definition for MatrixArray<T>.
Definition: matrix-array.h:280
MatrixArray Transpose() const
This operator interprets the 3D array as an array of matrices, and performs a linear algebra operatio...
MatrixArray()=default
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 operator+(const MatrixArray< T > &rhs) const
operator+ definition for MatrixArray<T>.
Definition: matrix-array.h:264
ValArray is a class to efficiently store 3D array.
Definition: val-array.h:80
std::valarray< T > m_values
The data values.
Definition: val-array.h:370
typename std::enable_if< B, T >::type enable_if_t
Definition: json.h:2746
Every class exported by the ns3 library is enclosed in the ns3 namespace.