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>
191 unsigned int requiredStorageSize = GetRequiredStorageSize();
193 DataType* lhs_array = m_data.data();
200 template<
typename DataType>
203 ASSERTL2(row < this->GetRows(), std::string(
"Row ") + std::to_string(row) +
204 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
205 std::string(
" rows"));
206 ASSERTL2(column < this->GetColumns(), std::string(
"Column ") + std::to_string(column) +
207 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
208 std::string(
" columns"));
210 return this->GetValue(row, column, this->GetTransposeFlag());
213 template<
typename DataType>
216 return this->GetValue(row, column, transpose);
219 template<
typename DataType>
223 this->GetRows(), this->GetColumns(),
224 this->GetNumberOfSubDiagonals(), this->GetNumberOfSuperDiagonals());
227 template<
typename DataType>
230 unsigned int numRows = this->GetSize()[0];
231 unsigned int numColumns = this->GetSize()[1];
233 row, col, numRows, numColumns, transpose,
234 m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
237 template<
typename DataType>
240 ASSERTL2(row < this->GetRows(), std::string(
"Row ") + std::to_string(row) +
241 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
242 std::string(
" rows"));
243 ASSERTL2(column < this->GetColumns(), std::string(
"Column ") + std::to_string(column) +
244 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
245 std::string(
" columns"));
247 return GetValue(row, column, this->GetTransposeFlag());
250 template<
typename DataType>
253 static DataType defaultReturnValue;
254 unsigned int index = CalculateIndex(row, column, transpose);
255 if( index != std::numeric_limits<unsigned int>::max() )
257 return m_data[index];
261 return defaultReturnValue;
265 template<
typename DataType>
271 template<
typename DataType>
277 template<
typename DataType>
280 return m_data.data();
283 template<
typename DataType>
286 return begin(this->GetTransposeFlag());
289 template<
typename DataType>
292 if( transpose ==
'N' )
294 return const_iterator(m_data.data(), m_data.data() + m_data.size());
302 template<
typename DataType>
305 return end(this->GetTransposeFlag());
308 template<
typename DataType>
311 if( transpose ==
'N' )
313 return const_iterator(m_data.data(), m_data.data() + m_data.size(),
true);
321 template<
typename DataType>
324 return m_data.size();
327 template<
typename DataType>
330 if( m_numberOfSubDiagonals != std::numeric_limits<unsigned int>::max() )
332 return m_numberOfSubDiagonals;
334 else if( this->GetRows() > 0 )
336 return this->GetRows()-1;
344 template<
typename DataType>
347 if( m_numberOfSuperDiagonals != std::numeric_limits<unsigned int>::max() )
349 return m_numberOfSuperDiagonals;
351 else if( this->GetRows() > 0 )
353 return this->GetRows()-1;
361 template<
typename DataType>
364 return GetNumberOfSubDiagonals() + GetNumberOfSuperDiagonals() + 1;
367 template<
typename DataType>
370 if( this->GetRows() != rhs.
GetRows() ||
378 return std::equal(begin(), end(), rhs.
begin());
382 for(
unsigned int i = 0; i < this->GetRows(); ++i)
384 for(
unsigned int j = 0; j < this->GetColumns(); ++j)
386 if( (*
this)(i,j) != rhs(i,j) )
397 template<
typename DataType>
400 template<
typename DataType>
401 std::tuple<unsigned int, unsigned int>
404 return Advance(curRow, curColumn, this->GetTransposeFlag());
407 template<
typename DataType>
408 std::tuple<unsigned int, unsigned int>
411 unsigned int numRows = this->GetTransposedRows(transpose);
412 unsigned int numColumns = this->GetTransposedColumns(transpose);
414 switch(this->GetStorageType())
418 numRows, numColumns, curRow, curColumn);
422 numRows, numColumns, curRow, curColumn);
426 numRows, numColumns, curRow, curColumn);
431 numRows, numColumns, curRow, curColumn);
437 numRows, numColumns, curRow, curColumn);
441 numRows, numColumns, curRow, curColumn);
457 return std::tuple<unsigned int, unsigned int>(curRow, curColumn);
460 template<
typename DataType>
466 template<
typename DataType>
472 template<
typename DataType>
476 m_wrapperType(wrapperType),
477 m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
478 m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals)
480 PerformCopyConstruction(rhs);
484 template<
typename DataType>
487 template<
typename DataType>
490 if( m_wrapperType ==
eCopy )
492 unsigned int requiredStorageSize = GetRequiredStorageSize();
493 if( m_data.size() > requiredStorageSize )
496 CopyArrayN(m_data, newArray, requiredStorageSize);
500 else if( m_wrapperType ==
eWrapper )
502 ASSERTL0(
true,
"Can't call RemoveExcessCapacity on a wrapped matrix.");
506 template<
typename DataType>
509 if( m_wrapperType ==
eCopy )
511 if( m_data.size() < requiredStorageSize )
514 std::copy(m_data.data(), m_data.data() + m_data.size(), newData.
data());
518 else if( m_wrapperType ==
eWrapper )
522 ASSERTL0(m_data.size() >= requiredStorageSize,
"Wrapped NekMatrices must have the same dimension in operator=");
526 template<
typename DataType>
529 unsigned int requiredStorageSize = GetRequiredStorageSize();
530 ResizeDataArrayIfNeeded(requiredStorageSize);
533 template<
typename DataType>
547 template<
typename DataType>
553 template<
typename DataType>
559 template<
typename DataType>
567 template<
typename DataType>
570 this->Resize(rows, cols);
577 this->GetData().ChangeSize(this->GetRequiredStorageSize());
578 ASSERTL0(this->GetRequiredStorageSize() <= this->GetData().size(),
"Can't resize matrices if there is not enough capacity.");
582 template<
typename DataType>
585 ASSERTL2(row < this->GetRows(), std::string(
"Row ") + std::to_string(row) +
586 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
587 std::string(
" rows"));
588 ASSERTL2(column < this->GetColumns(), std::string(
"Column ") + std::to_string(column) +
589 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
590 std::string(
" columns"));
592 return (*
this)(row, column, this->GetTransposeFlag());
595 template<
typename DataType>
598 unsigned int index = this->CalculateIndex(row, column, transpose);
599 if( index != std::numeric_limits<unsigned int>::max() )
601 return Proxy(this->GetData()[index]);
610 template<
typename DataType>
613 ASSERTL2(row < this->GetRows(), std::string(
"Row ") + std::to_string(row) +
614 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
615 std::string(
" rows"));
616 ASSERTL2(column < this->GetColumns(), std::string(
"Column ") + std::to_string(column) +
617 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
618 std::string(
" columns"));
619 SetValue(row, column, d, this->GetTransposeFlag());
622 template<
typename DataType>
625 unsigned int index = this->CalculateIndex(row, column, transpose);
626 if( index != std::numeric_limits<unsigned int>::max() )
628 this->GetData()[index] = d;
636 template<
typename DataType>
639 return this->GetData();
642 template<
typename DataType>
645 return this->GetData().data();
648 template<
typename DataType>
651 return begin(this->GetTransposeFlag());
654 template<
typename DataType>
657 if( transpose ==
'N' )
659 return iterator(this->GetData().data(), this->GetData().data() + this->GetData().size());
667 template<
typename DataType>
670 return end(this->GetTransposeFlag());
673 template<
typename DataType>
676 if( transpose ==
'N' )
678 return iterator(this->GetData().data(), this->GetData().data() + this->GetData().size(),
true);
682 return iterator(
this, transpose,
true);
686 template<
typename DataType>
690 int nvals = this->GetColumns();
695 EigenSolve(EigValReal,EigValImag,Evecs);
697 Vmath::Vmul(nvals,EigValReal,1,EigValReal,1,EigValReal,1);
698 Vmath::Vmul(nvals,EigValImag,1,EigValImag,1,EigValImag,1);
699 Vmath::Vadd(nvals,EigValReal,1,EigValImag,1,EigValReal,1);
706 template<
typename DataType>
711 ASSERTL0(this->GetRows()==this->GetColumns(),
"Only square matrices can be called");
713 switch(this->GetType())
717 this->GetData(), EigValReal,
718 EigValImag, EigVecs);
721 Vmath::Vcopy(this->GetRows(),&(this->GetData())[0],1, &EigValReal[0],1);
739 template<
typename DataType>
742 ASSERTL0(this->GetRows()==this->GetColumns(),
"Only square matrices can be inverted.");
743 ASSERTL0(this->GetTransposeFlag()==
'N',
"Only untransposed matrices may be inverted.");
745 switch(this->GetType())
749 this->GetData(), this->GetTransposeFlag());
779 template<
typename DataType>
782 if( m_tempSpace.capacity() == 0 )
789 template<
typename DataType>
792 std::swap(m_tempSpace, this->GetData());
795 template<
typename DataType>
803 template<
typename DataType>
806 for(
unsigned int i = 0; i < this->GetPtr().size(); ++i)
808 this->GetPtr()[i] *= s;
814 template<
typename DataType>
833 template<
typename DataType>
836 for(
unsigned int i = 0; i < m.
GetRows(); ++i)
838 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)
NekMatrix< typename NekMatrix< LhsDataType, LhsMatrixType >::NumberType, StandardMatrixTag > operator-(const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &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)