40template <
typename DataType>
43 m_numberOfSuperDiagonals(
std::numeric_limits<unsigned int>::max()),
44 m_numberOfSubDiagonals(
std::numeric_limits<unsigned int>::max()),
50template <
typename DataType>
54 unsigned int subDiagonals,
55 unsigned int superDiagonals)
56 :
Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(
eCopy),
57 m_numberOfSuperDiagonals(superDiagonals),
58 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
63template <
typename DataType>
67 unsigned int subDiagonals,
68 unsigned int superDiagonals,
69 unsigned int capacity)
70 :
Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(
eCopy),
71 m_numberOfSuperDiagonals(superDiagonals),
72 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
74 unsigned int requiredStorage = this->GetRequiredStorageSize();
75 unsigned int actualSize = std::max(requiredStorage, capacity);
79template <
typename DataType>
81 unsigned int rows,
unsigned int columns,
82 typename boost::call_traits<DataType>::const_reference initValue,
84 unsigned int superDiagonals)
85 :
Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(
eCopy),
86 m_numberOfSuperDiagonals(superDiagonals),
87 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
90 std::fill(m_data.begin(), m_data.end(), initValue);
93template <
typename DataType>
98 unsigned int subDiagonals,
99 unsigned int superDiagonals)
100 :
Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(
eCopy),
101 m_numberOfSuperDiagonals(superDiagonals),
102 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
104 unsigned int size = GetRequiredStorageSize();
106 std::copy(data, data + size, m_data.begin());
109template <
typename DataType>
111 unsigned int rows,
unsigned int columns,
113 unsigned int subDiagonals,
unsigned int superDiagonals)
114 :
Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(
eCopy),
115 m_numberOfSuperDiagonals(superDiagonals),
116 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
122template <
typename DataType>
126 unsigned int superDiagonals)
127 :
Matrix<DataType>(rows, columns, policy), m_data(),
128 m_wrapperType(wrapperType), m_numberOfSuperDiagonals(superDiagonals),
129 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
142template <
typename DataType>
145 :
Matrix<DataType>(rhs), m_data(), m_wrapperType(rhs.m_wrapperType),
146 m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
147 m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals), m_tempSpace()
149 PerformCopyConstruction(rhs);
152template <
typename DataType>
165 ResizeDataArrayIfNeeded();
167 unsigned int requiredStorageSize = GetRequiredStorageSize();
175template <
typename DataType>
177 DataType, StandardMatrixTag>::operator=(
const DataType &rhs)
179 unsigned int requiredStorageSize = GetRequiredStorageSize();
181 DataType *lhs_array = m_data.data();
183 Vmath::Fill(requiredStorageSize, rhs, lhs_array, 1);
188template <
typename DataType>
190 DataType, StandardMatrixTag>::operator()(
unsigned int row,
191 unsigned int column)
const
194 std::string(
"Row ") + std::to_string(row) +
195 std::string(
" requested in a matrix with a maximum of ") +
196 std::to_string(this->GetRows()) + std::string(
" rows"));
197 ASSERTL2(column < this->GetColumns(),
198 std::string(
"Column ") + std::to_string(column) +
199 std::string(
" requested in a matrix with a maximum of ") +
200 std::to_string(this->GetColumns()) + std::string(
" columns"));
202 return this->GetValue(row, column, this->GetTransposeFlag());
205template <
typename DataType>
207 DataType, StandardMatrixTag>::operator()(
unsigned int row,
209 char transpose)
const
211 return this->GetValue(row, column, transpose);
214template <
typename DataType>
219 this->GetStorageType(), this->GetRows(), this->GetColumns(),
220 this->GetNumberOfSubDiagonals(), this->GetNumberOfSuperDiagonals());
223template <
typename DataType>
225 unsigned int row,
unsigned int col,
const char transpose)
const
227 unsigned int numRows = this->GetSize()[0];
228 unsigned int numColumns = this->GetSize()[1];
230 this->GetStorageType(), row, col, numRows, numColumns, transpose,
231 m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
234template <
typename DataType>
235typename boost::call_traits<DataType>::const_reference
NekMatrix<
236 DataType, StandardMatrixTag>::GetValue(
unsigned int row,
237 unsigned int column)
const
240 std::string(
"Row ") + std::to_string(row) +
241 std::string(
" requested in a matrix with a maximum of ") +
242 std::to_string(this->GetRows()) + std::string(
" rows"));
243 ASSERTL2(column < this->GetColumns(),
244 std::string(
"Column ") + std::to_string(column) +
245 std::string(
" requested in a matrix with a maximum of ") +
246 std::to_string(this->GetColumns()) + std::string(
" columns"));
248 return GetValue(row, column, this->GetTransposeFlag());
251template <
typename DataType>
253 DataType, StandardMatrixTag>::GetValue(
unsigned int row,
255 char transpose)
const
257 static DataType defaultReturnValue;
258 unsigned int index = CalculateIndex(row, column, transpose);
259 if (index != std::numeric_limits<unsigned int>::max())
261 return m_data[index];
265 return defaultReturnValue;
269template <
typename DataType>
271 StandardMatrixTag>::GetPtr()
const
276template <
typename DataType>
282template <
typename DataType>
285 return m_data.data();
288template <
typename DataType>
290 DataType, StandardMatrixTag>::begin()
const
292 return begin(this->GetTransposeFlag());
295template <
typename DataType>
297 DataType, StandardMatrixTag>::begin(
char transpose)
const
299 if (transpose ==
'N')
301 return const_iterator(m_data.data(), m_data.data() + m_data.size());
309template <
typename DataType>
311 DataType, StandardMatrixTag>::end()
const
313 return end(this->GetTransposeFlag());
316template <
typename DataType>
318 DataType, StandardMatrixTag>::end(
char transpose)
const
320 if (transpose ==
'N')
322 return const_iterator(m_data.data(), m_data.data() + m_data.size(),
331template <
typename DataType>
334 return m_data.size();
337template <
typename DataType>
341 if (m_numberOfSubDiagonals != std::numeric_limits<unsigned int>::max())
343 return m_numberOfSubDiagonals;
345 else if (this->GetRows() > 0)
347 return this->GetRows() - 1;
355template <
typename DataType>
359 if (m_numberOfSuperDiagonals != std::numeric_limits<unsigned int>::max())
361 return m_numberOfSuperDiagonals;
363 else if (this->GetRows() > 0)
365 return this->GetRows() - 1;
373template <
typename DataType>
377 return GetNumberOfSubDiagonals() + GetNumberOfSuperDiagonals() + 1;
380template <
typename DataType>
384 if (this->GetRows() != rhs.
GetRows() ||
392 return std::equal(begin(), end(), rhs.
begin());
396 for (
unsigned int i = 0; i < this->GetRows(); ++i)
398 for (
unsigned int j = 0; j < this->GetColumns(); ++j)
400 if ((*
this)(i, j) != rhs(i, j))
411template <
typename DataType>
414 return m_wrapperType;
417template <
typename DataType>
418std::tuple<unsigned int, unsigned int>
NekMatrix<
419 DataType, StandardMatrixTag>::Advance(
unsigned int curRow,
420 unsigned int curColumn)
const
422 return Advance(curRow, curColumn, this->GetTransposeFlag());
425template <
typename DataType>
426std::tuple<unsigned int, unsigned int>
NekMatrix<
427 DataType, StandardMatrixTag>::Advance(
unsigned int curRow,
428 unsigned int curColumn,
429 char transpose)
const
431 unsigned int numRows = this->GetTransposedRows(transpose);
432 unsigned int numColumns = this->GetTransposedColumns(transpose);
434 switch (this->GetStorageType())
477 return std::tuple<unsigned int, unsigned int>(curRow, curColumn);
480template <
typename DataType>
487template <
typename DataType>
488std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>>
NekMatrix<
489 DataType, StandardMatrixTag>::
493 return std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>>(
497template <
typename DataType>
501 :
BaseType(rhs), m_data(), m_wrapperType(wrapperType),
502 m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
503 m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals)
505 PerformCopyConstruction(rhs);
508template <
typename DataType>
514template <
typename DataType>
517 if (m_wrapperType ==
eCopy)
519 unsigned int requiredStorageSize = GetRequiredStorageSize();
520 if (m_data.size() > requiredStorageSize)
523 CopyArrayN(m_data, newArray, requiredStorageSize);
529 ASSERTL0(
true,
"Can't call RemoveExcessCapacity on a wrapped matrix.");
533template <
typename DataType>
535 unsigned int requiredStorageSize)
537 if (m_wrapperType ==
eCopy)
539 if (m_data.size() < requiredStorageSize)
542 std::copy(m_data.data(), m_data.data() + m_data.size(),
552 m_data.size() >= requiredStorageSize,
553 "Wrapped NekMatrices must have the same dimension in operator=");
557template <
typename DataType>
560 unsigned int requiredStorageSize = GetRequiredStorageSize();
561 ResizeDataArrayIfNeeded(requiredStorageSize);
564template <
typename DataType>
579template <
typename DataType>
580typename boost::call_traits<DataType>::value_type
NekMatrix<
581 DataType, StandardMatrixTag>::v_GetValue(
unsigned int row,
582 unsigned int column)
const
587template <
typename DataType>
593template <
typename DataType>
595 unsigned int row,
unsigned int column,
596 typename boost::call_traits<DataType>::const_reference
d)
601template <
typename DataType>
605 this->Resize(rows, cols);
612 this->GetData().ChangeSize(this->GetRequiredStorageSize());
613 ASSERTL0(this->GetRequiredStorageSize() <= this->GetData().size(),
614 "Can't resize matrices if there is not enough capacity.");
617template <
typename DataType>
619 DataType, StandardMatrixTag>::operator()(
unsigned int row,
623 std::string(
"Row ") + std::to_string(row) +
624 std::string(
" requested in a matrix with a maximum of ") +
625 std::to_string(this->GetRows()) + std::string(
" rows"));
626 ASSERTL2(column < this->GetColumns(),
627 std::string(
"Column ") + std::to_string(column) +
628 std::string(
" requested in a matrix with a maximum of ") +
629 std::to_string(this->GetColumns()) + std::string(
" columns"));
631 return (*
this)(row, column, this->GetTransposeFlag());
634template <
typename DataType>
636 DataType, StandardMatrixTag>::operator()(
unsigned int row,
640 unsigned int index = this->CalculateIndex(row, column, transpose);
641 if (index != std::numeric_limits<unsigned int>::max())
643 return Proxy(this->GetData()[index]);
651template <
typename DataType>
653 unsigned int row,
unsigned int column,
654 typename boost::call_traits<DataType>::const_reference
d)
657 std::string(
"Row ") + std::to_string(row) +
658 std::string(
" requested in a matrix with a maximum of ") +
659 std::to_string(this->GetRows()) + std::string(
" rows"));
660 ASSERTL2(column < this->GetColumns(),
661 std::string(
"Column ") + std::to_string(column) +
662 std::string(
" requested in a matrix with a maximum of ") +
663 std::to_string(this->GetColumns()) + std::string(
" columns"));
664 SetValue(row, column,
d, this->GetTransposeFlag());
667template <
typename DataType>
669 unsigned int row,
unsigned int column,
670 typename boost::call_traits<DataType>::const_reference
d,
char transpose)
672 unsigned int index = this->CalculateIndex(row, column, transpose);
673 if (index != std::numeric_limits<unsigned int>::max())
675 this->GetData()[index] =
d;
681 "Can't assign values into zeroed elements of a special array.");
685template <
typename DataType>
688 return this->GetData();
691template <
typename DataType>
694 return this->GetData().data();
697template <
typename DataType>
699 DataType, StandardMatrixTag>::begin()
701 return begin(this->GetTransposeFlag());
704template <
typename DataType>
706 DataType, StandardMatrixTag>::begin(
char transpose)
708 if (transpose ==
'N')
710 return iterator(this->GetData().data(),
711 this->GetData().data() + this->GetData().size());
719template <
typename DataType>
721 DataType, StandardMatrixTag>::end()
723 return end(this->GetTransposeFlag());
726template <
typename DataType>
728 DataType, StandardMatrixTag>::end(
char transpose)
730 if (transpose ==
'N')
732 return iterator(this->GetData().data(),
733 this->GetData().data() + this->GetData().size(),
true);
737 return iterator(
this, transpose,
true);
741template <
typename DataType>
746 int nvals = this->GetColumns();
751 EigenSolve(EigValReal, EigValImag, Evecs);
753 Vmath::Vmul(nvals, EigValReal, 1, EigValReal, 1, EigValReal, 1);
754 Vmath::Vmul(nvals, EigValImag, 1, EigValImag, 1, EigValImag, 1);
755 Vmath::Vadd(nvals, EigValReal, 1, EigValImag, 1, EigValReal, 1);
763template <
typename DataType>
768 ASSERTL0(this->GetRows() == this->GetColumns(),
769 "Only square matrices can be called");
771 switch (this->GetType())
775 EigValReal, EigValImag, EigVecs);
797template <
typename DataType>
800 ASSERTL0(this->GetRows() == this->GetColumns(),
801 "Only square matrices can be inverted.");
802 ASSERTL0(this->GetTransposeFlag() ==
'N',
803 "Only untransposed matrices may be inverted.");
805 switch (this->GetType())
809 this->GetData(), this->GetTransposeFlag());
839template <
typename DataType>
842 if (m_tempSpace.capacity() == 0)
849template <
typename DataType>
852 std::swap(m_tempSpace, this->GetData());
855template <
typename DataType>
857 DataType, StandardMatrixTag>::operator-()
const
864template <
typename DataType>
866 DataType, StandardMatrixTag>::operator*=(
const DataType &s)
868 for (
unsigned int i = 0; i < this->GetPtr().size(); ++i)
870 this->GetPtr()[i] *= s;
875template <
typename DataType>
896template <
typename DataType>
899 for (
unsigned int i = 0; i < m.
GetRows(); ++i)
901 for (
unsigned int j = 0; j < m.
GetColumns(); ++j)
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
#define LIB_UTILITIES_EXPORT
bool operator==(const VertexSharedPtr &v1, const VertexSharedPtr &v2)
Define comparison operator for the vertex struct.
1D Array of constant elements with garbage collection and bounds checking.
size_type size() const
Returns the array's size.
MatrixStorage GetType() const
static unsigned int CalculateIndex(MatrixStorage type, unsigned int row, unsigned int col, unsigned int numRows, unsigned int numColumns, const char transpose='N', unsigned int numSubDiags=0, unsigned int numSuperDiags=0)
unsigned int GetRows() const
static unsigned int GetRequiredStorageSize(MatrixStorage type, unsigned int rows, unsigned int columns, unsigned int subDiags=0, unsigned int superDiags=0)
char GetTransposeFlag() const
unsigned int GetColumns() const
Matrix< DataType > & operator=(const Matrix< DataType > &rhs)
unsigned int m_numberOfSuperDiagonals
unsigned int GetNumberOfSubDiagonals() const
iterator_impl< const DataType, const ThisType > const_iterator
iterator_impl< DataType, ThisType > iterator
const Array< OneD, const DataType > & GetPtr() const
unsigned int m_numberOfSubDiagonals
Array< OneD, DataType > m_data
unsigned int GetNumberOfSuperDiagonals() const
std::vector< double > d(NPUPPER *NPUPPER)
void NegateInPlace(NekVector< DataType > &v)
@ eLOWER_TRIANGULAR_BANDED
@ ePOSITIVE_DEFINITE_SYMMETRIC_BANDED
@ ePOSITIVE_DEFINITE_SYMMETRIC
@ eUPPER_TRIANGULAR_BANDED
void CopyArrayN(const Array< OneD, ConstDataType > &source, Array< OneD, DataType > &dest, typename Array< OneD, DataType >::size_type n)
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)
PointerWrapper
Specifies if the pointer passed to a NekMatrix or NekVector is copied into an internal representation...
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
void Zero(int n, T *x, const int incx)
Zero vector.
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
scalarT< T > sqrt(scalarT< T > in)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data)
static void EigenSolve(unsigned int n, const Array< OneD, const DataType > &A, Array< OneD, DataType > &EigValReal, Array< OneD, DataType > &EigValImag, Array< OneD, DataType > &EigVecs)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data, const char transpose)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn, char transpose='N')
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)