40 template <
typename DataType>
43 m_numberOfSuperDiagonals(std::numeric_limits<unsigned int>::max()),
44 m_numberOfSubDiagonals(std::numeric_limits<unsigned int>::max()),
50 template <
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()
63 template <
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);
79 template <
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);
93 template <
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());
109 template <
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()
122 template <
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()
142 template <
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);
152 template <
typename DataType>
166 ResizeDataArrayIfNeeded();
168 unsigned int requiredStorageSize = GetRequiredStorageSize();
176 template <
typename DataType>
180 unsigned int requiredStorageSize = GetRequiredStorageSize();
182 DataType *lhs_array = m_data.data();
184 Vmath::Fill(requiredStorageSize, rhs, lhs_array, 1);
189 template <
typename DataType>
191 DataType, StandardMatrixTag>::operator()(
unsigned int row,
192 unsigned int column)
const
195 std::string(
"Row ") + std::to_string(row) +
196 std::string(
" requested in a matrix with a maximum of ") +
197 std::to_string(this->GetRows()) + std::string(
" rows"));
198 ASSERTL2(column < this->GetColumns(),
199 std::string(
"Column ") + std::to_string(column) +
200 std::string(
" requested in a matrix with a maximum of ") +
201 std::to_string(this->GetColumns()) + std::string(
" columns"));
203 return this->GetValue(row, column, this->GetTransposeFlag());
206 template <
typename DataType>
208 DataType, StandardMatrixTag>::operator()(
unsigned int row,
210 char transpose)
const
212 return this->GetValue(row, column, transpose);
215 template <
typename DataType>
220 this->GetStorageType(), this->GetRows(), this->GetColumns(),
221 this->GetNumberOfSubDiagonals(), this->GetNumberOfSuperDiagonals());
224 template <
typename DataType>
226 unsigned int row,
unsigned int col,
const char transpose)
const
228 unsigned int numRows = this->GetSize()[0];
229 unsigned int numColumns = this->GetSize()[1];
231 this->GetStorageType(), row, col, numRows, numColumns, transpose,
232 m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
235 template <
typename DataType>
236 typename boost::call_traits<DataType>::const_reference
NekMatrix<
237 DataType, StandardMatrixTag>::GetValue(
unsigned int row,
238 unsigned int column)
const
241 std::string(
"Row ") + std::to_string(row) +
242 std::string(
" requested in a matrix with a maximum of ") +
243 std::to_string(this->GetRows()) + std::string(
" rows"));
244 ASSERTL2(column < this->GetColumns(),
245 std::string(
"Column ") + std::to_string(column) +
246 std::string(
" requested in a matrix with a maximum of ") +
247 std::to_string(this->GetColumns()) + std::string(
" columns"));
249 return GetValue(row, column, this->GetTransposeFlag());
252 template <
typename DataType>
254 DataType, StandardMatrixTag>::GetValue(
unsigned int row,
256 char transpose)
const
258 static DataType defaultReturnValue;
259 unsigned int index = CalculateIndex(row, column, transpose);
260 if (index != std::numeric_limits<unsigned int>::max())
262 return m_data[index];
266 return defaultReturnValue;
270 template <
typename DataType>
277 template <
typename DataType>
283 template <
typename DataType>
286 return m_data.data();
289 template <
typename DataType>
291 DataType, StandardMatrixTag>::begin()
const
293 return begin(this->GetTransposeFlag());
296 template <
typename DataType>
298 DataType, StandardMatrixTag>::begin(
char transpose)
const
300 if (transpose ==
'N')
302 return const_iterator(m_data.data(), m_data.data() + m_data.size());
310 template <
typename DataType>
312 DataType, StandardMatrixTag>::end()
const
314 return end(this->GetTransposeFlag());
317 template <
typename DataType>
319 DataType, StandardMatrixTag>::end(
char transpose)
const
321 if (transpose ==
'N')
323 return const_iterator(m_data.data(), m_data.data() + m_data.size(),
332 template <
typename DataType>
335 return m_data.size();
338 template <
typename DataType>
342 if (m_numberOfSubDiagonals != std::numeric_limits<unsigned int>::max())
344 return m_numberOfSubDiagonals;
346 else if (this->GetRows() > 0)
348 return this->GetRows() - 1;
356 template <
typename DataType>
360 if (m_numberOfSuperDiagonals != std::numeric_limits<unsigned int>::max())
362 return m_numberOfSuperDiagonals;
364 else if (this->GetRows() > 0)
366 return this->GetRows() - 1;
374 template <
typename DataType>
378 return GetNumberOfSubDiagonals() + GetNumberOfSuperDiagonals() + 1;
381 template <
typename DataType>
385 if (this->GetRows() != rhs.
GetRows() ||
393 return std::equal(begin(), end(), rhs.
begin());
397 for (
unsigned int i = 0; i < this->GetRows(); ++i)
399 for (
unsigned int j = 0; j < this->GetColumns(); ++j)
401 if ((*
this)(i, j) != rhs(i, j))
412 template <
typename DataType>
415 return m_wrapperType;
418 template <
typename DataType>
419 std::tuple<unsigned int, unsigned int>
NekMatrix<
420 DataType, StandardMatrixTag>::Advance(
unsigned int curRow,
421 unsigned int curColumn)
const
423 return Advance(curRow, curColumn, this->GetTransposeFlag());
426 template <
typename DataType>
427 std::tuple<unsigned int, unsigned int>
NekMatrix<
428 DataType, StandardMatrixTag>::Advance(
unsigned int curRow,
429 unsigned int curColumn,
430 char transpose)
const
432 unsigned int numRows = this->GetTransposedRows(transpose);
433 unsigned int numColumns = this->GetTransposedColumns(transpose);
435 switch (this->GetStorageType())
478 return std::tuple<unsigned int, unsigned int>(curRow, curColumn);
481 template <
typename DataType>
488 template <
typename DataType>
489 std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>>
NekMatrix<
490 DataType, StandardMatrixTag>::
494 return std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>>(
498 template <
typename DataType>
502 :
BaseType(rhs), m_data(), m_wrapperType(wrapperType),
503 m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
504 m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals)
506 PerformCopyConstruction(rhs);
509 template <
typename DataType>
515 template <
typename DataType>
518 if (m_wrapperType ==
eCopy)
520 unsigned int requiredStorageSize = GetRequiredStorageSize();
521 if (m_data.size() > requiredStorageSize)
524 CopyArrayN(m_data, newArray, requiredStorageSize);
530 ASSERTL0(
true,
"Can't call RemoveExcessCapacity on a wrapped matrix.");
534 template <
typename DataType>
536 unsigned int requiredStorageSize)
538 if (m_wrapperType ==
eCopy)
540 if (m_data.size() < requiredStorageSize)
543 std::copy(m_data.data(), m_data.data() + m_data.size(),
553 m_data.size() >= requiredStorageSize,
554 "Wrapped NekMatrices must have the same dimension in operator=");
558 template <
typename DataType>
561 unsigned int requiredStorageSize = GetRequiredStorageSize();
562 ResizeDataArrayIfNeeded(requiredStorageSize);
565 template <
typename DataType>
580 template <
typename DataType>
581 typename boost::call_traits<DataType>::value_type
NekMatrix<
582 DataType, StandardMatrixTag>::v_GetValue(
unsigned int row,
583 unsigned int column)
const
588 template <
typename DataType>
594 template <
typename DataType>
596 unsigned int row,
unsigned int column,
597 typename boost::call_traits<DataType>::const_reference d)
602 template <
typename DataType>
606 this->Resize(rows, cols);
613 this->GetData().ChangeSize(this->GetRequiredStorageSize());
614 ASSERTL0(this->GetRequiredStorageSize() <= this->GetData().size(),
615 "Can't resize matrices if there is not enough capacity.");
618 template <
typename DataType>
620 DataType, StandardMatrixTag>::operator()(
unsigned int row,
624 std::string(
"Row ") + std::to_string(row) +
625 std::string(
" requested in a matrix with a maximum of ") +
626 std::to_string(this->GetRows()) + std::string(
" rows"));
627 ASSERTL2(column < this->GetColumns(),
628 std::string(
"Column ") + std::to_string(column) +
629 std::string(
" requested in a matrix with a maximum of ") +
630 std::to_string(this->GetColumns()) + std::string(
" columns"));
632 return (*
this)(row, column, this->GetTransposeFlag());
635 template <
typename DataType>
637 DataType, StandardMatrixTag>::operator()(
unsigned int row,
641 unsigned int index = this->CalculateIndex(row, column, transpose);
642 if (index != std::numeric_limits<unsigned int>::max())
644 return Proxy(this->GetData()[index]);
652 template <
typename DataType>
654 unsigned int row,
unsigned int column,
655 typename boost::call_traits<DataType>::const_reference d)
658 std::string(
"Row ") + std::to_string(row) +
659 std::string(
" requested in a matrix with a maximum of ") +
660 std::to_string(this->GetRows()) + std::string(
" rows"));
661 ASSERTL2(column < this->GetColumns(),
662 std::string(
"Column ") + std::to_string(column) +
663 std::string(
" requested in a matrix with a maximum of ") +
664 std::to_string(this->GetColumns()) + std::string(
" columns"));
665 SetValue(row, column, d, this->GetTransposeFlag());
668 template <
typename DataType>
670 unsigned int row,
unsigned int column,
671 typename boost::call_traits<DataType>::const_reference d,
char transpose)
673 unsigned int index = this->CalculateIndex(row, column, transpose);
674 if (index != std::numeric_limits<unsigned int>::max())
676 this->GetData()[index] = d;
682 "Can't assign values into zeroed elements of a special array.");
686 template <
typename DataType>
689 return this->GetData();
692 template <
typename DataType>
695 return this->GetData().data();
698 template <
typename DataType>
700 DataType, StandardMatrixTag>::begin()
702 return begin(this->GetTransposeFlag());
705 template <
typename DataType>
707 DataType, StandardMatrixTag>::begin(
char transpose)
709 if (transpose ==
'N')
711 return iterator(this->GetData().data(),
712 this->GetData().data() + this->GetData().size());
720 template <
typename DataType>
722 DataType, StandardMatrixTag>::end()
724 return end(this->GetTransposeFlag());
727 template <
typename DataType>
729 DataType, StandardMatrixTag>::end(
char transpose)
731 if (transpose ==
'N')
733 return iterator(this->GetData().data(),
734 this->GetData().data() + this->GetData().size(),
true);
738 return iterator(
this, transpose,
true);
742 template <
typename DataType>
747 int nvals = this->GetColumns();
752 EigenSolve(EigValReal, EigValImag, Evecs);
754 Vmath::Vmul(nvals, EigValReal, 1, EigValReal, 1, EigValReal, 1);
755 Vmath::Vmul(nvals, EigValImag, 1, EigValImag, 1, EigValImag, 1);
756 Vmath::Vadd(nvals, EigValReal, 1, EigValImag, 1, EigValReal, 1);
764 template <
typename DataType>
769 ASSERTL0(this->GetRows() == this->GetColumns(),
770 "Only square matrices can be called");
772 switch (this->GetType())
776 EigValReal, EigValImag, EigVecs);
798 template <
typename DataType>
801 ASSERTL0(this->GetRows() == this->GetColumns(),
802 "Only square matrices can be inverted.");
803 ASSERTL0(this->GetTransposeFlag() ==
'N',
804 "Only untransposed matrices may be inverted.");
806 switch (this->GetType())
810 this->GetData(), this->GetTransposeFlag());
840 template <
typename DataType>
843 if (m_tempSpace.capacity() == 0)
850 template <
typename DataType>
853 std::swap(m_tempSpace, this->GetData());
856 template <
typename DataType>
858 DataType, StandardMatrixTag>::operator-()
const
865 template <
typename DataType>
869 for (
unsigned int i = 0; i < this->GetPtr().size(); ++i)
871 this->GetPtr()[i] *= s;
876 template <
typename DataType>
897 template <
typename DataType>
900 for (
unsigned int i = 0; i < m.
GetRows(); ++i)
902 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
The above copyright notice and this permission notice shall be included.
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)
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)
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)