core: Use size_t instead of uint16_t for easier integrations with std container types
This commit is contained in:
committed by
Biljana B
parent
e6b2ff7e7e
commit
b72c6437b7
@@ -34,7 +34,7 @@ using ConstEigenMatrix = Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, Eigen
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
MatrixArray<T>::MatrixArray(uint16_t numRows, uint16_t numCols, uint16_t numPages)
|
||||
MatrixArray<T>::MatrixArray(size_t numRows, size_t numCols, size_t numPages)
|
||||
: ValArray<T>(numRows, numCols, numPages)
|
||||
{
|
||||
}
|
||||
@@ -58,30 +58,30 @@ MatrixArray<T>::MatrixArray(const std::vector<T>& values)
|
||||
}
|
||||
|
||||
template <class T>
|
||||
MatrixArray<T>::MatrixArray(uint16_t numRows, uint16_t numCols, const std::valarray<T>& values)
|
||||
MatrixArray<T>::MatrixArray(size_t numRows, size_t numCols, const std::valarray<T>& values)
|
||||
: ValArray<T>(numRows, numCols, values)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
MatrixArray<T>::MatrixArray(uint16_t numRows, uint16_t numCols, std::valarray<T>&& values)
|
||||
MatrixArray<T>::MatrixArray(size_t numRows, size_t numCols, std::valarray<T>&& values)
|
||||
: ValArray<T>(numRows, numCols, std::move(values))
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
MatrixArray<T>::MatrixArray(uint16_t numRows,
|
||||
uint16_t numCols,
|
||||
uint16_t numPages,
|
||||
MatrixArray<T>::MatrixArray(size_t numRows,
|
||||
size_t numCols,
|
||||
size_t numPages,
|
||||
const std::valarray<T>& values)
|
||||
: ValArray<T>(numRows, numCols, numPages, values)
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
MatrixArray<T>::MatrixArray(uint16_t numRows,
|
||||
uint16_t numCols,
|
||||
uint16_t numPages,
|
||||
MatrixArray<T>::MatrixArray(size_t numRows,
|
||||
size_t numCols,
|
||||
size_t numPages,
|
||||
std::valarray<T>&& values)
|
||||
: ValArray<T>(numRows, numCols, numPages, std::move(values))
|
||||
{
|
||||
@@ -96,7 +96,7 @@ MatrixArray<T>::operator*(const MatrixArray<T>& rhs) const
|
||||
|
||||
MatrixArray<T> res{m_numRows, rhs.m_numCols, m_numPages};
|
||||
|
||||
for (uint16_t page = 0; page < res.m_numPages; ++page)
|
||||
for (size_t page = 0; page < res.m_numPages; ++page)
|
||||
{
|
||||
#ifdef HAVE_EIGEN3 // Eigen found and enabled Eigen optimizations
|
||||
|
||||
@@ -109,9 +109,9 @@ MatrixArray<T>::operator*(const MatrixArray<T>& rhs) const
|
||||
|
||||
size_t matrixOffset = page * m_numRows * m_numCols;
|
||||
size_t rhsMatrixOffset = page * rhs.m_numRows * rhs.m_numCols;
|
||||
for (uint16_t i = 0; i < res.m_numRows; ++i)
|
||||
for (size_t i = 0; i < res.m_numRows; ++i)
|
||||
{
|
||||
for (uint16_t j = 0; j < res.m_numCols; ++j)
|
||||
for (size_t j = 0; j < res.m_numCols; ++j)
|
||||
{
|
||||
res(i, j, page) = (m_values[std::slice(matrixOffset + i, m_numCols, m_numRows)] *
|
||||
rhs.m_values[std::slice(rhsMatrixOffset + j * rhs.m_numRows,
|
||||
@@ -134,7 +134,7 @@ MatrixArray<T>::Transpose() const
|
||||
// m_numPages = this.m_numPages
|
||||
MatrixArray<T> res{m_numCols, m_numRows, m_numPages};
|
||||
|
||||
for (uint16_t page = 0; page < m_numPages; ++page)
|
||||
for (size_t page = 0; page < m_numPages; ++page)
|
||||
{
|
||||
#ifdef HAVE_EIGEN3 // Eigen found and Eigen optimizations enabled
|
||||
|
||||
@@ -145,7 +145,7 @@ MatrixArray<T>::Transpose() const
|
||||
#else // Eigen not found or Eigen optimizations not enabled
|
||||
|
||||
size_t matrixIndex = page * m_numRows * m_numCols;
|
||||
for (uint16_t i = 0; i < m_numRows; ++i)
|
||||
for (size_t i = 0; i < m_numRows; ++i)
|
||||
{
|
||||
res.m_values[std::slice(matrixIndex + i * res.m_numRows, res.m_numRows, 1)] =
|
||||
m_values[std::slice(matrixIndex + i, m_numCols, m_numRows)];
|
||||
@@ -176,7 +176,7 @@ MatrixArray<T>::MultiplyByLeftAndRightMatrix(const MatrixArray<T>& lMatrix,
|
||||
ConstEigenMatrix<T> rMatrixEigen(rMatrix.GetPagePtr(0), rMatrix.m_numRows, rMatrix.m_numCols);
|
||||
#endif
|
||||
|
||||
for (uint16_t page = 0; page < m_numPages; ++page)
|
||||
for (size_t page = 0; page < m_numPages; ++page)
|
||||
{
|
||||
#ifdef HAVE_EIGEN3 // Eigen found and Eigen optimizations enabled
|
||||
|
||||
@@ -188,14 +188,14 @@ MatrixArray<T>::MultiplyByLeftAndRightMatrix(const MatrixArray<T>& lMatrix,
|
||||
#else // Eigen not found or Eigen optimizations not enabled
|
||||
|
||||
size_t matrixOffset = page * m_numRows * m_numCols;
|
||||
for (uint16_t resRow = 0; resRow < res.m_numRows; ++resRow)
|
||||
for (size_t resRow = 0; resRow < res.m_numRows; ++resRow)
|
||||
{
|
||||
for (uint16_t resCol = 0; resCol < res.m_numCols; ++resCol)
|
||||
for (size_t resCol = 0; resCol < res.m_numCols; ++resCol)
|
||||
{
|
||||
// create intermediate row result, a multiply of resRow row of lMatrix and each
|
||||
// column of this matrix
|
||||
std::valarray<T> interRes(m_numCols);
|
||||
for (uint16_t thisCol = 0; thisCol < m_numCols; ++thisCol)
|
||||
for (size_t thisCol = 0; thisCol < m_numCols; ++thisCol)
|
||||
{
|
||||
interRes[thisCol] =
|
||||
(lMatrix
|
||||
|
||||
@@ -92,7 +92,7 @@ class MatrixArray : public ValArray<T>
|
||||
* \param numCols the number of columns
|
||||
* \param numPages the number of pages
|
||||
*/
|
||||
MatrixArray<T>(uint16_t numRows, uint16_t numCols = 1, uint16_t numPages = 1);
|
||||
MatrixArray<T>(size_t numRows, size_t numCols = 1, size_t numPages = 1);
|
||||
/**
|
||||
* \brief Constructor creates a single array of values.size () elements and 1 column,
|
||||
* and uses std::valarray<T> values to initialize the elements.
|
||||
@@ -118,7 +118,7 @@ class MatrixArray : public ValArray<T>
|
||||
* \param numCols the number of columns
|
||||
* \param values std::valarray<T> that will be used to initialize elements of 3D array
|
||||
*/
|
||||
MatrixArray<T>(uint16_t numRows, uint16_t numCols, const std::valarray<T>& values);
|
||||
MatrixArray<T>(size_t numRows, size_t numCols, const std::valarray<T>& values);
|
||||
/**
|
||||
* \brief Constructor creates a single matrix of numRows and numCols, and moves
|
||||
* std::valarray<T> values to initialize the elements.
|
||||
@@ -126,7 +126,7 @@ class MatrixArray : public ValArray<T>
|
||||
* \param numCols the number of columns
|
||||
* \param values std::valarray<T> that will be moved to initialize elements of 3D array
|
||||
*/
|
||||
MatrixArray<T>(uint16_t numRows, uint16_t numCols, std::valarray<T>&& values);
|
||||
MatrixArray<T>(size_t numRows, size_t numCols, std::valarray<T>&& values);
|
||||
/**
|
||||
* \brief Constructor creates the array of numPages matrices of numRows x numCols dimensions,
|
||||
* and uses std::valarray<T> values to initialize all the elements.
|
||||
@@ -135,10 +135,7 @@ class MatrixArray : public ValArray<T>
|
||||
* \param numPages the number of pages
|
||||
* \param values std::valarray<T> that will be used to initialize elements of 3D array
|
||||
*/
|
||||
MatrixArray<T>(uint16_t numRows,
|
||||
uint16_t numCols,
|
||||
uint16_t numPages,
|
||||
const std::valarray<T>& values);
|
||||
MatrixArray<T>(size_t numRows, size_t numCols, size_t numPages, const std::valarray<T>& values);
|
||||
/**
|
||||
* \brief Constructor creates the array of numPages matrices of numRows x numCols dimensions,
|
||||
* and moves std::valarray<T> values to initialize all the elements.
|
||||
@@ -147,10 +144,7 @@ class MatrixArray : public ValArray<T>
|
||||
* \param numPages the number of pages
|
||||
* \param values std::valarray<T> that will be used to initialize elements of 3D array
|
||||
*/
|
||||
MatrixArray<T>(uint16_t numRows,
|
||||
uint16_t numCols,
|
||||
uint16_t numPages,
|
||||
std::valarray<T>&& values);
|
||||
MatrixArray<T>(size_t numRows, size_t numCols, size_t numPages, std::valarray<T>&& values);
|
||||
/** instruct the compiler to generate the implicitly declared destructor*/
|
||||
~MatrixArray<T>() override = default;
|
||||
/** instruct the compiler to generate the implicitly declared copy constructor*/
|
||||
|
||||
@@ -89,7 +89,7 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param numCols the number of columns
|
||||
* \param numPages the number of pages
|
||||
*/
|
||||
ValArray<T>(uint16_t numRows, uint16_t numCols = 1, uint16_t numPages = 1);
|
||||
ValArray<T>(size_t numRows, size_t numCols = 1, size_t numPages = 1);
|
||||
/**
|
||||
* \brief Constructor creates a single 1D array of values.size () elements and 1 column,
|
||||
* and uses std::valarray<T> values to initialize the elements.
|
||||
@@ -115,7 +115,7 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param numCols the number of columns
|
||||
* \param values valarray<T> that will be used to initialize elements of 3D array
|
||||
*/
|
||||
ValArray<T>(uint16_t numRows, uint16_t numCols, const std::valarray<T>& values);
|
||||
ValArray<T>(size_t numRows, size_t numCols, const std::valarray<T>& values);
|
||||
/**
|
||||
* \brief Constructor creates a single 2D array of numRows and numCols, and moves
|
||||
* std::valarray<T> values to initialize the elements.
|
||||
@@ -123,7 +123,7 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param numCols the number of columns
|
||||
* \param values valarray<T> that will be used to initialize elements of 3D array
|
||||
*/
|
||||
ValArray<T>(uint16_t numRows, uint16_t numCols, std::valarray<T>&& values);
|
||||
ValArray<T>(size_t numRows, size_t numCols, std::valarray<T>&& values);
|
||||
/**
|
||||
* \brief 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
|
||||
@@ -133,10 +133,7 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param numPages the number of pages
|
||||
* \param values valarray<T> that will be used to initialize elements of 3D array
|
||||
*/
|
||||
ValArray<T>(uint16_t numRows,
|
||||
uint16_t numCols,
|
||||
uint16_t numPages,
|
||||
const std::valarray<T>& values);
|
||||
ValArray<T>(size_t numRows, size_t numCols, size_t numPages, const std::valarray<T>& values);
|
||||
/**
|
||||
* \brief 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
|
||||
@@ -146,7 +143,7 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param numPages the number of pages
|
||||
* \param values valarray<T> that will be used to initialize elements of 3D array
|
||||
*/
|
||||
ValArray<T>(uint16_t numRows, uint16_t numCols, uint16_t numPages, std::valarray<T>&& values);
|
||||
ValArray<T>(size_t numRows, size_t numCols, size_t numPages, std::valarray<T>&& values);
|
||||
/** instruct the compiler to generate the implicitly declared destructor*/
|
||||
virtual ~ValArray<T>() = default;
|
||||
/** instruct the compiler to generate the implicitly declared copy constructor*/
|
||||
@@ -168,15 +165,15 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
/**
|
||||
* \returns Number of rows
|
||||
*/
|
||||
uint16_t GetNumRows() const;
|
||||
size_t GetNumRows() const;
|
||||
/**
|
||||
* \returns Number of columns
|
||||
*/
|
||||
uint16_t GetNumCols() const;
|
||||
size_t GetNumCols() const;
|
||||
/**
|
||||
* \returns Number of pages, i.e., the number of 2D arrays
|
||||
*/
|
||||
uint16_t GetNumPages() const;
|
||||
size_t GetNumPages() const;
|
||||
/**
|
||||
* \returns Total number of elements
|
||||
*/
|
||||
@@ -188,7 +185,7 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param pageIndex The index of the page
|
||||
* \returns A const reference to the element with with rowIndex, colIndex and pageIndex indices.
|
||||
*/
|
||||
T& operator()(uint16_t rowIndex, uint16_t colIndex, uint16_t pageIndex);
|
||||
T& operator()(size_t rowIndex, size_t colIndex, size_t pageIndex);
|
||||
/**
|
||||
* \brief Const access operator, with bound-checking in debug profile
|
||||
* \param rowIndex The index of the row
|
||||
@@ -196,7 +193,7 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param pageIndex The index of the page
|
||||
* \returns A const reference to the element with with rowIndex, colIndex and pageIndex indices.
|
||||
*/
|
||||
const T& operator()(uint16_t rowIndex, uint16_t colIndex, uint16_t pageIndex) const;
|
||||
const T& operator()(size_t rowIndex, size_t colIndex, size_t pageIndex) const;
|
||||
/**
|
||||
* \brief Access operator for 2D ValArrays.
|
||||
* Assuming that the third dimension is equal to 1, e.g. ValArray contains
|
||||
@@ -209,7 +206,7 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param colIndex The index of the column
|
||||
* \returns A reference to the element with the specified indices
|
||||
*/
|
||||
T& operator()(uint16_t rowIndex, uint16_t colIndex);
|
||||
T& operator()(size_t rowIndex, size_t colIndex);
|
||||
/**
|
||||
* \brief Const access operator for 2D ValArrays.
|
||||
* Assuming that the third dimension is equal to 1, e.g. ValArray contains
|
||||
@@ -218,7 +215,7 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param colIndex column index
|
||||
* \returns a Const reference to the value with the specified row and column index.
|
||||
*/
|
||||
const T& operator()(uint16_t rowIndex, uint16_t colIndex) const;
|
||||
const T& operator()(size_t rowIndex, size_t colIndex) const;
|
||||
/**
|
||||
* \brief Single-element access operator() for 1D ValArrays.
|
||||
* Assuming that the number of columns and pages is equal to 1, e.g. ValArray
|
||||
@@ -230,13 +227,13 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param index The index of the 1D ValArray.
|
||||
* \returns A reference to the value with the specified index.
|
||||
*/
|
||||
T& operator()(uint16_t index);
|
||||
T& operator()(size_t index);
|
||||
/**
|
||||
* \brief Single-element access operator() for 1D ValArrays.
|
||||
* \param index The index of the 1D ValArray.
|
||||
* \returns The const reference to the values with the specified index.
|
||||
*/
|
||||
const T& operator()(uint16_t index) const;
|
||||
const T& operator()(size_t index) const;
|
||||
/**
|
||||
* \brief Element-wise multiplication with a scalar value.
|
||||
* \param rhs A scalar value of type T
|
||||
@@ -302,14 +299,14 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
* \param pageIndex The index of the desired 2D array
|
||||
* \returns a pointer to the data elements of the 2D array
|
||||
*/
|
||||
T* GetPagePtr(uint16_t pageIndex);
|
||||
T* GetPagePtr(size_t pageIndex);
|
||||
/**
|
||||
* \brief Get a data pointer to a specific 2D array for use in linear
|
||||
* algebra libraries
|
||||
* \param pageIndex An index of the desired 2D array
|
||||
* \returns a pointer to the data elements of the 2D array
|
||||
*/
|
||||
const T* GetPagePtr(uint16_t pageIndex) const;
|
||||
const T* GetPagePtr(size_t pageIndex) const;
|
||||
/**
|
||||
* \brief Checks whether rhs and lhs ValArray objects have the same dimensions.
|
||||
* \param rhs The rhs ValArray
|
||||
@@ -365,11 +362,11 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
const T& Elem(size_t row, size_t col, size_t page) const;
|
||||
|
||||
protected:
|
||||
uint16_t m_numRows =
|
||||
size_t m_numRows =
|
||||
0; //!< The size of the first dimension, i.e., the number of rows of each 2D array
|
||||
uint16_t m_numCols =
|
||||
size_t m_numCols =
|
||||
0; //!< The size of the second dimension, i.e., the number of columns of each 2D array
|
||||
uint16_t m_numPages = 0; //!< The size of the third dimension, i.e., the number of 2D arrays
|
||||
size_t m_numPages = 0; //!< The size of the third dimension, i.e., the number of 2D arrays
|
||||
std::valarray<T> m_values; //!< The data values
|
||||
};
|
||||
|
||||
@@ -378,21 +375,21 @@ class ValArray : public SimpleRefCount<ValArray<T>>
|
||||
************************************************/
|
||||
|
||||
template <class T>
|
||||
inline uint16_t
|
||||
inline size_t
|
||||
ValArray<T>::GetNumRows() const
|
||||
{
|
||||
return m_numRows;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline uint16_t
|
||||
inline size_t
|
||||
ValArray<T>::GetNumCols() const
|
||||
{
|
||||
return m_numCols;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline uint16_t
|
||||
inline size_t
|
||||
ValArray<T>::GetNumPages() const
|
||||
{
|
||||
return m_numPages;
|
||||
@@ -407,7 +404,7 @@ ValArray<T>::GetSize() const
|
||||
|
||||
template <class T>
|
||||
inline T&
|
||||
ValArray<T>::operator()(uint16_t rowIndex, uint16_t colIndex, uint16_t pageIndex)
|
||||
ValArray<T>::operator()(size_t rowIndex, size_t colIndex, size_t pageIndex)
|
||||
{
|
||||
NS_ASSERT_MSG(rowIndex < m_numRows, "Row index out of bounds");
|
||||
NS_ASSERT_MSG(colIndex < m_numCols, "Column index out of bounds");
|
||||
@@ -418,7 +415,7 @@ ValArray<T>::operator()(uint16_t rowIndex, uint16_t colIndex, uint16_t pageIndex
|
||||
|
||||
template <class T>
|
||||
inline const T&
|
||||
ValArray<T>::operator()(uint16_t rowIndex, uint16_t colIndex, uint16_t pageIndex) const
|
||||
ValArray<T>::operator()(size_t rowIndex, size_t colIndex, size_t pageIndex) const
|
||||
{
|
||||
NS_ASSERT_MSG(rowIndex < m_numRows, "Row index out of bounds");
|
||||
NS_ASSERT_MSG(colIndex < m_numCols, "Column index out of bounds");
|
||||
@@ -429,7 +426,7 @@ ValArray<T>::operator()(uint16_t rowIndex, uint16_t colIndex, uint16_t pageIndex
|
||||
|
||||
template <class T>
|
||||
inline T&
|
||||
ValArray<T>::operator()(uint16_t rowIndex, uint16_t colIndex)
|
||||
ValArray<T>::operator()(size_t rowIndex, size_t colIndex)
|
||||
{
|
||||
NS_ASSERT_MSG(m_numPages == 1, "Cannot use 2D access operator for 3D ValArray.");
|
||||
return (*this)(rowIndex, colIndex, 0);
|
||||
@@ -437,7 +434,7 @@ ValArray<T>::operator()(uint16_t rowIndex, uint16_t colIndex)
|
||||
|
||||
template <class T>
|
||||
inline const T&
|
||||
ValArray<T>::operator()(uint16_t rowIndex, uint16_t colIndex) const
|
||||
ValArray<T>::operator()(size_t rowIndex, size_t colIndex) const
|
||||
{
|
||||
NS_ASSERT_MSG(m_numPages == 1, "Cannot use 2D access operator for 3D ValArray.");
|
||||
return (*this)(rowIndex, colIndex, 0);
|
||||
@@ -445,7 +442,7 @@ ValArray<T>::operator()(uint16_t rowIndex, uint16_t colIndex) const
|
||||
|
||||
template <class T>
|
||||
inline T&
|
||||
ValArray<T>::operator()(uint16_t index)
|
||||
ValArray<T>::operator()(size_t index)
|
||||
{
|
||||
NS_ASSERT_MSG(index < m_values.size(),
|
||||
"Invalid index to 1D ValArray. The size of the array should be set through "
|
||||
@@ -458,7 +455,7 @@ ValArray<T>::operator()(uint16_t index)
|
||||
|
||||
template <class T>
|
||||
inline const T&
|
||||
ValArray<T>::operator()(uint16_t index) const
|
||||
ValArray<T>::operator()(size_t index) const
|
||||
{
|
||||
NS_ASSERT_MSG(index < m_values.size(),
|
||||
"Invalid index to 1D ValArray.The size of the array should be set through "
|
||||
@@ -522,7 +519,7 @@ ValArray<T>::operator-=(const ValArray<T>& rhs)
|
||||
|
||||
template <class T>
|
||||
inline T*
|
||||
ValArray<T>::GetPagePtr(uint16_t pageIndex)
|
||||
ValArray<T>::GetPagePtr(size_t pageIndex)
|
||||
{
|
||||
NS_ASSERT_MSG(pageIndex < m_numPages, "Invalid page index.");
|
||||
return &(m_values[m_numRows * m_numCols * pageIndex]);
|
||||
@@ -530,7 +527,7 @@ ValArray<T>::GetPagePtr(uint16_t pageIndex)
|
||||
|
||||
template <class T>
|
||||
inline const T*
|
||||
ValArray<T>::GetPagePtr(uint16_t pageIndex) const
|
||||
ValArray<T>::GetPagePtr(size_t pageIndex) const
|
||||
{
|
||||
NS_ASSERT_MSG(pageIndex < m_numPages, "Invalid page index.");
|
||||
return &(m_values[m_numRows * m_numCols * pageIndex]);
|
||||
@@ -584,7 +581,7 @@ ValArray<T>::Elem(size_t row, size_t col, size_t page) const
|
||||
************************************************/
|
||||
|
||||
template <class T>
|
||||
ValArray<T>::ValArray(uint16_t numRows, uint16_t numCols, uint16_t numPages)
|
||||
ValArray<T>::ValArray(size_t numRows, size_t numCols, size_t numPages)
|
||||
: m_numRows{numRows},
|
||||
m_numCols{numCols},
|
||||
m_numPages{numPages}
|
||||
@@ -594,7 +591,7 @@ ValArray<T>::ValArray(uint16_t numRows, uint16_t numCols, uint16_t numPages)
|
||||
|
||||
template <class T>
|
||||
ValArray<T>::ValArray(const std::valarray<T>& values)
|
||||
: m_numRows{(uint16_t)values.size()},
|
||||
: m_numRows{values.size()},
|
||||
m_numCols{1},
|
||||
m_numPages{1},
|
||||
m_values{values}
|
||||
@@ -603,7 +600,7 @@ ValArray<T>::ValArray(const std::valarray<T>& values)
|
||||
|
||||
template <class T>
|
||||
ValArray<T>::ValArray(std::valarray<T>&& values)
|
||||
: m_numRows{(uint16_t)values.size()},
|
||||
: m_numRows{values.size()},
|
||||
m_numCols{1},
|
||||
m_numPages{1},
|
||||
m_values{std::move(values)}
|
||||
@@ -612,7 +609,7 @@ ValArray<T>::ValArray(std::valarray<T>&& values)
|
||||
|
||||
template <class T>
|
||||
ValArray<T>::ValArray(const std::vector<T>& values)
|
||||
: m_numRows{(uint16_t)values.size()},
|
||||
: m_numRows{values.size()},
|
||||
m_numCols{1},
|
||||
m_numPages{1}
|
||||
{
|
||||
@@ -621,7 +618,7 @@ ValArray<T>::ValArray(const std::vector<T>& values)
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ValArray<T>::ValArray(uint16_t numRows, uint16_t numCols, const std::valarray<T>& values)
|
||||
ValArray<T>::ValArray(size_t numRows, size_t numCols, const std::valarray<T>& values)
|
||||
: m_numRows{numRows},
|
||||
m_numCols{numCols},
|
||||
m_numPages{1},
|
||||
@@ -632,7 +629,7 @@ ValArray<T>::ValArray(uint16_t numRows, uint16_t numCols, const std::valarray<T>
|
||||
};
|
||||
|
||||
template <class T>
|
||||
ValArray<T>::ValArray(uint16_t numRows, uint16_t numCols, std::valarray<T>&& values)
|
||||
ValArray<T>::ValArray(size_t numRows, size_t numCols, std::valarray<T>&& values)
|
||||
: m_numRows{numRows},
|
||||
m_numCols{numCols},
|
||||
m_numPages{1}
|
||||
@@ -643,9 +640,9 @@ ValArray<T>::ValArray(uint16_t numRows, uint16_t numCols, std::valarray<T>&& val
|
||||
};
|
||||
|
||||
template <class T>
|
||||
ValArray<T>::ValArray(uint16_t numRows,
|
||||
uint16_t numCols,
|
||||
uint16_t numPages,
|
||||
ValArray<T>::ValArray(size_t numRows,
|
||||
size_t numCols,
|
||||
size_t numPages,
|
||||
const std::valarray<T>& values)
|
||||
: m_numRows{numRows},
|
||||
m_numCols{numCols},
|
||||
@@ -657,10 +654,7 @@ ValArray<T>::ValArray(uint16_t numRows,
|
||||
};
|
||||
|
||||
template <class T>
|
||||
ValArray<T>::ValArray(uint16_t numRows,
|
||||
uint16_t numCols,
|
||||
uint16_t numPages,
|
||||
std::valarray<T>&& values)
|
||||
ValArray<T>::ValArray(size_t numRows, size_t numCols, size_t numPages, std::valarray<T>&& values)
|
||||
: m_numRows{numRows},
|
||||
m_numCols{numCols},
|
||||
m_numPages{numPages}
|
||||
@@ -723,12 +717,12 @@ std::ostream&
|
||||
operator<<(std::ostream& os, const ValArray<T>& a)
|
||||
{
|
||||
os << "\n";
|
||||
for (auto p = 0; p != a.GetNumPages(); ++p)
|
||||
for (size_t p = 0; p != a.GetNumPages(); ++p)
|
||||
{
|
||||
os << "Page " << p << ":\n";
|
||||
for (auto i = 0; i != a.GetNumRows(); ++i)
|
||||
for (size_t i = 0; i != a.GetNumRows(); ++i)
|
||||
{
|
||||
for (auto j = 0; j != a.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j != a.GetNumCols(); ++j)
|
||||
{
|
||||
os << "\t" << a(i, j, p);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ NS_LOG_COMPONENT_DEFINE("MatrixArrayTest");
|
||||
|
||||
/**
|
||||
* \ingroup matrixArray-tests
|
||||
* MatrixArray test for testing constructors
|
||||
* MatrixArray test case for testing constructors, operators and other functions
|
||||
*/
|
||||
template <class T>
|
||||
class MatrixArrayTestCase : public TestCase
|
||||
@@ -100,9 +100,9 @@ MatrixArrayTestCase<T>::DoRun()
|
||||
// test multiplication of matrices (MatrixArray containing only 1 matrix)
|
||||
MatrixArray<T> m1 = MatrixArray<T>(2, 3);
|
||||
MatrixArray<T> m2 = MatrixArray<T>(m1.GetNumCols(), m1.GetNumRows());
|
||||
for (auto i = 0; i < m1.GetNumRows(); ++i)
|
||||
for (size_t i = 0; i < m1.GetNumRows(); ++i)
|
||||
{
|
||||
for (auto j = 0; j < m1.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j < m1.GetNumCols(); ++j)
|
||||
{
|
||||
m1(i, j) = 1;
|
||||
m2(j, i) = 1;
|
||||
@@ -121,9 +121,9 @@ MatrixArrayTestCase<T>::DoRun()
|
||||
NS_TEST_ASSERT_MSG_EQ(m3.GetNumRows(),
|
||||
m3.GetNumCols(),
|
||||
"The number of rows and cols should be equal");
|
||||
for (auto i = 0; i < m3.GetNumCols(); ++i)
|
||||
for (size_t i = 0; i < m3.GetNumCols(); ++i)
|
||||
{
|
||||
for (auto j = 0; j < m3.GetNumRows(); ++j)
|
||||
for (size_t j = 0; j < m3.GetNumRows(); ++j)
|
||||
{
|
||||
NS_TEST_ASSERT_MSG_EQ(std::real(m3(i, j)),
|
||||
m1.GetNumCols(),
|
||||
@@ -133,9 +133,9 @@ MatrixArrayTestCase<T>::DoRun()
|
||||
|
||||
// multiplication with a scalar value
|
||||
MatrixArray<T> m4 = m3 * (static_cast<T>(5.0));
|
||||
for (auto i = 0; i < m4.GetNumCols(); ++i)
|
||||
for (size_t i = 0; i < m4.GetNumCols(); ++i)
|
||||
{
|
||||
for (auto j = 0; j < m4.GetNumRows(); ++j)
|
||||
for (size_t j = 0; j < m4.GetNumRows(); ++j)
|
||||
{
|
||||
NS_TEST_ASSERT_MSG_EQ(m3(i, j) * (static_cast<T>(5.0)),
|
||||
m4(i, j),
|
||||
@@ -147,11 +147,11 @@ MatrixArrayTestCase<T>::DoRun()
|
||||
// test multiplication of arrays of matrices
|
||||
MatrixArray<T> m5 = MatrixArray<T>(2, 3, 2);
|
||||
MatrixArray<T> m6 = MatrixArray<T>(m5.GetNumCols(), m5.GetNumRows(), m5.GetNumPages());
|
||||
for (auto p = 0; p < m5.GetNumPages(); ++p)
|
||||
for (size_t p = 0; p < m5.GetNumPages(); ++p)
|
||||
{
|
||||
for (auto i = 0; i < m5.GetNumRows(); ++i)
|
||||
for (size_t i = 0; i < m5.GetNumRows(); ++i)
|
||||
{
|
||||
for (auto j = 0; j < m5.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j < m5.GetNumCols(); ++j)
|
||||
{
|
||||
m5(i, j, p) = 1;
|
||||
m6(j, i, p) = 1;
|
||||
@@ -169,11 +169,11 @@ MatrixArrayTestCase<T>::DoRun()
|
||||
m7.GetNumCols(),
|
||||
"The number of rows and cols should be equal");
|
||||
|
||||
for (auto p = 0; p < m7.GetNumPages(); ++p)
|
||||
for (size_t p = 0; p < m7.GetNumPages(); ++p)
|
||||
{
|
||||
for (auto i = 0; i < m7.GetNumCols(); ++i)
|
||||
for (size_t i = 0; i < m7.GetNumCols(); ++i)
|
||||
{
|
||||
for (auto j = 0; j < m7.GetNumRows(); ++j)
|
||||
for (size_t j = 0; j < m7.GetNumRows(); ++j)
|
||||
{
|
||||
NS_TEST_ASSERT_MSG_EQ(std::real(m7(i, j, p)),
|
||||
m5.GetNumCols(),
|
||||
|
||||
@@ -95,9 +95,9 @@ void
|
||||
ValArrayTestCase<T>::DoRun()
|
||||
{
|
||||
ValArray<T> v1 = ValArray<T>(2, 3);
|
||||
for (uint16_t i = 0; i < v1.GetNumRows(); ++i)
|
||||
for (size_t i = 0; i < v1.GetNumRows(); ++i)
|
||||
{
|
||||
for (uint16_t j = 0; j < v1.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j < v1.GetNumCols(); ++j)
|
||||
{
|
||||
v1(i, j) = 1;
|
||||
}
|
||||
@@ -108,9 +108,9 @@ ValArrayTestCase<T>::DoRun()
|
||||
NS_TEST_ASSERT_MSG_EQ(v1.GetNumCols(), v2.GetNumCols(), "The number of cols are not equal.");
|
||||
|
||||
// test copy constructor
|
||||
for (uint16_t i = 0; i < v1.GetNumRows(); ++i)
|
||||
for (size_t i = 0; i < v1.GetNumRows(); ++i)
|
||||
{
|
||||
for (uint16_t j = 0; j < v1.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j < v1.GetNumCols(); ++j)
|
||||
{
|
||||
NS_TEST_ASSERT_MSG_EQ(v1(i, j), v2(i, j), "The elements are not equal.");
|
||||
}
|
||||
@@ -120,9 +120,9 @@ ValArrayTestCase<T>::DoRun()
|
||||
ValArray<T> v3 = v1;
|
||||
NS_TEST_ASSERT_MSG_EQ(v1.GetNumRows(), v3.GetNumRows(), "The number of rows are not equal.");
|
||||
NS_TEST_ASSERT_MSG_EQ(v1.GetNumCols(), v3.GetNumCols(), "The number of cols are not equal.");
|
||||
for (uint16_t i = 0; i < v1.GetNumRows(); ++i)
|
||||
for (size_t i = 0; i < v1.GetNumRows(); ++i)
|
||||
{
|
||||
for (uint16_t j = 0; j < v1.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j < v1.GetNumCols(); ++j)
|
||||
{
|
||||
NS_TEST_ASSERT_MSG_EQ(v1(i, j), v2(i, j), "The elements are not equal.");
|
||||
}
|
||||
@@ -136,9 +136,9 @@ ValArrayTestCase<T>::DoRun()
|
||||
v4 = std::move(v1);
|
||||
NS_LOG_INFO("v4 size after move: " << v4.GetSize());
|
||||
NS_TEST_ASSERT_MSG_EQ(v1size, v4.GetSize(), "The number of elements are not equal.");
|
||||
for (uint16_t i = 0; i < v4.GetNumRows(); ++i)
|
||||
for (size_t i = 0; i < v4.GetNumRows(); ++i)
|
||||
{
|
||||
for (uint16_t j = 0; j < v4.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j < v4.GetNumCols(); ++j)
|
||||
{
|
||||
// Use v3 for comparison since it hasn't moved
|
||||
NS_TEST_ASSERT_MSG_EQ(v3(i, j), v4(i, j), "The elements are not equal.");
|
||||
@@ -150,9 +150,9 @@ ValArrayTestCase<T>::DoRun()
|
||||
size_t v3size = v3.GetSize();
|
||||
ValArray<T> v5(std::move(v3));
|
||||
NS_TEST_ASSERT_MSG_EQ(v3size, v5.GetSize(), "The number of elements are not equal.");
|
||||
for (uint16_t i = 0; i < v5.GetNumRows(); ++i)
|
||||
for (size_t i = 0; i < v5.GetNumRows(); ++i)
|
||||
{
|
||||
for (uint16_t j = 0; j < v5.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j < v5.GetNumCols(); ++j)
|
||||
{
|
||||
// Use v4 for comparison since it hasn't moved
|
||||
NS_TEST_ASSERT_MSG_EQ(v4(i, j), v5(i, j), "The elements are not equal.");
|
||||
@@ -177,10 +177,10 @@ ValArrayTestCase<T>::DoRun()
|
||||
// test whether column-major order was respected during the initialization and
|
||||
// also in the access operator if we iterate over rows first we should find 0, 2, 4, 6, ...
|
||||
std::valarray<int> initArray2{0, 2, 4, 6, 1, 3, 5, 7};
|
||||
auto testIndex = 0;
|
||||
for (uint16_t i = 0; i < v6.GetNumRows(); ++i)
|
||||
size_t testIndex = 0;
|
||||
for (size_t i = 0; i < v6.GetNumRows(); ++i)
|
||||
{
|
||||
for (uint16_t j = 0; j < v6.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j < v6.GetNumCols(); ++j)
|
||||
{
|
||||
NS_TEST_ASSERT_MSG_EQ(v6(i, j),
|
||||
static_cast<T>(initArray2[testIndex]),
|
||||
@@ -203,11 +203,11 @@ ValArrayTestCase<T>::DoRun()
|
||||
// if we iterate over rows first we should find 0, 2, 4, 6, ...
|
||||
std::valarray<int> initArray4{0, 2, 4, 6, 1, 3, 5, 7, 0, 2, 4, 6, 1, 3, 5, 7};
|
||||
testIndex = 0;
|
||||
for (uint16_t p = 0; p < v7.GetNumPages(); ++p)
|
||||
for (size_t p = 0; p < v7.GetNumPages(); ++p)
|
||||
{
|
||||
for (uint16_t i = 0; i < v7.GetNumRows(); ++i)
|
||||
for (size_t i = 0; i < v7.GetNumRows(); ++i)
|
||||
{
|
||||
for (uint16_t j = 0; j < v7.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j < v7.GetNumCols(); ++j)
|
||||
{
|
||||
NS_TEST_ASSERT_MSG_EQ(v7(i, j, p),
|
||||
static_cast<T>(initArray4[testIndex]),
|
||||
@@ -219,11 +219,11 @@ ValArrayTestCase<T>::DoRun()
|
||||
|
||||
// multiplication with a scalar value with 3D array
|
||||
ValArray<T> v8 = v7 * (static_cast<T>(5.0));
|
||||
for (uint16_t p = 0; p < v8.GetNumPages(); ++p)
|
||||
for (size_t p = 0; p < v8.GetNumPages(); ++p)
|
||||
{
|
||||
for (uint16_t i = 0; i < v8.GetNumRows(); ++i)
|
||||
for (size_t i = 0; i < v8.GetNumRows(); ++i)
|
||||
{
|
||||
for (uint16_t j = 0; j < v8.GetNumCols(); ++j)
|
||||
for (size_t j = 0; j < v8.GetNumCols(); ++j)
|
||||
{
|
||||
NS_TEST_ASSERT_MSG_EQ(v7(i, j, p) * (static_cast<T>(5.0)),
|
||||
v8(i, j, p),
|
||||
|
||||
Reference in New Issue
Block a user