97 ValArray(
size_t numRows,
size_t numCols = 1,
size_t numPages = 1);
123 ValArray(
size_t numRows,
size_t numCols,
const std::valarray<T>& values);
131 ValArray(
size_t numRows,
size_t numCols, std::valarray<T>&& values);
141 ValArray(
size_t numRows,
size_t numCols,
size_t numPages,
const std::valarray<T>& values);
151 ValArray(
size_t numRows,
size_t numCols,
size_t numPages, std::valarray<T>&& values);
193 T&
operator()(
size_t rowIndex,
size_t colIndex,
size_t pageIndex);
201 const T&
operator()(
size_t rowIndex,
size_t colIndex,
size_t pageIndex)
const;
359 T&
Elem(
size_t row,
size_t col,
size_t page);
367 const T&
Elem(
size_t row,
size_t col,
size_t page)
const;
407 return m_values.size();
414 NS_ASSERT_MSG(rowIndex < m_numRows,
"Row index out of bounds");
415 NS_ASSERT_MSG(colIndex < m_numCols,
"Column index out of bounds");
416 NS_ASSERT_MSG(pageIndex < m_numPages,
"Pages index out of bounds");
417 size_t index = (rowIndex + m_numRows * (colIndex + m_numCols * pageIndex));
418 return m_values[index];
425 NS_ASSERT_MSG(rowIndex < m_numRows,
"Row index out of bounds");
426 NS_ASSERT_MSG(colIndex < m_numCols,
"Column index out of bounds");
427 NS_ASSERT_MSG(pageIndex < m_numPages,
"Pages index out of bounds");
428 size_t index = (rowIndex + m_numRows * (colIndex + m_numCols * pageIndex));
429 return m_values[index];
436 NS_ASSERT_MSG(m_numPages == 1,
"Cannot use 2D access operator for 3D ValArray.");
437 return (*
this)(rowIndex, colIndex, 0);
444 NS_ASSERT_MSG(m_numPages == 1,
"Cannot use 2D access operator for 3D ValArray.");
445 return (*
this)(rowIndex, colIndex, 0);
453 "Invalid index to 1D ValArray. The size of the array should be set through "
455 NS_ASSERT_MSG(((m_numRows == 1 || m_numCols == 1) && (m_numPages == 1)) ||
456 (m_numRows == 1 && m_numCols == 1),
457 "Access operator allowed only for 1D ValArray.");
458 return m_values[index];
466 "Invalid index to 1D ValArray.The size of the array should be set through "
468 NS_ASSERT_MSG(((m_numRows == 1 || m_numCols == 1) && (m_numPages == 1)) ||
469 (m_numRows == 1 && m_numCols == 1),
470 "Access operator allowed only for 1D ValArray.");
471 return m_values[index];
481 m_values * std::valarray<T>(rhs, m_numRows * m_numCols * m_numPages));
488 AssertEqualDims(rhs);
496 AssertEqualDims(rhs);
504 return ValArray<T>(m_numRows, m_numCols, m_numPages, -m_values);
511 AssertEqualDims(rhs);
520 AssertEqualDims(rhs);
529 NS_ASSERT_MSG(pageIndex < m_numPages,
"Invalid page index.");
530 return &(m_values[m_numRows * m_numCols * pageIndex]);
537 NS_ASSERT_MSG(pageIndex < m_numPages,
"Invalid page index.");
538 return &(m_values[m_numRows * m_numCols * pageIndex]);
553 return (*
this)(index);
560 return (*
this)(index);
564inline const std::valarray<T>&
574 return (*
this)(row, col, page);
581 return (*
this)(row, col, page);
590 : m_numRows{numRows},
599 : m_numRows{values.size()},
608 : m_numRows{values.size()},
611 m_values{
std::move(values)}
617 : m_numRows{values.size()},
622 std::copy(values.begin(), values.end(), std::begin(
m_values));
627 : m_numRows{numRows},
633 "Dimensions and the initialization array size do not match.");
638 : m_numRows{numRows},
643 "Dimensions and the initialization array size do not match.");
651 const std::valarray<T>& values)
652 : m_numRows{numRows},
654 m_numPages{numPages},
658 "Dimensions and the initialization array size do not match.");
663 : m_numRows{numRows},
668 "Dimensions and the initialization array size do not match.");
676 return EqualDims(rhs) &&
677 std::equal(std::begin(m_values), std::end(m_values), std::begin(rhs.
m_values));
684 return !((*this) == rhs);
691 return EqualDims(rhs) && std::equal(std::begin(m_values),
694 [tol](T lhsValue, T rhsValue) {
695 return lhsValue == rhsValue ||
696 std::abs(lhsValue - rhsValue) <= std::abs(tol);
705 "Dimensions mismatch: "
706 "lhs (rows, cols, pages) = ("
707 << m_numRows <<
", " << m_numCols <<
", " << m_numPages
709 "rhs (rows, cols, pages) = ("
727 os <<
"Page " << p <<
":\n";
732 os <<
"\t" << a(i, j, p);
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
A template-based reference counting class.
ValArray is a class to efficiently store 3D array.
T * GetPagePtr(size_t pageIndex)
Get a data pointer to a specific 2D array for use in linear algebra libraries.
T & operator()(size_t rowIndex, size_t colIndex)
Access operator for 2D ValArrays.
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 wi...
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 & operator()(size_t rowIndex, size_t colIndex, size_t pageIndex)
Access operator, with bound-checking in debug profile.
const T & operator()(size_t index) const
Single-element access operator() for 1D ValArrays.
T & Elem(size_t row, size_t col, size_t page)
Alternative access operator to access a specific element.
ValArray operator+(const ValArray< T > &rhs) const
operator+ definition for ValArray<T>.
ValArray(std::valarray< T > &&values)
Constructor creates a single 1D array of values.size () elements and 1 column, and moves std::valarra...
ValArray(const std::valarray< T > &values)
Constructor creates a single 1D array of values.size () elements and 1 column, and uses std::valarray...
ValArray(const ValArray< T > &)=default
instruct the compiler to generate the implicitly declared copy constructor
ValArray(ValArray< T > &&)=default
instruct the compiler to generate the implicitly declared move constructor
const std::valarray< T > & GetValues() const
Returns underlying values.
ValArray< T > & operator+=(const ValArray< T > &rhs)
operator+= definition for ValArray<T>.
bool IsAlmostEqual(const ValArray< T > &rhs, T tol) const
Compare Valarray up to a given absolute tolerance.
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 in...
const T & Elem(size_t row, size_t col, size_t page) const
Alternative const access operator to access a specific element.
bool operator!=(const ValArray< T > &rhs) const
operator!= definition for ValArray<T>.
ValArray< T > & operator=(ValArray< T > &&)=default
Move assignment operator.
T & operator[](size_t index)
Single-element access operator[] that can be used to access a specific element of 1D ValArray.
bool operator==(const ValArray< T > &rhs) const
operator== definition for ValArray<T>.
size_t GetNumPages() const
ValArray & operator=(const ValArray< T > &)=default
Copy assignment operator.
const T & operator()(size_t rowIndex, size_t colIndex, size_t pageIndex) const
Const access operator, with bound-checking in debug profile.
ValArray(const std::vector< T > &values)
Constructor creates a single 1D array of values.size () elements and 1 column, and uses values std::v...
T & operator()(size_t index)
Single-element access operator() for 1D ValArrays.
const T & operator[](size_t index) const
Const access operator that can be used to access a specific element of 1D ValArray.
size_t m_numCols
The size of the second dimension, i.e., the number of columns of each 2D array.
std::valarray< T > m_values
The data values.
ValArray< T > & operator-=(const ValArray< T > &rhs)
operator-= definition for ValArray<T>.
size_t GetNumRows() const
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",...
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 ini...
size_t m_numRows
The size of the first dimension, i.e., the number of rows of each 2D array.
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...
const T & operator()(size_t rowIndex, size_t colIndex) const
Const access operator for 2D ValArrays.
const T * GetPagePtr(size_t pageIndex) const
Get a data pointer to a specific 2D array for use in linear algebra libraries.
bool EqualDims(const ValArray< T > &rhs) const
Checks whether rhs and lhs ValArray objects have the same dimensions.
size_t GetNumCols() const
size_t m_numPages
The size of the third dimension, i.e., the number of 2D arrays.
ValArray operator*(const T &rhs) const
Element-wise multiplication with a scalar value.
ValArray operator-() const
unary operator- definition for ValArray<T>.
virtual ~ValArray()=default
instruct the compiler to generate the implicitly declared destructor
ValArray operator-(const ValArray< T > &rhs) const
binary operator- definition for ValArray<T>.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
ns3::SimpleRefCount declaration and template implementation.