ValArray is a class to efficiently store 3D array. More...
#include "val-array.h"
Public Member Functions | |
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. | |
Protected Attributes | |
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. | |
ValArray is a class to efficiently store 3D array.
The class is general enough to represent 1D array or 2D arrays. ValArray also provides basic algebra element-wise operations over the whole array (1D, 2D, 3D).
Main characteristics of ValArray are the following:
Examples of column-major order:
a) in the case of a 2D array, we will have in memory the following order of elements, assuming that the indexes are rowIndex, colIndex, pageIndex:
a000 a100 a010 a110 a020 a120.
b) in the case of a 3D array, e.g, if there are two 2D arrays of 2x3 dimensions we will have in memory the following order of elements, assuming that the indexes are rowIndex, colIndex, pageIndex:
a000 a100 a010 a110 a020 a120 a001 a101 a011 a111 a021 a121.
Definition of ValArray as a template class allows using different numerical types as the elements of the vectors/matrices, e.g., complex numbers, double, int, etc.
Definition at line 73 of file val-array.h.
|
default |
ns3::ValArray< T >::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.
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 578 of file val-array.h.
References ns3::ValArray< T >::m_numCols, ns3::ValArray< T >::m_numPages, ns3::ValArray< T >::m_numRows, and ns3::ValArray< T >::m_values.
|
explicit |
Constructor creates a single 1D 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 587 of file val-array.h.
ns3::ValArray< T >::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.
values | std::valarray<T> that will be moved to initialize elements of 1D array |
Definition at line 596 of file val-array.h.
|
explicit |
Constructor creates a single 1D array of values.size () elements and 1 column, and uses values std::vector<T> to initialize the elements.
values | std::vector<T> that will be used to initialize elements of 1D array |
Definition at line 605 of file val-array.h.
References ns3::ValArray< T >::m_values.
ns3::ValArray< T >::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.
numRows | the number of rows |
numCols | the number of columns |
values | valarray<T> that will be used to initialize elements of 3D array |
Definition at line 615 of file val-array.h.
References ns3::ValArray< T >::m_numCols, ns3::ValArray< T >::m_numRows, and NS_ASSERT_MSG.
ns3::ValArray< T >::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.
numRows | the number of rows |
numCols | the number of columns |
values | valarray<T> that will be used to initialize elements of 3D array |
Definition at line 626 of file val-array.h.
References ns3::ValArray< T >::m_numCols, ns3::ValArray< T >::m_numRows, ns3::ValArray< T >::m_values, and NS_ASSERT_MSG.
ns3::ValArray< T >::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.
numRows | the number of rows |
numCols | the number of columns |
numPages | the number of pages |
values | valarray<T> that will be used to initialize elements of 3D array |
Definition at line 637 of file val-array.h.
References ns3::ValArray< T >::m_numCols, ns3::ValArray< T >::m_numPages, ns3::ValArray< T >::m_numRows, and NS_ASSERT_MSG.
ns3::ValArray< T >::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.
numRows | the number of rows |
numCols | the number of columns |
numPages | the number of pages |
values | valarray<T> that will be used to initialize elements of 3D array |
Definition at line 651 of file val-array.h.
References ns3::ValArray< T >::m_numCols, ns3::ValArray< T >::m_numPages, ns3::ValArray< T >::m_numRows, ns3::ValArray< T >::m_values, and NS_ASSERT_MSG.
|
virtualdefault |
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
void ns3::ValArray< T >::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.
rhs | the rhs ValArray |
Definition at line 691 of file val-array.h.
References ns3::ValArray< T >::m_numCols, ns3::ValArray< T >::m_numPages, ns3::ValArray< T >::m_numRows, and NS_ASSERT_MSG.
|
inline |
Alternative access operator to access a specific element.
row | the row index of the element to be obtained |
col | the col index of the element to be obtained |
page | the page index of the element to be obtained |
Definition at line 561 of file val-array.h.
|
inline |
Alternative const access operator to access a specific element.
row | the row index of the element to be obtained |
col | the column index of the element to be obtained |
page | the page index of the element to be obtained |
Definition at line 568 of file val-array.h.
|
inline |
Checks whether rhs and lhs ValArray objects have the same dimensions.
rhs | The rhs ValArray |
Definition at line 532 of file val-array.h.
References ns3::ValArray< T >::m_numCols, ns3::ValArray< T >::m_numPages, and ns3::ValArray< T >::m_numRows.
|
inline |
Definition at line 380 of file val-array.h.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun(), ns3::tests::ValArrayTestCase< T >::DoRun(), ns3::ThreeGppChannelModel::GetNewChannel(), ns3::MatrixArray< T >::IdentityMatrix(), and ns3::operator<<().
|
inline |
Definition at line 387 of file val-array.h.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun(), ns3::tests::ValArrayTestCase< T >::DoRun(), ns3::ThreeGppChannelModel::GetNewChannel(), ns3::MatrixArray< T >::IdentityMatrix(), and ns3::operator<<().
|
inline |
Definition at line 373 of file val-array.h.
Referenced by ns3::ThreeGppSpectrumPropagationLossModel::CalcBeamformingGain(), ns3::tests::MatrixArrayTestCase< T >::DoRun(), ns3::tests::ValArrayTestCase< T >::DoRun(), ns3::ThreeGppChannelModel::GetNewChannel(), ns3::MatrixArray< T >::IdentityMatrix(), ns3::MatrixArray< T >::JoinPages(), and ns3::operator<<().
|
inline |
Get a data pointer to a specific 2D array for use in linear algebra libraries.
pageIndex | The index of the desired 2D array |
Definition at line 516 of file val-array.h.
References NS_ASSERT_MSG.
Referenced by ns3::MatrixArray< T >::MultiplyByLeftAndRightMatrix().
|
inline |
Get a data pointer to a specific 2D array for use in linear algebra libraries.
pageIndex | An index of the desired 2D array |
Definition at line 524 of file val-array.h.
References NS_ASSERT_MSG.
|
inline |
Definition at line 394 of file val-array.h.
Referenced by ns3::ThreeGppSpectrumPropagationLossModel::CalcBeamformingGain(), ns3::ThreeGppSpectrumPropagationLossModel::CalcLongTerm(), UniformPlanarArrayTestCase::ComputeGain(), ns3::tests::MatrixArrayTestCase< T >::DoRun(), ns3::tests::ValArrayTestCase< T >::DoRun(), ns3::PhasedArrayModel::norm(), and ns3::PhasedArrayModel::SetBeamformingVector().
|
inline |
Returns underlying values.
This function allows to directly work with the underlying values, which can be faster then using access operators.
Definition at line 554 of file val-array.h.
Referenced by ns3::tests::MatrixArrayTestCase< T >::DoRun().
bool ns3::ValArray< T >::IsAlmostEqual | ( | const ValArray< T > & | rhs, |
T | tol ) const |
Compare Valarray up to a given absolute tolerance.
This operation is element-wise operation, i.e., the elements with the same indices from the lhs and rhs ValArray are being compared, allowing the tolerance defined byt "tol" parameter.
rhs | The rhs ValArray |
tol | The absolute tolerance |
Definition at line 678 of file val-array.h.
References ns3::ValArray< T >::m_values.
Referenced by ns3::tests::ValArrayTestCase< T >::DoRun(), and ThreeGppMimoPolarizationTest::DoRun().
bool ns3::ValArray< T >::operator!= | ( | const ValArray< T > & | rhs | ) | const |
|
inline |
Single-element access operator() for 1D ValArrays.
Assuming that the number of columns and pages is equal to 1, e.g. ValArray contains a single column or a single row.
Note: intentionally not implemented through three parameters access operator, to avoid accidental mistakes by user, e.g., providing 1 parameters when 2 or 3 are necessary.
index | The index of the 1D ValArray. |
Definition at line 439 of file val-array.h.
References NS_ASSERT_MSG.
|
inline |
Single-element access operator() for 1D ValArrays.
index | The index of the 1D ValArray. |
Definition at line 452 of file val-array.h.
References NS_ASSERT_MSG.
|
inline |
Access operator for 2D ValArrays.
Assuming that the third dimension is equal to 1, e.g. ValArray contains a single 2D array. Note: intentionally not implemented through three parameters access operator, to avoid accidental mistakes by user, e.g., providing 2 parameters when 3 are necessary, but access operator would return valid value if default value of pages provided is 0.
rowIndex | The index of the row |
colIndex | The index of the column |
Definition at line 423 of file val-array.h.
References NS_ASSERT_MSG.
|
inline |
Const access operator for 2D ValArrays.
Assuming that the third dimension is equal to 1, e.g. ValArray contains a single 2D array.
rowIndex | row index |
colIndex | column index |
Definition at line 431 of file val-array.h.
References NS_ASSERT_MSG.
|
inline |
Access operator, with bound-checking in debug profile.
rowIndex | The index of the row |
colIndex | The index of the column |
pageIndex | The index of the page |
Definition at line 401 of file val-array.h.
References NS_ASSERT_MSG.
|
inline |
Const access operator, with bound-checking in debug profile.
rowIndex | The index of the row |
colIndex | The index of the column |
pageIndex | The index of the page |
Definition at line 412 of file val-array.h.
References NS_ASSERT_MSG.
|
inline |
Element-wise multiplication with a scalar value.
rhs | A scalar value of type T |
Definition at line 465 of file val-array.h.
|
inline |
operator+ definition for ValArray<T>.
Definition at line 475 of file val-array.h.
References ns3::ValArray< T >::m_values.
|
inline |
operator+= definition for ValArray<T>.
Definition at line 498 of file val-array.h.
References ns3::ValArray< T >::m_values.
|
inline |
unary operator- definition for ValArray<T>.
Definition at line 491 of file val-array.h.
|
inline |
binary operator- definition for ValArray<T>.
Definition at line 483 of file val-array.h.
References ns3::ValArray< T >::m_values.
|
inline |
operator-= definition for ValArray<T>.
Definition at line 507 of file val-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.
bool ns3::ValArray< T >::operator== | ( | const ValArray< T > & | rhs | ) | const |
operator== definition for ValArray<T>.
Definition at line 663 of file val-array.h.
References ns3::ValArray< T >::m_values.
|
inline |
Single-element access operator[] that can be used to access a specific element of 1D ValArray.
It mimics operator[] from std::vector. This function is introduced for compatibility with ns-3 usage of 1D arrays, which are usually represented through std::vector operators in spectrum and antenna module.
index | The index of the element to be returned |
Definition at line 540 of file val-array.h.
|
inline |
Const access operator that can be used to access a specific element of 1D ValArray.
index | The index of the element to be returned |
Definition at line 547 of file val-array.h.
|
protected |
The size of the second dimension, i.e., the number of columns of each 2D array.
Definition at line 361 of file val-array.h.
Referenced by ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::AssertEqualDims(), ns3::ValArray< T >::EqualDims(), and ns3::MatrixArray< T >::MultiplyByLeftAndRightMatrix().
|
protected |
The size of the third dimension, i.e., the number of 2D arrays.
Definition at line 363 of file val-array.h.
Referenced by ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::AssertEqualDims(), ns3::ValArray< T >::EqualDims(), ns3::MatrixArray< T >::MultiplyByLeftAndRightMatrix(), and ns3::MatrixArray< T >::operator*().
|
protected |
The size of the first dimension, i.e., the number of rows of each 2D array.
Definition at line 359 of file val-array.h.
Referenced by ns3::MatrixArray< std::complex< double > >::MatrixArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::AssertEqualDims(), ns3::ValArray< T >::EqualDims(), and ns3::MatrixArray< T >::MultiplyByLeftAndRightMatrix().
|
protected |
The data values.
Definition at line 364 of file val-array.h.
Referenced by ns3::MatrixArray< std::complex< double > >::MatrixArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::ValArray< T >::ValArray(), ns3::MatrixArray< T >::ExtractPage(), ns3::MatrixArray< T >::HermitianTranspose(), ns3::ValArray< T >::IsAlmostEqual(), ns3::MatrixArray< T >::operator+(), ns3::ValArray< T >::operator+(), ns3::ValArray< T >::operator+=(), ns3::MatrixArray< T >::operator-(), ns3::ValArray< T >::operator-(), ns3::ValArray< T >::operator-=(), and ns3::ValArray< T >::operator==().