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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
MatrixArray | Determinant () const |
This operator calculates a vector o determinants, one for each page. | |
MatrixArray< T > | ExtractPage (size_t page) const |
Function extracts a page from a MatrixArray. | |
MatrixArray | FrobeniusNorm () const |
This operator calculates a vector of Frobenius norm, one for each page. | |
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. | |
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 | 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 |
Page-wise matrix multiplication. | |
MatrixArray | operator* (const T &rhs) const |
Element-wise multiplication with a scalar value. | |
MatrixArray | operator+ (const MatrixArray< T > &rhs) const |
operator+ definition for MatrixArray<T>. | |
MatrixArray | operator- () const |
unary operator- definition for MatrixArray<T>. | |
MatrixArray | operator- (const MatrixArray< T > &rhs) const |
binary operator- definition for MatrixArray<T>. | |
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>. | |
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. | |
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. | |
ValArray (const ValArray< T > &)=default | |
instruct the compiler to generate the implicitly declared copy constructor | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
ValArray (ValArray< T > &&)=default | |
instruct the compiler to generate the implicitly declared move constructor | |
virtual | ~ValArray ()=default |
instruct the compiler to generate the implicitly declared destructor | |
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. | |
T & | Elem (size_t row, size_t col, size_t page) |
Alternative access operator to access a specific element. | |
const T & | Elem (size_t row, size_t col, size_t page) const |
Alternative const access operator to access a specific element. | |
bool | EqualDims (const ValArray< T > &rhs) const |
Checks whether rhs and lhs ValArray objects have the same dimensions. | |
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. | |
const T * | GetPagePtr (size_t pageIndex) const |
Get a data pointer to a specific 2D array for use in linear algebra libraries. | |
size_t | GetSize () const |
const std::valarray< T > & | GetValues () const |
Returns underlying values. | |
bool | IsAlmostEqual (const ValArray< T > &rhs, T tol) const |
Compare Valarray up to a given absolute tolerance. | |
bool | operator!= (const ValArray< T > &rhs) const |
operator!= definition for ValArray<T>. | |
T & | operator() (size_t index) |
Single-element access operator() for 1D ValArrays. | |
const T & | operator() (size_t index) const |
Single-element access operator() for 1D ValArrays. | |
T & | operator() (size_t rowIndex, size_t colIndex) |
Access operator for 2D ValArrays. | |
const T & | operator() (size_t rowIndex, size_t colIndex) const |
Const access operator for 2D ValArrays. | |
T & | operator() (size_t rowIndex, size_t colIndex, size_t pageIndex) |
Access operator, with bound-checking in debug profile. | |
const T & | operator() (size_t rowIndex, size_t colIndex, size_t pageIndex) const |
Const access operator, with bound-checking in debug profile. | |
ValArray | operator* (const T &rhs) const |
Element-wise multiplication with a scalar value. | |
ValArray | operator+ (const ValArray< T > &rhs) const |
operator+ definition for ValArray<T>. | |
ValArray< T > & | operator+= (const ValArray< T > &rhs) |
operator+= definition for ValArray<T>. | |
ValArray | operator- () const |
unary operator- definition for ValArray<T>. | |
ValArray | operator- (const ValArray< T > &rhs) const |
binary operator- definition for ValArray<T>. | |
ValArray< T > & | operator-= (const ValArray< T > &rhs) |
operator-= definition for ValArray<T>. | |
ValArray & | operator= (const ValArray< T > &)=default |
Copy assignment operator. | |
ValArray< T > & | operator= (ValArray< T > &&)=default |
Move assignment operator. | |
bool | operator== (const ValArray< T > &rhs) const |
operator== definition for ValArray<T>. | |
T & | operator[] (size_t index) |
Single-element access operator[] that can be used to access a specific element of 1D ValArray. | |
const T & | operator[] (size_t index) const |
Const access operator that can be used to access a specific element of 1D ValArray. | |
Public Member Functions inherited from ns3::SimpleRefCount< ValArray< T > > | |
SimpleRefCount () | |
Default constructor. | |
SimpleRefCount (const SimpleRefCount &o) | |
Copy constructor. | |
uint32_t | GetReferenceCount () const |
Get the reference count of the object. | |
SimpleRefCount & | operator= (const SimpleRefCount &o) |
Assignment operator. | |
void | Ref () const |
Increment the reference count. | |
void | Unref () const |
Decrement the reference count. | |
Static Public Member Functions | |
static MatrixArray< T > | IdentityMatrix (const MatrixArray &likeme) |
Function produces an identity MatrixArray with the same size as the input MatrixArray. | |
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. | |
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. | |
size_t | m_numPages = 0 |
The size of the third dimension, i.e., the number of 2D arrays. | |
size_t | m_numRows |
The size of the first dimension, i.e., the number of rows of each 2D array. | |
std::valarray< T > | m_values |
The data values. | |
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 71 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 26 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 32 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 38 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 44 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 50 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 56 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 62 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 71 of file matrix-array.cc.
MatrixArray< T > ns3::MatrixArray< T >::Determinant | ( | ) | const |
This operator calculates a vector o determinants, one for each page.
Definition at line 150 of file matrix-array.cc.
References NS_ASSERT_MSG.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun().
MatrixArray< T > ns3::MatrixArray< T >::ExtractPage | ( | size_t | page | ) | const |
Function extracts a page from a MatrixArray.
page | Index of the page to be extracted from the n-page MatrixArray |
Definition at line 303 of file matrix-array.cc.
References ns3::ValArray< T >::m_values, and NS_ASSERT_MSG.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun().
MatrixArray< T > ns3::MatrixArray< T >::FrobeniusNorm | ( | ) | const |
This operator calculates a vector of Frobenius norm, one for each page.
Definition at line 194 of file matrix-array.cc.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun().
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 274 of file matrix-array.cc.
References ns3::GetSize(), and ns3::ValArray< T >::m_values.
Referenced by ns3::ThreeGppSpectrumPropagationLossModel::CalcBeamformingGain().
|
static |
Function produces an identity MatrixArray with the same size as the input MatrixArray.
likeme | Input matrix used to determine the size of the identity matrix |
Definition at line 357 of file matrix-array.cc.
References ns3::ValArray< T >::GetNumCols(), ns3::ValArray< T >::GetNumPages(), ns3::ValArray< T >::GetNumRows(), and NS_ASSERT_MSG.
|
static |
Function produces an identity MatrixArray with the specified size.
size | Size of the output identity matrix |
pages | Number of copies of the identity matrix |
Definition at line 342 of file matrix-array.cc.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun().
|
static |
Function joins multiple pages into a single MatrixArray.
pages | Vector containing n 1-page MatrixArrays to be merged into a n-page MatrixArray |
Definition at line 317 of file matrix-array.cc.
References ns3::ValArray< T >::GetNumRows(), and NS_ASSERT_MSG.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun().
MatrixArray< T > ns3::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.
nCopies | Number of copies to make of the input 1-page MatrixArray |
Definition at line 287 of file matrix-array.cc.
References NS_ASSERT_MSG.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun().
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 214 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, and NS_ASSERT_MSG.
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 81 of file matrix-array.cc.
References ns3::ValArray< T >::m_numPages, and NS_ASSERT_MSG.
|
inline |
Element-wise multiplication with a scalar value.
rhs | is a scalar value of type T |
Definition at line 287 of file matrix-array.h.
|
inline |
operator+ definition for MatrixArray<T>.
rhs | The rhs MatrixArray object |
Definition at line 297 of file matrix-array.h.
References ns3::ValArray< T >::m_values.
|
inline |
unary operator- definition for MatrixArray<T>.
Definition at line 313 of file matrix-array.h.
|
inline |
binary operator- definition for MatrixArray<T>.
rhs | The rhs MatrixArray object |
Definition at line 305 of file matrix-array.h.
References ns3::ValArray< T >::m_values.
MatrixArray< T > ns3::MatrixArray< T >::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>.
Definition at line 120 of file matrix-array.cc.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun().