MatrixArray class inherits ValArray class and provides additional interfaces to ValArray which enable page-wise linear algebra operations for arrays of matrices. More...
#include "matrix-array.h"
Public Member Functions | |
MatrixArray ()=default | |
MatrixArray (const std::valarray< T > &values) | |
Constructor creates a single array of values.size () elements and 1 column, and uses std::valarray<T> values to initialize the elements. More... | |
MatrixArray (const std::vector< T > &values) | |
Constructor creates a single array of values.size () elements and 1 column, and uses std::vector<T> values to initialize the elements. More... | |
MatrixArray (size_t numRows, size_t numCols, const std::valarray< T > &values) | |
Constructor creates a single matrix of numRows and numCols, and uses std::valarray<T> values to initialize the elements. More... | |
MatrixArray (size_t numRows, size_t numCols, size_t numPages, const std::valarray< T > &values) | |
Constructor creates the array of numPages matrices of numRows x numCols dimensions, and uses std::valarray<T> values to initialize all the elements. More... | |
MatrixArray (size_t numRows, size_t numCols, size_t numPages, std::valarray< T > &&values) | |
Constructor creates the array of numPages matrices of numRows x numCols dimensions, and moves std::valarray<T> values to initialize all the elements. More... | |
MatrixArray (size_t numRows, size_t numCols, std::valarray< T > &&values) | |
Constructor creates a single matrix of numRows and numCols, and moves std::valarray<T> values to initialize the elements. More... | |
MatrixArray (size_t numRows, size_t numCols=1, size_t numPages=1) | |
Constructor "pages" number of matrices that are of size "numRows"x"numCols", and are initialized with all-zero elements. More... | |
MatrixArray (std::valarray< T > &&values) | |
Constructor creates a single array of values.size () elements and 1 column, and moves std::valarray<T> values to initialize the elements. More... | |
template<bool EnableBool = true, typename = std::enable_if_t<(std::is_same_v<T, std::complex<double>> && EnableBool)>> | |
MatrixArray< T > | HermitianTranspose () const |
Function that performs the Hermitian transpose of this MatrixArray and returns a new matrix that is the result of the operation. More... | |
MatrixArray | MultiplyByLeftAndRightMatrix (const MatrixArray< T > &lMatrix, const MatrixArray< T > &rMatrix) const |
Multiply each matrix in the array by the left and the right matrix. More... | |
MatrixArray | operator* (const MatrixArray< T > &rhs) const |
Page-wise matrix multiplication. More... | |
MatrixArray | operator* (const T &rhs) const |
Element-wise multiplication with a scalar value. More... | |
MatrixArray | operator+ (const MatrixArray< T > &rhs) const |
operator+ definition for MatrixArray<T>. More... | |
MatrixArray | operator- () const |
unary operator- definition for MatrixArray<T>. More... | |
MatrixArray | operator- (const MatrixArray< T > &rhs) const |
binary operator- definition for MatrixArray<T>. More... | |
MatrixArray | Transpose () const |
This operator interprets the 3D array as an array of matrices, and performs a linear algebra operation on each of the matrices (pages), i.e., transposes the matrix or array of matrices definition for MatrixArray<T>. More... | |
Public Member Functions inherited from ns3::ValArray< T > | |
ValArray ()=default | |
ValArray (const std::valarray< T > &values) | |
Constructor creates a single 1D array of values.size () elements and 1 column, and uses std::valarray<T> values to initialize the elements. More... | |
ValArray (const std::vector< T > &values) | |
Constructor creates a single 1D array of values.size () elements and 1 column, and uses values std::vector<T> to initialize the elements. More... | |
ValArray (const ValArray< T > &)=default | |
instruct the compiler to generate the implicitly declared copy constructor More... | |
ValArray (size_t numRows, size_t numCols, const std::valarray< T > &values) | |
Constructor creates a single 2D array of numRows and numCols, and uses std::valarray<T> values to initialize the elements. More... | |
ValArray (size_t numRows, size_t numCols, size_t numPages, const std::valarray< T > &values) | |
Constructor creates the 3D array of numRows x numCols x numPages dimensions, and uses std::valarray<T> values to initialize all the 2D arrays, where first numRows*numCols elements will belong to the first 2D array. More... | |
ValArray (size_t numRows, size_t numCols, size_t numPages, std::valarray< T > &&values) | |
Constructor creates the 3D array of numRows x numCols x numPages dimensions, and moves std::valarray<T> values to initialize all the 2D arrays, where first numRows*numCols elements will belong to the first 2D array. More... | |
ValArray (size_t numRows, size_t numCols, std::valarray< T > &&values) | |
Constructor creates a single 2D array of numRows and numCols, and moves std::valarray<T> values to initialize the elements. More... | |
ValArray (size_t numRows, size_t numCols=1, size_t numPages=1) | |
Constructor that creates "numPages" number of 2D arrays that are of dimensions "numRows"x"numCols", and are initialized with all-zero elements. More... | |
ValArray (std::valarray< T > &&values) | |
Constructor creates a single 1D array of values.size () elements and 1 column, and moves std::valarray<T> values to initialize the elements. More... | |
ValArray (ValArray< T > &&)=default | |
instruct the compiler to generate the implicitly declared move constructor More... | |
virtual | ~ValArray ()=default |
instruct the compiler to generate the implicitly declared destructor More... | |
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 with the matrices dimensions. More... | |
T & | Elem (size_t row, size_t col, size_t page) |
Alternative access operator to access a specific element. More... | |
const T & | Elem (size_t row, size_t col, size_t page) const |
Alternative const access operator to access a specific element. More... | |
bool | EqualDims (const ValArray< T > &rhs) const |
Checks whether rhs and lhs ValArray objects have the same dimensions. More... | |
size_t | GetNumCols () const |
size_t | GetNumPages () const |
size_t | GetNumRows () const |
T * | GetPagePtr (size_t pageIndex) |
Get a data pointer to a specific 2D array for use in linear algebra libraries. More... | |
const T * | GetPagePtr (size_t pageIndex) const |
Get a data pointer to a specific 2D array for use in linear algebra libraries. More... | |
size_t | GetSize () const |
const std::valarray< T > & | GetValues () const |
Returns underlying values. More... | |
bool | IsAlmostEqual (const ValArray< T > &rhs, T tol) const |
Compare Valarray up to a given absolute tolerance. More... | |
bool | operator!= (const ValArray< T > &rhs) const |
operator!= definition for ValArray<T>. More... | |
T & | operator() (size_t index) |
Single-element access operator() for 1D ValArrays. More... | |
const T & | operator() (size_t index) const |
Single-element access operator() for 1D ValArrays. More... | |
T & | operator() (size_t rowIndex, size_t colIndex) |
Access operator for 2D ValArrays. More... | |
const T & | operator() (size_t rowIndex, size_t colIndex) const |
Const access operator for 2D ValArrays. More... | |
T & | operator() (size_t rowIndex, size_t colIndex, size_t pageIndex) |
Access operator, with bound-checking in debug profile. More... | |
const T & | operator() (size_t rowIndex, size_t colIndex, size_t pageIndex) const |
Const access operator, with bound-checking in debug profile. More... | |
ValArray | operator* (const T &rhs) const |
Element-wise multiplication with a scalar value. More... | |
ValArray | operator+ (const ValArray< T > &rhs) const |
operator+ definition for ValArray<T>. More... | |
ValArray< T > & | operator+= (const ValArray< T > &rhs) |
operator+= definition for ValArray<T>. More... | |
ValArray | operator- () const |
unary operator- definition for ValArray<T>. More... | |
ValArray | operator- (const ValArray< T > &rhs) const |
binary operator- definition for ValArray<T>. More... | |
ValArray< T > & | operator-= (const ValArray< T > &rhs) |
operator-= definition for ValArray<T>. More... | |
ValArray & | operator= (const ValArray< T > &)=default |
Copy assignment operator. More... | |
ValArray< T > & | operator= (ValArray< T > &&)=default |
Move assignment operator. More... | |
bool | operator== (const ValArray< T > &rhs) const |
operator== definition for ValArray<T>. More... | |
T & | operator[] (size_t index) |
Single-element access operator[] that can be used to access a specific element of 1D ValArray. More... | |
const T & | operator[] (size_t index) const |
Const access operator that can be used to access a specific element of 1D ValArray. More... | |
Public Member Functions inherited from ns3::SimpleRefCount< ValArray< T > > | |
SimpleRefCount () | |
Default constructor. More... | |
SimpleRefCount (const SimpleRefCount &o[[maybe_unused]]) | |
Copy constructor. More... | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. More... | |
SimpleRefCount & | operator= (const SimpleRefCount &o[[maybe_unused]]) |
Assignment operator. More... | |
void | Ref () const |
Increment the reference count. More... | |
void | Unref () const |
Decrement the reference count. More... | |
Additional Inherited Members | |
Protected Attributes inherited from ns3::ValArray< T > | |
size_t | m_numCols |
The size of the second dimension, i.e., the number of columns of each 2D array. More... | |
size_t | m_numPages = 0 |
The size of the third dimension, i.e., the number of 2D arrays. More... | |
size_t | m_numRows |
The size of the first dimension, i.e., the number of rows of each 2D array. More... | |
std::valarray< T > | m_values |
The data values. More... | |
MatrixArray class inherits ValArray class and provides additional interfaces to ValArray which enable page-wise linear algebra operations for arrays of matrices.
While ValArray class is focused on efficient storage, access and basic algebra element-wise operations on 3D numerical arrays, MatrixArray is focused on the efficient algebra operations on arrays of matrices.
Each page (2-dimensional array) within a 3D array is considered to be a matrix, and operations are performed separately for each page/matrix. For example, a multiplication of two MatrixArrays means that a matrix multiplication is performed between each page in the first MatrixArray with the corresponding page in the second MatrixArray. Some of the operations can use the Eigen3 matrix library for speedup. In addition, this class can be extended to provide interfaces to the Eigen3 matrix library and enable additional linear algebra operations. The objective of this class is to two-fold:
Important characteristics:
Definition at line 82 of file matrix-array.h.
|
default |
ns3::MatrixArray< T >::MatrixArray | ( | size_t | numRows, |
size_t | numCols = 1 , |
||
size_t | numPages = 1 |
||
) |
Constructor "pages" number of matrices that are of size "numRows"x"numCols", and are initialized with all-zero elements.
If only 1 parameter, numRows, is provided then a single 1D array is being created.
numRows | the number of rows |
numCols | the number of columns |
numPages | the number of pages |
Definition at line 37 of file matrix-array.cc.
|
explicit |
Constructor creates a single array of values.size () elements and 1 column, and uses std::valarray<T> values to initialize the elements.
values | std::valarray<T> that will be used to initialize elements of 1D array |
Definition at line 43 of file matrix-array.cc.
ns3::MatrixArray< T >::MatrixArray | ( | std::valarray< T > && | values | ) |
Constructor creates a single array of values.size () elements and 1 column, and moves std::valarray<T> values to initialize the elements.
values | std::valarray<T> that will be moved to initialize elements of 1D array |
Definition at line 49 of file matrix-array.cc.
|
explicit |
Constructor creates a single array of values.size () elements and 1 column, and uses std::vector<T> values to initialize the elements.
values | std::vector<T> that will be used to initialize elements of 1D array |
Definition at line 55 of file matrix-array.cc.
ns3::MatrixArray< T >::MatrixArray | ( | size_t | numRows, |
size_t | numCols, | ||
const std::valarray< T > & | values | ||
) |
Constructor creates a single matrix of numRows and numCols, and uses std::valarray<T> values to initialize the elements.
numRows | the number of rows |
numCols | the number of columns |
values | std::valarray<T> that will be used to initialize elements of 3D array |
Definition at line 61 of file matrix-array.cc.
ns3::MatrixArray< T >::MatrixArray | ( | size_t | numRows, |
size_t | numCols, | ||
std::valarray< T > && | values | ||
) |
Constructor creates a single matrix of numRows and numCols, and moves std::valarray<T> values to initialize the elements.
numRows | the number of rows |
numCols | the number of columns |
values | std::valarray<T> that will be moved to initialize elements of 3D array |
Definition at line 67 of file matrix-array.cc.
ns3::MatrixArray< T >::MatrixArray | ( | size_t | numRows, |
size_t | numCols, | ||
size_t | numPages, | ||
const std::valarray< T > & | values | ||
) |
Constructor creates the array of numPages matrices of numRows x numCols dimensions, and uses std::valarray<T> values to initialize all the elements.
numRows | the number of rows |
numCols | the number of columns |
numPages | the number of pages |
values | std::valarray<T> that will be used to initialize elements of 3D array |
Definition at line 73 of file matrix-array.cc.
ns3::MatrixArray< T >::MatrixArray | ( | size_t | numRows, |
size_t | numCols, | ||
size_t | numPages, | ||
std::valarray< T > && | values | ||
) |
Constructor creates the array of numPages matrices of numRows x numCols dimensions, and moves std::valarray<T> values to initialize all the elements.
numRows | the number of rows |
numCols | the number of columns |
numPages | the number of pages |
values | std::valarray<T> that will be used to initialize elements of 3D array |
Definition at line 82 of file matrix-array.cc.
template MatrixArray< std::complex< double > > ns3::MatrixArray< T >::HermitianTranspose | ( | ) | const |
Function that performs the Hermitian transpose of this MatrixArray and returns a new matrix that is the result of the operation.
This function assumes that the matrix contains complex numbers, because of that it is only available for the <std::complex<double>> specialization of MatrixArray.
Definition at line 221 of file matrix-array.cc.
References ns3::GetSize(), and ns3::ValArray< T >::m_values.
Referenced by ns3::ThreeGppSpectrumPropagationLossModel::CalcBeamformingGain().
MatrixArray< T > ns3::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.
For each page of this MatrixArray the operation performed is lMatrix * matrix(pageIndex) * rMatrix, and the resulting MatrixArray<T> contains the array of the results per page. If "this" has dimensions M x N x P, lMatrix must have dimensions M number of columns, and a single page, and rMatrix must have N number of rows, and also a single page.
The result of this function will have the dimensions J x K x P. Where J is the number of rows of the lMatrix, and K is the number of columns of rMatrix. Dimensions are:
lMatrix(JxMx1) * this (MxNxP) * rMatrix(NxKx1) -> result(JxKxP)
This operation is not possible when using the multiplication operator because the number of pages does not match.
lMatrix | the left matrix in the multiplication |
rMatrix | the right matrix in the multiplication |
Definition at line 161 of file matrix-array.cc.
References ns3::ValArray< T >::GetPagePtr(), ns3::ValArray< T >::m_numCols, ns3::ValArray< T >::m_numPages, ns3::ValArray< T >::m_numRows, ns3::ValArray< T >::m_values, NS_ASSERT_MSG, anonymous_namespace{print-introspected-doxygen.cc}::page, and two-ray-to-three-gpp-ch-calibration::res.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun().
MatrixArray< T > ns3::MatrixArray< T >::operator* | ( | const MatrixArray< T > & | rhs | ) | const |
Page-wise matrix multiplication.
This operator interprets the 3D array as an array of matrices, and performs a linear algebra operation on each of the matrices (pages), i.e., matrices from this MatrixArray and rhs with the same page indices are multiplied. The number of columns of this MatrixArray must be equal to the number of rows in rhs, and rhs must have the same number of pages as this MatrixArray.
rhs | is another MatrixArray instance |
Definition at line 92 of file matrix-array.cc.
References ns3::ValArray< T >::GetPagePtr(), ns3::ValArray< T >::m_numCols, ns3::ValArray< T >::m_numPages, ns3::ValArray< T >::m_numRows, ns3::ValArray< T >::m_values, NS_ASSERT_MSG, anonymous_namespace{print-introspected-doxygen.cc}::page, and two-ray-to-three-gpp-ch-calibration::res.
|
inline |
Element-wise multiplication with a scalar value.
rhs | is a scalar value of type T |
Definition at line 254 of file matrix-array.h.
|
inline |
operator+ definition for MatrixArray<T>.
rhs | The rhs MatrixArray object |
Definition at line 264 of file matrix-array.h.
References ns3::ValArray< T >::m_values.
|
inline |
unary operator- definition for MatrixArray<T>.
Definition at line 280 of file matrix-array.h.
|
inline |
binary operator- definition for MatrixArray<T>.
rhs | The rhs MatrixArray object |
Definition at line 272 of file matrix-array.h.
References ns3::ValArray< T >::m_values.
MatrixArray< T > ns3::MatrixArray< T >::Transpose |
This operator interprets the 3D array as an array of matrices, and performs a linear algebra operation on each of the matrices (pages), i.e., transposes the matrix or array of matrices definition for MatrixArray<T>.
Definition at line 131 of file matrix-array.cc.
References anonymous_namespace{print-introspected-doxygen.cc}::page, and two-ray-to-three-gpp-ch-calibration::res.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun().