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 MatrixArray< T > &)=default | |
instruct the compiler to generate the implicitly declared copy constructor | |
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 (MatrixArray< T > &&)=default | |
instruct the compiler to generate the implicitly declared move constructor | |
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 () override=default | |
instruct the compiler to generate the implicitly declared destructor | |
template<bool EnableBool = true, typename = typename std::enable_if<(std::is_same<T, std::complex<double>>::value && EnableBool)>::type> | |
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 > | 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 |
Page-wise matrix multiplication. | |
MatrixArray< T > | operator* (const T &rhs) const |
Element-wise multiplication with a scalar value. | |
MatrixArray< T > | operator+ (const MatrixArray< T > &rhs) const |
operator+ definition for MatrixArray<T>. | |
MatrixArray< T > | operator- () const |
unary operator- definition for MatrixArray<T>. | |
MatrixArray< T > | operator- (const MatrixArray< T > &rhs) const |
binary operator- definition for MatrixArray<T>. | |
MatrixArray< T > & | operator= (const MatrixArray< T > &)=default |
Copy assignment operator. | |
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 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< T > | operator* (const T &rhs) const |
Element-wise multiplication with a scalar value. | |
ValArray< T > | operator+ (const ValArray< T > &rhs) const |
operator+ definition for ValArray<T>. | |
ValArray< T > & | operator+= (const ValArray< T > &rhs) |
operator+= definition for ValArray<T>. | |
ValArray< T > | operator- () const |
unary operator- definition for ValArray<T>. | |
ValArray< T > | 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< T > & | 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. | |
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 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.
|
overridedefault |
instruct the compiler to generate the implicitly declared destructor
|
default |
instruct the compiler to generate the implicitly declared copy constructor
|
default |
instruct the compiler to generate the implicitly declared move constructor
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.
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, 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 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, and NS_ASSERT_MSG.
|
inline |
Element-wise multiplication with a scalar value.
rhs | is a scalar value of type T |
Definition at line 272 of file matrix-array.h.
|
inline |
operator+ definition for MatrixArray<T>.
rhs | The rhs MatrixArray object |
Definition at line 282 of file matrix-array.h.
References ns3::ValArray< T >::m_values.
|
inline |
unary operator- definition for MatrixArray<T>.
Definition at line 298 of file matrix-array.h.
|
inline |
binary operator- definition for MatrixArray<T>.
rhs | The rhs MatrixArray object |
Definition at line 290 of file matrix-array.h.
References ns3::ValArray< T >::m_values.
|
default |
Copy assignment operator.
Instruct the compiler to generate the implicitly declared copy assignment operator.
|
default |
Move assignment operator.
Instruct the compiler to generate the implicitly declared move assignment operator.
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.
Referenced by ns3::ThreeGppSpectrumPropagationLossModel::CalcLongTerm(), and ns3::tests::MatrixArrayTestCase< T >::DoRun().