92 ValArray(
size_t numRows,
size_t numCols = 1,
size_t numPages = 1);
98 explicit ValArray(
const std::valarray<T>& values);
104 ValArray(std::valarray<T>&& values);
110 explicit ValArray(
const std::vector<T>& values);
118 ValArray(
size_t numRows,
size_t numCols,
const std::valarray<T>& values);
126 ValArray(
size_t numRows,
size_t numCols, std::valarray<T>&& values);
136 ValArray(
size_t numRows,
size_t numCols,
size_t numPages,
const std::valarray<T>& values);
146 ValArray(
size_t numRows,
size_t numCols,
size_t numPages, std::valarray<T>&& values);
188 T&
operator()(
size_t rowIndex,
size_t colIndex,
size_t pageIndex);
196 const T&
operator()(
size_t rowIndex,
size_t colIndex,
size_t pageIndex)
const;
209 T&
operator()(
size_t rowIndex,
size_t colIndex);
218 const T&
operator()(
size_t rowIndex,
size_t colIndex)
const;
346 const std::valarray<T>&
GetValues()
const;
354 T&
Elem(
size_t row,
size_t col,
size_t page);
362 const T&
Elem(
size_t row,
size_t col,
size_t page)
const;
402 return m_values.size();
409 NS_ASSERT_MSG(rowIndex < m_numRows,
"Row index out of bounds");
410 NS_ASSERT_MSG(colIndex < m_numCols,
"Column index out of bounds");
411 NS_ASSERT_MSG(pageIndex < m_numPages,
"Pages index out of bounds");
412 size_t index = (rowIndex + m_numRows * (colIndex + m_numCols * pageIndex));
413 return m_values[index];
420 NS_ASSERT_MSG(rowIndex < m_numRows,
"Row index out of bounds");
421 NS_ASSERT_MSG(colIndex < m_numCols,
"Column index out of bounds");
422 NS_ASSERT_MSG(pageIndex < m_numPages,
"Pages index out of bounds");
423 size_t index = (rowIndex + m_numRows * (colIndex + m_numCols * pageIndex));
424 return m_values[index];
431 NS_ASSERT_MSG(m_numPages == 1,
"Cannot use 2D access operator for 3D ValArray.");
432 return (*
this)(rowIndex, colIndex, 0);
439 NS_ASSERT_MSG(m_numPages == 1,
"Cannot use 2D access operator for 3D ValArray.");
440 return (*
this)(rowIndex, colIndex, 0);
448 "Invalid index to 1D ValArray. The size of the array should be set through "
450 NS_ASSERT_MSG(((m_numRows == 1 || m_numCols == 1) && (m_numPages == 1)) ||
451 (m_numRows == 1 && m_numCols == 1),
452 "Access operator allowed only for 1D ValArray.");
453 return m_values[index];
461 "Invalid index to 1D ValArray.The size of the array should be set through "
463 NS_ASSERT_MSG(((m_numRows == 1 || m_numCols == 1) && (m_numPages == 1)) ||
464 (m_numRows == 1 && m_numCols == 1),
465 "Access operator allowed only for 1D ValArray.");
466 return m_values[index];
476 m_values * std::valarray<T>(rhs, m_numRows * m_numCols * m_numPages));
483 AssertEqualDims(rhs);
491 AssertEqualDims(rhs);
499 return ValArray<T>(m_numRows, m_numCols, m_numPages, -m_values);
506 AssertEqualDims(rhs);
515 AssertEqualDims(rhs);
524 NS_ASSERT_MSG(pageIndex < m_numPages,
"Invalid page index.");
525 return &(m_values[m_numRows * m_numCols * pageIndex]);
532 NS_ASSERT_MSG(pageIndex < m_numPages,
"Invalid page index.");
533 return &(m_values[m_numRows * m_numCols * pageIndex]);
548 return (*
this)(index);
555 return (*
this)(index);
559 inline const std::valarray<T>&
569 return (*
this)(row, col,
page);
576 return (*
this)(row, col,
page);
585 : m_numRows{numRows},
594 : m_numRows{values.size()},
603 : m_numRows{values.size()},
606 m_values{std::move(values)}
612 : m_numRows{values.size()},
617 std::copy(values.begin(), values.end(), std::begin(
m_values));
622 : m_numRows{numRows},
628 "Dimensions and the initialization array size do not match.");
633 : m_numRows{numRows},
638 "Dimensions and the initialization array size do not match.");
646 const std::valarray<T>& values)
647 : m_numRows{numRows},
649 m_numPages{numPages},
653 "Dimensions and the initialization array size do not match.");
658 : m_numRows{numRows},
663 "Dimensions and the initialization array size do not match.");
671 return EqualDims(rhs) &&
672 std::equal(std::begin(m_values), std::end(m_values), std::begin(rhs.
m_values));
679 return !((*this) == rhs);
686 return EqualDims(rhs) && std::equal(std::begin(m_values),
689 [tol](T lhsValue, T rhsValue) {
690 return lhsValue == rhsValue ||
691 std::abs(lhsValue - rhsValue) <= std::abs(tol);
700 "Dimensions mismatch: "
701 "lhs (rows, cols, pages) = ("
702 << m_numRows <<
", " << m_numCols <<
", " << m_numPages
704 "rhs (rows, cols, pages) = ("
722 os <<
"Page " << p <<
":\n";
727 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.
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< T > & operator=(ValArray< T > &&)=default
Move assignment operator.
T & operator()(size_t rowIndex, size_t colIndex, size_t pageIndex)
Access operator, with bound-checking in debug profile.
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(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.
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.
ValArray & operator=(const ValArray< T > &)=default
Copy assignment operator.
bool operator==(const ValArray< T > &rhs) const
operator== definition for ValArray<T>.
size_t GetNumPages() const
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
size_t m_numRows
The size of the first dimension, i.e., the number of rows of each 2D array.
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
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
std::string page
start a separate page
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.