36 template <
typename DataType>
39 m_numberOfSuperDiagonals(std::numeric_limits<unsigned int>::max()),
40 m_numberOfSubDiagonals(std::numeric_limits<unsigned int>::max()),
46 template <
typename DataType>
50 unsigned int subDiagonals,
51 unsigned int superDiagonals)
52 :
Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(
eCopy),
53 m_numberOfSuperDiagonals(superDiagonals),
54 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
59 template <
typename DataType>
63 unsigned int subDiagonals,
64 unsigned int superDiagonals,
65 unsigned int capacity)
66 :
Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(
eCopy),
67 m_numberOfSuperDiagonals(superDiagonals),
68 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
70 unsigned int requiredStorage = this->GetRequiredStorageSize();
71 unsigned int actualSize = std::max(requiredStorage, capacity);
75 template <
typename DataType>
77 unsigned int rows,
unsigned int columns,
78 typename boost::call_traits<DataType>::const_reference initValue,
80 unsigned int superDiagonals)
81 :
Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(
eCopy),
82 m_numberOfSuperDiagonals(superDiagonals),
83 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
86 std::fill(m_data.begin(), m_data.end(), initValue);
89 template <
typename DataType>
94 unsigned int subDiagonals,
95 unsigned int superDiagonals)
96 :
Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(
eCopy),
97 m_numberOfSuperDiagonals(superDiagonals),
98 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
100 unsigned int size = GetRequiredStorageSize();
102 std::copy(data, data + size, m_data.begin());
105 template <
typename DataType>
107 unsigned int rows,
unsigned int columns,
109 unsigned int subDiagonals,
unsigned int superDiagonals)
110 :
Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(
eCopy),
111 m_numberOfSuperDiagonals(superDiagonals),
112 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
118 template <
typename DataType>
122 unsigned int superDiagonals)
123 :
Matrix<DataType>(rows, columns, policy), m_data(),
124 m_wrapperType(wrapperType), m_numberOfSuperDiagonals(superDiagonals),
125 m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
138 template <
typename DataType>
141 :
Matrix<DataType>(rhs), m_data(), m_wrapperType(rhs.m_wrapperType),
142 m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
143 m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals), m_tempSpace()
145 PerformCopyConstruction(rhs);
148 template <
typename DataType>
162 ResizeDataArrayIfNeeded();
164 unsigned int requiredStorageSize = GetRequiredStorageSize();
172 template <
typename DataType>
176 unsigned int requiredStorageSize = GetRequiredStorageSize();
178 DataType *lhs_array = m_data.data();
180 Vmath::Fill(requiredStorageSize, rhs, lhs_array, 1);
185 template <
typename DataType>
187 DataType, StandardMatrixTag>::operator()(
unsigned int row,
188 unsigned int column)
const
191 std::string(
"Row ") + std::to_string(row) +
192 std::string(
" requested in a matrix with a maximum of ") +
193 std::to_string(this->GetRows()) + std::string(
" rows"));
194 ASSERTL2(column < this->GetColumns(),
195 std::string(
"Column ") + std::to_string(column) +
196 std::string(
" requested in a matrix with a maximum of ") +
197 std::to_string(this->GetColumns()) + std::string(
" columns"));
199 return this->GetValue(row, column, this->GetTransposeFlag());
202 template <
typename DataType>
204 DataType, StandardMatrixTag>::operator()(
unsigned int row,
206 char transpose)
const
208 return this->GetValue(row, column, transpose);
211 template <
typename DataType>
216 this->GetStorageType(), this->GetRows(), this->GetColumns(),
217 this->GetNumberOfSubDiagonals(), this->GetNumberOfSuperDiagonals());
220 template <
typename DataType>
222 unsigned int row,
unsigned int col,
const char transpose)
const
224 unsigned int numRows = this->GetSize()[0];
225 unsigned int numColumns = this->GetSize()[1];
227 this->GetStorageType(), row, col, numRows, numColumns, transpose,
228 m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
231 template <
typename DataType>
232 typename boost::call_traits<DataType>::const_reference
NekMatrix<
233 DataType, StandardMatrixTag>::GetValue(
unsigned int row,
234 unsigned int column)
const
237 std::string(
"Row ") + std::to_string(row) +
238 std::string(
" requested in a matrix with a maximum of ") +
239 std::to_string(this->GetRows()) + std::string(
" rows"));
240 ASSERTL2(column < this->GetColumns(),
241 std::string(
"Column ") + std::to_string(column) +
242 std::string(
" requested in a matrix with a maximum of ") +
243 std::to_string(this->GetColumns()) + std::string(
" columns"));
245 return GetValue(row, column, this->GetTransposeFlag());
248 template <
typename DataType>
250 DataType, StandardMatrixTag>::GetValue(
unsigned int row,
252 char transpose)
const
254 static DataType defaultReturnValue;
255 unsigned int index = CalculateIndex(row, column, transpose);
256 if (index != std::numeric_limits<unsigned int>::max())
258 return m_data[index];
262 return defaultReturnValue;
266 template <
typename DataType>
273 template <
typename DataType>
279 template <
typename DataType>
282 return m_data.data();
285 template <
typename DataType>
287 DataType, StandardMatrixTag>::begin()
const
289 return begin(this->GetTransposeFlag());
292 template <
typename DataType>
294 DataType, StandardMatrixTag>::begin(
char transpose)
const
296 if (transpose ==
'N')
298 return const_iterator(m_data.data(), m_data.data() + m_data.size());
306 template <
typename DataType>
308 DataType, StandardMatrixTag>::end()
const
310 return end(this->GetTransposeFlag());
313 template <
typename DataType>
315 DataType, StandardMatrixTag>::end(
char transpose)
const
317 if (transpose ==
'N')
319 return const_iterator(m_data.data(), m_data.data() + m_data.size(),
328 template <
typename DataType>
331 return m_data.size();
334 template <
typename DataType>
338 if (m_numberOfSubDiagonals != std::numeric_limits<unsigned int>::max())
340 return m_numberOfSubDiagonals;
342 else if (this->GetRows() > 0)
344 return this->GetRows() - 1;
352 template <
typename DataType>
356 if (m_numberOfSuperDiagonals != std::numeric_limits<unsigned int>::max())
358 return m_numberOfSuperDiagonals;
360 else if (this->GetRows() > 0)
362 return this->GetRows() - 1;
370 template <
typename DataType>
374 return GetNumberOfSubDiagonals() + GetNumberOfSuperDiagonals() + 1;
377 template <
typename DataType>
381 if (this->GetRows() != rhs.
GetRows() ||
389 return std::equal(begin(), end(), rhs.
begin());
393 for (
unsigned int i = 0; i < this->GetRows(); ++i)
395 for (
unsigned int j = 0; j < this->GetColumns(); ++j)
397 if ((*
this)(i, j) != rhs(i, j))
408 template <
typename DataType>
411 return m_wrapperType;
414 template <
typename DataType>
415 std::tuple<unsigned int, unsigned int>
NekMatrix<
416 DataType, StandardMatrixTag>::Advance(
unsigned int curRow,
417 unsigned int curColumn)
const
419 return Advance(curRow, curColumn, this->GetTransposeFlag());
422 template <
typename DataType>
423 std::tuple<unsigned int, unsigned int>
NekMatrix<
424 DataType, StandardMatrixTag>::Advance(
unsigned int curRow,
425 unsigned int curColumn,
426 char transpose)
const
428 unsigned int numRows = this->GetTransposedRows(transpose);
429 unsigned int numColumns = this->GetTransposedColumns(transpose);
431 switch (this->GetStorageType())
474 return std::tuple<unsigned int, unsigned int>(curRow, curColumn);
477 template <
typename DataType>
484 template <
typename DataType>
485 std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>>
NekMatrix<
486 DataType, StandardMatrixTag>::
490 return std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>>(
494 template <
typename DataType>
498 :
BaseType(rhs), m_data(), m_wrapperType(wrapperType),
499 m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
500 m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals)
502 PerformCopyConstruction(rhs);
505 template <
typename DataType>
511 template <
typename DataType>
514 if (m_wrapperType ==
eCopy)
516 unsigned int requiredStorageSize = GetRequiredStorageSize();
517 if (m_data.size() > requiredStorageSize)
520 CopyArrayN(m_data, newArray, requiredStorageSize);
526 ASSERTL0(
true,
"Can't call RemoveExcessCapacity on a wrapped matrix.");
530 template <
typename DataType>
532 unsigned int requiredStorageSize)
534 if (m_wrapperType ==
eCopy)
536 if (m_data.size() < requiredStorageSize)
539 std::copy(m_data.data(), m_data.data() + m_data.size(),
549 m_data.size() >= requiredStorageSize,
550 "Wrapped NekMatrices must have the same dimension in operator=");
554 template <
typename DataType>
557 unsigned int requiredStorageSize = GetRequiredStorageSize();
558 ResizeDataArrayIfNeeded(requiredStorageSize);
561 template <
typename DataType>
576 template <
typename DataType>
577 typename boost::call_traits<DataType>::value_type
NekMatrix<
578 DataType, StandardMatrixTag>::v_GetValue(
unsigned int row,
579 unsigned int column)
const
584 template <
typename DataType>
590 template <
typename DataType>
592 unsigned int row,
unsigned int column,
593 typename boost::call_traits<DataType>::const_reference d)
598 template <
typename DataType>
602 this->Resize(rows, cols);
609 this->GetData().ChangeSize(this->GetRequiredStorageSize());
610 ASSERTL0(this->GetRequiredStorageSize() <= this->GetData().size(),
611 "Can't resize matrices if there is not enough capacity.");
614 template <
typename DataType>
616 DataType, StandardMatrixTag>::operator()(
unsigned int row,
620 std::string(
"Row ") + std::to_string(row) +
621 std::string(
" requested in a matrix with a maximum of ") +
622 std::to_string(this->GetRows()) + std::string(
" rows"));
623 ASSERTL2(column < this->GetColumns(),
624 std::string(
"Column ") + std::to_string(column) +
625 std::string(
" requested in a matrix with a maximum of ") +
626 std::to_string(this->GetColumns()) + std::string(
" columns"));
628 return (*
this)(row, column, this->GetTransposeFlag());
631 template <
typename DataType>
633 DataType, StandardMatrixTag>::operator()(
unsigned int row,
637 unsigned int index = this->CalculateIndex(row, column, transpose);
638 if (index != std::numeric_limits<unsigned int>::max())
640 return Proxy(this->GetData()[index]);
648 template <
typename DataType>
650 unsigned int row,
unsigned int column,
651 typename boost::call_traits<DataType>::const_reference d)
654 std::string(
"Row ") + std::to_string(row) +
655 std::string(
" requested in a matrix with a maximum of ") +
656 std::to_string(this->GetRows()) + std::string(
" rows"));
657 ASSERTL2(column < this->GetColumns(),
658 std::string(
"Column ") + std::to_string(column) +
659 std::string(
" requested in a matrix with a maximum of ") +
660 std::to_string(this->GetColumns()) + std::string(
" columns"));
661 SetValue(row, column, d, this->GetTransposeFlag());
664 template <
typename DataType>
666 unsigned int row,
unsigned int column,
667 typename boost::call_traits<DataType>::const_reference d,
char transpose)
669 unsigned int index = this->CalculateIndex(row, column, transpose);
670 if (index != std::numeric_limits<unsigned int>::max())
672 this->GetData()[index] = d;
678 "Can't assign values into zeroed elements of a special array.");
682 template <
typename DataType>
685 return this->GetData();
688 template <
typename DataType>
691 return this->GetData().data();
694 template <
typename DataType>
696 DataType, StandardMatrixTag>::begin()
698 return begin(this->GetTransposeFlag());
701 template <
typename DataType>
703 DataType, StandardMatrixTag>::begin(
char transpose)
705 if (transpose ==
'N')
707 return iterator(this->GetData().data(),
708 this->GetData().data() + this->GetData().size());
716 template <
typename DataType>
718 DataType, StandardMatrixTag>::end()
720 return end(this->GetTransposeFlag());
723 template <
typename DataType>
725 DataType, StandardMatrixTag>::end(
char transpose)
727 if (transpose ==
'N')
729 return iterator(this->GetData().data(),
730 this->GetData().data() + this->GetData().size(),
true);
734 return iterator(
this, transpose,
true);
738 template <
typename DataType>
743 int nvals = this->GetColumns();
748 EigenSolve(EigValReal, EigValImag, Evecs);
750 Vmath::Vmul(nvals, EigValReal, 1, EigValReal, 1, EigValReal, 1);
751 Vmath::Vmul(nvals, EigValImag, 1, EigValImag, 1, EigValImag, 1);
752 Vmath::Vadd(nvals, EigValReal, 1, EigValImag, 1, EigValReal, 1);
760 template <
typename DataType>
765 ASSERTL0(this->GetRows() == this->GetColumns(),
766 "Only square matrices can be called");
768 switch (this->GetType())
772 EigValReal, EigValImag, EigVecs);
794 template <
typename DataType>
797 ASSERTL0(this->GetRows() == this->GetColumns(),
798 "Only square matrices can be inverted.");
799 ASSERTL0(this->GetTransposeFlag() ==
'N',
800 "Only untransposed matrices may be inverted.");
802 switch (this->GetType())
806 this->GetData(), this->GetTransposeFlag());
836 template <
typename DataType>
839 if (m_tempSpace.capacity() == 0)
846 template <
typename DataType>
849 std::swap(m_tempSpace, this->GetData());
852 template <
typename DataType>
854 DataType, StandardMatrixTag>::operator-()
const
861 template <
typename DataType>
865 for (
unsigned int i = 0; i < this->GetPtr().size(); ++i)
867 this->GetPtr()[i] *= s;
872 template <
typename DataType>
893 template <
typename DataType>
896 for (
unsigned int i = 0; i < m.
GetRows(); ++i)
898 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)