38 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>
52 unsigned int subDiagonals,
53 unsigned int superDiagonals) :
54 Matrix<DataType>(rows, columns, policy),
57 m_numberOfSuperDiagonals(superDiagonals),
58 m_numberOfSubDiagonals(subDiagonals),
64 template<
typename DataType>
67 unsigned int subDiagonals,
68 unsigned int superDiagonals,
69 unsigned int capacity) :
70 Matrix<DataType>(rows, columns, policy),
73 m_numberOfSuperDiagonals(superDiagonals),
74 m_numberOfSubDiagonals(subDiagonals),
77 unsigned int requiredStorage = this->GetRequiredStorageSize();
78 unsigned int actualSize = std::max(requiredStorage, capacity);
82 template<
typename DataType>
85 unsigned int subDiagonals,
86 unsigned int superDiagonals) :
87 Matrix<DataType>(rows, columns, policy),
90 m_numberOfSuperDiagonals(superDiagonals),
91 m_numberOfSubDiagonals(subDiagonals),
95 std::fill(m_data.begin(), m_data.end(), initValue);
98 template<
typename DataType>
101 unsigned int subDiagonals,
102 unsigned int superDiagonals) :
103 Matrix<DataType>(rows, columns, policy),
105 m_wrapperType(
eCopy),
106 m_numberOfSuperDiagonals(superDiagonals),
107 m_numberOfSubDiagonals(subDiagonals),
110 unsigned int size = GetRequiredStorageSize();
112 std::copy(data, data + size, m_data.begin());
115 template<
typename DataType>
118 unsigned int subDiagonals,
119 unsigned int superDiagonals) :
120 Matrix<DataType>(rows, columns, policy),
122 m_wrapperType(
eCopy),
123 m_numberOfSuperDiagonals(superDiagonals),
124 m_numberOfSubDiagonals(subDiagonals),
131 template<
typename DataType>
134 unsigned int subDiagonals,
135 unsigned int superDiagonals) :
136 Matrix<DataType>(rows, columns, policy),
138 m_wrapperType(wrapperType),
139 m_numberOfSuperDiagonals(superDiagonals),
140 m_numberOfSubDiagonals(subDiagonals),
154 template<
typename DataType>
158 m_wrapperType(rhs.m_wrapperType),
159 m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
160 m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals),
163 PerformCopyConstruction(rhs);
166 template<
typename DataType>
178 ResizeDataArrayIfNeeded();
180 unsigned int requiredStorageSize = GetRequiredStorageSize();
187 template<
typename DataType>
190 ASSERTL2(row < this->GetRows(), std::string(
"Row ") + std::to_string(row) +
191 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
192 std::string(
" rows"));
193 ASSERTL2(column < this->GetColumns(), std::string(
"Column ") + std::to_string(column) +
194 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
195 std::string(
" columns"));
197 return this->GetValue(row, column, this->GetTransposeFlag());
200 template<
typename DataType>
203 return this->GetValue(row, column, transpose);
206 template<
typename DataType>
210 this->GetRows(), this->GetColumns(),
211 this->GetNumberOfSubDiagonals(), this->GetNumberOfSuperDiagonals());
214 template<
typename DataType>
217 unsigned int numRows = this->GetSize()[0];
218 unsigned int numColumns = this->GetSize()[1];
220 row, col, numRows, numColumns, transpose,
221 m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
224 template<
typename DataType>
227 ASSERTL2(row < this->GetRows(), std::string(
"Row ") + std::to_string(row) +
228 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
229 std::string(
" rows"));
230 ASSERTL2(column < this->GetColumns(), std::string(
"Column ") + std::to_string(column) +
231 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
232 std::string(
" columns"));
234 return GetValue(row, column, this->GetTransposeFlag());
237 template<
typename DataType>
240 static DataType defaultReturnValue;
241 unsigned int index = CalculateIndex(row, column, transpose);
242 if( index != std::numeric_limits<unsigned int>::max() )
244 return m_data[index];
248 return defaultReturnValue;
252 template<
typename DataType>
258 template<
typename DataType>
264 template<
typename DataType>
267 return m_data.data();
270 template<
typename DataType>
273 return begin(this->GetTransposeFlag());
276 template<
typename DataType>
279 if( transpose ==
'N' )
281 return const_iterator(m_data.data(), m_data.data() + m_data.num_elements());
289 template<
typename DataType>
292 return end(this->GetTransposeFlag());
295 template<
typename DataType>
298 if( transpose ==
'N' )
300 return const_iterator(m_data.data(), m_data.data() + m_data.num_elements(),
true);
308 template<
typename DataType>
311 return m_data.num_elements();
314 template<
typename DataType>
317 if( m_numberOfSubDiagonals != std::numeric_limits<unsigned int>::max() )
319 return m_numberOfSubDiagonals;
321 else if( this->GetRows() > 0 )
323 return this->GetRows()-1;
331 template<
typename DataType>
334 if( m_numberOfSuperDiagonals != std::numeric_limits<unsigned int>::max() )
336 return m_numberOfSuperDiagonals;
338 else if( this->GetRows() > 0 )
340 return this->GetRows()-1;
348 template<
typename DataType>
351 return GetNumberOfSubDiagonals() + GetNumberOfSuperDiagonals() + 1;
354 template<
typename DataType>
357 if( this->GetRows() != rhs.
GetRows() ||
365 return std::equal(begin(), end(), rhs.
begin());
369 for(
unsigned int i = 0; i < this->GetRows(); ++i)
371 for(
unsigned int j = 0; j < this->GetColumns(); ++j)
373 if( (*
this)(i,j) !=
rhs(i,j) )
384 template<
typename DataType>
387 template<
typename DataType>
388 std::tuple<unsigned int, unsigned int>
391 return Advance(curRow, curColumn, this->GetTransposeFlag());
394 template<
typename DataType>
395 std::tuple<unsigned int, unsigned int>
398 unsigned int numRows = this->GetTransposedRows(transpose);
399 unsigned int numColumns = this->GetTransposedColumns(transpose);
401 switch(this->GetStorageType())
405 numRows, numColumns, curRow, curColumn);
409 numRows, numColumns, curRow, curColumn);
413 numRows, numColumns, curRow, curColumn);
418 numRows, numColumns, curRow, curColumn);
424 numRows, numColumns, curRow, curColumn);
428 numRows, numColumns, curRow, curColumn);
444 return std::tuple<unsigned int, unsigned int>(curRow, curColumn);
447 template<
typename DataType>
453 template<
typename DataType>
459 template<
typename DataType>
463 m_wrapperType(wrapperType),
464 m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
465 m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals)
467 PerformCopyConstruction(rhs);
471 template<
typename DataType>
474 template<
typename DataType>
477 if( m_wrapperType ==
eCopy )
479 unsigned int requiredStorageSize = GetRequiredStorageSize();
480 if( m_data.num_elements() > requiredStorageSize )
483 CopyArrayN(m_data, newArray, requiredStorageSize);
487 else if( m_wrapperType ==
eWrapper )
489 ASSERTL0(
true,
"Can't call RemoveExcessCapacity on a wrapped matrix.");
493 template<
typename DataType>
496 if( m_wrapperType ==
eCopy )
498 if( m_data.num_elements() < requiredStorageSize )
501 std::copy(m_data.data(), m_data.data() + m_data.num_elements(), newData.
data());
505 else if( m_wrapperType ==
eWrapper )
509 ASSERTL0(m_data.num_elements() >= requiredStorageSize,
"Wrapped NekMatrices must have the same dimension in operator=");
513 template<
typename DataType>
516 unsigned int requiredStorageSize = GetRequiredStorageSize();
517 ResizeDataArrayIfNeeded(requiredStorageSize);
520 template<
typename DataType>
534 template<
typename DataType>
540 template<
typename DataType>
546 template<
typename DataType>
554 template<
typename DataType>
557 this->Resize(rows, cols);
564 this->GetData().ChangeSize(this->GetRequiredStorageSize());
565 ASSERTL0(this->GetRequiredStorageSize() <= this->GetData().num_elements(),
"Can't resize matrices if there is not enough capacity.");
569 template<
typename DataType>
572 ASSERTL2(row < this->GetRows(), std::string(
"Row ") + std::to_string(row) +
573 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
574 std::string(
" rows"));
575 ASSERTL2(column < this->GetColumns(), std::string(
"Column ") + std::to_string(column) +
576 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
577 std::string(
" columns"));
579 return (*
this)(row, column, this->GetTransposeFlag());
582 template<
typename DataType>
585 unsigned int index = this->CalculateIndex(row, column, transpose);
586 if( index != std::numeric_limits<unsigned int>::max() )
588 return Proxy(this->GetData()[index]);
597 template<
typename DataType>
600 ASSERTL2(row < this->GetRows(), std::string(
"Row ") + std::to_string(row) +
601 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
602 std::string(
" rows"));
603 ASSERTL2(column < this->GetColumns(), std::string(
"Column ") + std::to_string(column) +
604 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
605 std::string(
" columns"));
606 SetValue(row, column, d, this->GetTransposeFlag());
609 template<
typename DataType>
612 unsigned int index = this->CalculateIndex(row, column, transpose);
613 if( index != std::numeric_limits<unsigned int>::max() )
615 this->GetData()[index] = d;
623 template<
typename DataType>
626 return this->GetData();
629 template<
typename DataType>
632 return this->GetData().data();
635 template<
typename DataType>
638 return begin(this->GetTransposeFlag());
641 template<
typename DataType>
644 if( transpose ==
'N' )
646 return iterator(this->GetData().data(), this->GetData().data() + this->GetData().num_elements());
654 template<
typename DataType>
657 return end(this->GetTransposeFlag());
660 template<
typename DataType>
663 if( transpose ==
'N' )
665 return iterator(this->GetData().data(), this->GetData().data() + this->GetData().num_elements(),
true);
669 return iterator(
this, transpose,
true);
673 template<
typename DataType>
677 int nvals = this->GetColumns();
681 EigenSolve(EigValReal,EigValImag);
683 Vmath::Vmul(nvals,EigValReal,1,EigValReal,1,EigValReal,1);
684 Vmath::Vmul(nvals,EigValImag,1,EigValImag,1,EigValImag,1);
685 Vmath::Vadd(nvals,EigValReal,1,EigValImag,1,EigValReal,1);
692 template<
typename DataType>
697 ASSERTL0(this->GetRows()==this->GetColumns(),
"Only square matrices can be called");
699 switch(this->GetType())
703 this->GetData(), EigValReal,
704 EigValImag, EigVecs);
707 Vmath::Vcopy(this->GetRows(),&(this->GetData())[0],1, &EigValReal[0],1);
725 template<
typename DataType>
728 ASSERTL0(this->GetRows()==this->GetColumns(),
"Only square matrices can be inverted.");
729 ASSERTL0(this->GetTransposeFlag()==
'N',
"Only untransposed matrices may be inverted.");
731 switch(this->GetType())
735 this->GetData(), this->GetTransposeFlag());
765 template<
typename DataType>
768 if( m_tempSpace.capacity() == 0 )
775 template<
typename DataType>
778 std::swap(m_tempSpace, this->GetData());
781 template<
typename DataType>
789 template<
typename DataType>
792 for(
unsigned int i = 0; i < this->GetPtr().num_elements(); ++i)
794 this->GetPtr()[i] *= s;
800 template<
typename DataType>
815 template<
typename DataType>
818 for(
unsigned int i = 0; i < m.
GetRows(); ++i)
820 for(
unsigned int j = 0; j < m.
GetColumns(); ++j)
#define ASSERTL0(condition, msg)
const Array< OneD, const DataType > & GetPtr() const
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
iterator_impl< const DataType, const ThisType > const_iterator
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 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)
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data, const char transpose)
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
unsigned int m_numberOfSubDiagonals
char GetTransposeFlag() const
Array< OneD, DataType > m_data
MatrixStorage GetType() const
unsigned int GetColumns() const
Matrix< DataType > & operator=(const Matrix< DataType > &rhs)
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)
#define LIB_UTILITIES_EXPORT
void CopyArrayN(const Array< OneD, ConstDataType > &source, Array< OneD, DataType > &dest, unsigned int n)
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)
unsigned int m_numberOfSuperDiagonals
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
PointerWrapper
Specifies if the pointer passed to a NekMatrix or NekVector is copied into an internal representation...
unsigned int GetRows() const
NekMatrix< typename NekMatrix< LhsDataType, LhsMatrixType >::NumberType, StandardMatrixTag > operator-(const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
unsigned int GetNumberOfSuperDiagonals() const
iterator_impl< DataType, ThisType > iterator
static void EigenSolve(unsigned int n, const Array< OneD, const double > &A, Array< OneD, NekDouble > &EigValReal, Array< OneD, NekDouble > &EigValImag, Array< OneD, NekDouble > &EigVecs=NullNekDouble1DArray)
unsigned int GetNumberOfSubDiagonals() const
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed t...
static unsigned int GetRequiredStorageSize(MatrixStorage type, unsigned int rows, unsigned int columns, unsigned int subDiags=0, unsigned int superDiags=0)
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data)
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data)
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs
size_t num_elements() const
Returns the array's size.
void Zero(int n, T *x, const int incx)
Zero vector.
1D Array of constant elements with garbage collection and bounds checking.
bool operator==(const VertexSharedPtr &v1, const VertexSharedPtr &v2)
Define comparison operator for the vertex struct.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
void NegateInPlace(NekVector< DataType > &v)
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')
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 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.