86 ValArray(
size_t numRows,
size_t numCols = 1,
size_t numPages = 1);
92 explicit ValArray(
const std::valarray<T>& values);
112 ValArray(
size_t numRows,
size_t numCols,
const std::valarray<T>& values);
120 ValArray(
size_t numRows,
size_t numCols, std::valarray<T>&& values);
130 ValArray(
size_t numRows,
size_t numCols,
size_t numPages,
const std::valarray<T>& values);
140 ValArray(
size_t numRows,
size_t numCols,
size_t numPages, std::valarray<T>&& values);
182 T&
operator()(
size_t rowIndex,
size_t colIndex,
size_t pageIndex);
190 const T&
operator()(
size_t rowIndex,
size_t colIndex,
size_t pageIndex)
const;
348 T&
Elem(
size_t row,
size_t col,
size_t page);
356 const T&
Elem(
size_t row,
size_t col,
size_t page)
const;
396 return m_values.size();
403 NS_ASSERT_MSG(rowIndex < m_numRows,
"Row index out of bounds");
404 NS_ASSERT_MSG(colIndex < m_numCols,
"Column index out of bounds");
405 NS_ASSERT_MSG(pageIndex < m_numPages,
"Pages index out of bounds");
406 size_t index = (rowIndex + m_numRows * (colIndex + m_numCols * pageIndex));
407 return m_values[index];
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(m_numPages == 1,
"Cannot use 2D access operator for 3D ValArray.");
426 return (*
this)(rowIndex, colIndex, 0);
433 NS_ASSERT_MSG(m_numPages == 1,
"Cannot use 2D access operator for 3D ValArray.");
434 return (*
this)(rowIndex, colIndex, 0);
442 "Invalid index to 1D ValArray. The size of the array should be set through "
444 NS_ASSERT_MSG(((m_numRows == 1 || m_numCols == 1) && (m_numPages == 1)) ||
445 (m_numRows == 1 && m_numCols == 1),
446 "Access operator allowed only for 1D ValArray.");
447 return m_values[index];
455 "Invalid index to 1D ValArray.The size of the array should be set through "
457 NS_ASSERT_MSG(((m_numRows == 1 || m_numCols == 1) && (m_numPages == 1)) ||
458 (m_numRows == 1 && m_numCols == 1),
459 "Access operator allowed only for 1D ValArray.");
460 return m_values[index];
470 m_values * std::valarray<T>(rhs, m_numRows * m_numCols * m_numPages));
477 AssertEqualDims(rhs);
485 AssertEqualDims(rhs);
493 return ValArray<T>(m_numRows, m_numCols, m_numPages, -m_values);
500 AssertEqualDims(rhs);
509 AssertEqualDims(rhs);
518 NS_ASSERT_MSG(pageIndex < m_numPages,
"Invalid page index.");
519 return &(m_values[m_numRows * m_numCols * pageIndex]);
526 NS_ASSERT_MSG(pageIndex < m_numPages,
"Invalid page index.");
527 return &(m_values[m_numRows * m_numCols * pageIndex]);
542 return (*
this)(index);
549 return (*
this)(index);
553inline const std::valarray<T>&
563 return (*
this)(row, col, page);
570 return (*
this)(row, col, page);
579 : m_numRows{numRows},
588 : m_numRows{values.size()},
597 : m_numRows{values.size()},
600 m_values{
std::move(values)}
606 : m_numRows{values.size()},
611 std::copy(values.begin(), values.end(), std::begin(
m_values));
616 : m_numRows{numRows},
622 "Dimensions and the initialization array size do not match.");
627 : m_numRows{numRows},
632 "Dimensions and the initialization array size do not match.");
640 const std::valarray<T>& values)
641 : m_numRows{numRows},
643 m_numPages{numPages},
647 "Dimensions and the initialization array size do not match.");
652 : m_numRows{numRows},
657 "Dimensions and the initialization array size do not match.");
665 return EqualDims(rhs) &&
666 std::equal(std::begin(m_values), std::end(m_values), std::begin(rhs.
m_values));
673 return !((*this) == rhs);
680 return EqualDims(rhs) && std::equal(std::begin(m_values),
683 [tol](T lhsValue, T rhsValue) {
684 return lhsValue == rhsValue ||
685 std::abs(lhsValue - rhsValue) <= std::abs(tol);
694 "Dimensions mismatch: "
695 "lhs (rows, cols, pages) = ("
696 << m_numRows <<
", " << m_numCols <<
", " << m_numPages
698 "rhs (rows, cols, pages) = ("
716 os <<
"Page " << p <<
":\n";
721 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.