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<T>() = default;
95  MatrixArray<T>(uint16_t numRows, uint16_t numCols = 1, uint16_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>(uint16_t numRows, uint16_t numCols, const std::valarray<T>& values);
129  MatrixArray<T>(uint16_t numRows, uint16_t numCols, std::valarray<T>&& values);
138  MatrixArray<T>(uint16_t numRows,
139  uint16_t numCols,
140  uint16_t numPages,
141  const std::valarray<T>& values);
150  MatrixArray<T>(uint16_t numRows,
151  uint16_t numCols,
152  uint16_t numPages,
153  std::valarray<T>&& values);
155  ~MatrixArray<T>() override = default;
157  MatrixArray<T>(const MatrixArray<T>&) = default;
165  MatrixArray<T>(MatrixArray<T>&&) = default;
178  MatrixArray<T> operator*(const T& rhs) const;
184  MatrixArray<T> operator+(const MatrixArray<T>& rhs) const;
190  MatrixArray<T> operator-(const MatrixArray<T>& rhs) const;
195  MatrixArray<T> operator-() const;
207  MatrixArray<T> operator*(const MatrixArray<T>& rhs) const;
214  MatrixArray<T> Transpose() const;
238  const MatrixArray<T>& rMatrix) const;
239 
243 
251  template <bool EnableBool = true,
252  typename = typename std::enable_if<(std::is_same<T, std::complex<double>>::value &&
253  EnableBool)>::type>
255 
256  private:
257  // To simplify functions in MatrixArray that are using members from the template base class
261  using ValArray<T>::m_values;
262 };
263 
266 
269 
272 
273 /*************************************************
274  ** Class MatrixArray inline implementations
275  ************************************************/
276 template <class T>
277 inline MatrixArray<T>
278 MatrixArray<T>::operator*(const T& rhs) const
279 {
280  return MatrixArray<T>(m_numRows,
281  m_numCols,
282  m_numPages,
283  m_values * std::valarray<T>(rhs, m_numRows * m_numCols * m_numPages));
284 }
285 
286 template <class T>
287 inline MatrixArray<T>
289 {
290  AssertEqualDims(rhs);
291  return MatrixArray<T>(m_numRows, m_numCols, m_numPages, m_values + rhs.m_values);
292 }
293 
294 template <class T>
295 inline MatrixArray<T>
297 {
298  AssertEqualDims(rhs);
299  return MatrixArray<T>(m_numRows, m_numCols, m_numPages, m_values - rhs.m_values);
300 }
301 
302 template <class T>
303 inline MatrixArray<T>
305 {
306  return MatrixArray<T>(m_numRows, m_numCols, m_numPages, -m_values);
307 }
308 
309 } // namespace ns3
310 
311 #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< T > operator*(const T &rhs) const
Element-wise multiplication with a scalar value.
Definition: matrix-array.h:278
MatrixArray< T > operator-() const
unary operator- definition for MatrixArray<T>.
Definition: matrix-array.h:304
MatrixArray< T > & operator=(MatrixArray< T > &&)=default
Move assignment operator.
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 > &)=default
Copy assignment operator.
MatrixArray< T > operator+(const MatrixArray< T > &rhs) const
operator+ definition for MatrixArray<T>.
Definition: matrix-array.h:288
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:373
Every class exported by the ns3 library is enclosed in the ns3 namespace.
value
Definition: second.py:41