43#ifndef _TEUCHOS_SERIALTRIDIMATRIX_HPP_
44#define _TEUCHOS_SERIALTRIDIMATRIX_HPP_
66template<
typename OrdinalType,
typename ScalarType>
141 int shape(OrdinalType numRows);
209 ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex);
219 const ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex)
const;
245 ScalarType*
D()
const {
return D_;}
246 ScalarType*
DL()
const {
return DL_;}
247 ScalarType*
DU()
const {
return DU_;}
278 int scale (
const ScalarType alpha );
371 virtual void print(std::ostream& os)
const;
376 OrdinalType startCol,
379 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
395template<
typename OrdinalType,
typename ScalarType>
408template<
typename OrdinalType,
typename ScalarType>
413 values_ =
new ScalarType [numvals];
424template<
typename OrdinalType,
typename ScalarType>
431 values_ =
new ScalarType[numvals];
449template<
typename OrdinalType,
typename ScalarType>
456 values_ =
new ScalarType[numvals];
468 values_ =
new ScalarType[numvals];
477 for(OrdinalType i = 0 ; i< min ; ++i) {
492 values_ =
new ScalarType[numvals];
495 for(OrdinalType i = 0 ; i< min ; ++i) {
496 D_[i] = Source.
D_[i];
508template<
typename OrdinalType,
typename ScalarType>
511 OrdinalType numRowsCols_in, OrdinalType startRow )
517 values_ =
new ScalarType[numvals];
528template<
typename OrdinalType,
typename ScalarType>
538template<
typename OrdinalType,
typename ScalarType>
544 values_ =
new ScalarType[numvals];
551template<
typename OrdinalType,
typename ScalarType>
557 values_ =
new ScalarType[numvals];
562template<
typename OrdinalType,
typename ScalarType>
565 if(numRowsCols_in <1 ) {
570 const OrdinalType numvals = ( numRowsCols_in == 1) ? 1 : 4*(numRowsCols_in - 1);
571 ScalarType* values_tmp =
new ScalarType[numvals];
573 for(OrdinalType i= 0; i<numvals ; ++i)
574 values_tmp[i] = zero;
577 ScalarType* dl = values_tmp;
578 ScalarType* d = values_tmp + (numRowsCols_in-1);
579 ScalarType* du = d+(numRowsCols_in);
580 ScalarType* du2 = du+(numRowsCols_in - 1);
583 for(OrdinalType i = 0 ; i< min ; ++i) {
608template<
typename OrdinalType,
typename ScalarType>
613 for(OrdinalType i = 0; i<numvals ; ++i)
634template<
typename OrdinalType,
typename ScalarType>
658 values_ =
new ScalarType[numvals];
672 values_ =
new ScalarType[numvals];
683 for(OrdinalType i = 0 ; i < min ; ++i ) {
684 D_[i] = Source.
D()[i];
687 DL_[i] = Source.
DL()[i];
688 DU_[i] = Source.
DU()[i];
702template<
typename OrdinalType,
typename ScalarType>
714template<
typename OrdinalType,
typename ScalarType>
726template<
typename OrdinalType,
typename ScalarType>
747template<
typename OrdinalType,
typename ScalarType>
750 OrdinalType diff = colIndex - rowIndex;
757 return DL_[colIndex];
761 return DU_[rowIndex];
763 return DU2_[rowIndex];
766 "SerialTriDiMatrix<T>::operator (row,col) "
767 "Index (" << rowIndex <<
","<<colIndex<<
") out of range ");
771template<
typename OrdinalType,
typename ScalarType>
774 OrdinalType diff = colIndex - rowIndex;
780 return DL_[colIndex];
784 return DU_[rowIndex];
786 return DU2_[rowIndex];
789 "SerialTriDiMatrix<T>::operator (row,col) "
790 "Index (" << rowIndex <<
","<<colIndex<<
") out of range ");
798template<
typename OrdinalType,
typename ScalarType>
823template<
typename OrdinalType,
typename ScalarType>
831 for (j=i-1; j<= i+1; j++) {
840template<
typename OrdinalType,
typename ScalarType>
847 for (i = j-1; i <= j+1; i++) {
860template<
typename OrdinalType,
typename ScalarType>
863 bool allmatch =
true;
873 for(OrdinalType i = 0; i< numvals; ++i)
879template<
typename OrdinalType,
typename ScalarType>
881 return !((*this) == Operand);
888template<
typename OrdinalType,
typename ScalarType>
891 this->
scale( alpha );
895template<
typename OrdinalType,
typename ScalarType>
900 for (i=0; i < numvals ; ++i ) {
906template<
typename OrdinalType,
typename ScalarType>
917 for (j=0; j<numvals; j++) {
924template<
typename OrdinalType,
typename ScalarType>
929 os <<
"A_Copied: yes" << std::endl;
931 os <<
"A_Copied: no" << std::endl;
932 os <<
"Rows and Columns: " <<
numRowsCols_ << std::endl;
934 os <<
"(matrix is empty, no values to display)" << std::endl;
939 os <<
"DL: "<<std::endl;
943 os <<
"D: "<<std::endl;
947 os <<
"DU: "<<std::endl;
951 os <<
"DU2: "<<std::endl;
957 os <<
" square format:"<<std::endl;
960 if ( j >= i-1 && j <= i+1) {
961 os << (*this)(i,j)<<
" ";
975template<
typename OrdinalType,
typename ScalarType>
978 OrdinalType diff = colIndex - rowIndex;
980 "SerialTriDiMatrix<T>::checkIndex: "
981 "Row index " << rowIndex <<
" out of range [0, "<<
numRowsCols_ <<
"]");
984 "SerialTriDiMatrix<T>::checkIndex: "
985 "Col index " << colIndex <<
" out of range [0, "<<
numRowsCols_ <<
"]");
987 "SerialTriDiMatrix<T>::checkIndex: "
988 "index difference " << diff <<
" out of range [-1, 2]");
991template<
typename OrdinalType,
typename ScalarType>
1002template<
typename OrdinalType,
typename ScalarType>
1004 OrdinalType startRowCol,
1010 if(startRowCol > max )
return;
1012 for(i = startRowCol ; i < max ; ++i) {
1016 D()[i] += inputMatrix.
D()[i];
1017 if(i<(max-1) && (i-1) >= startRowCol) {
1018 DL()[i] += inputMatrix.
DL()[i];
1019 DU()[i] += inputMatrix.
DU()[i];
1021 if(i<(max-2) && (i-2) >= startRowCol) {
1022 DU2()[i] += inputMatrix.
DU2()[i];
1027 D()[i] = inputMatrix.
D()[i];
1028 if(i<(max-1) && (i-1) >= startRowCol) {
1029 DL()[i] = inputMatrix.
DL()[i];
1030 DU()[i] = inputMatrix.
DU()[i];
1032 if(i<(max-2) && (i-2) >= startRowCol) {
1033 DU2()[i] = inputMatrix.
DU2()[i];
Templated interface class to BLAS routines.
Object for storing data and providing functionality that is common to all computational classes.
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
#define TEUCHOS_CHK_REF(a)
#define TEUCHOS_MIN(x, y)
#define TEUCHOS_MAX(x, y)
#define TEUCHOS_CHK_ERR(a)
Teuchos::DataAccess Mode enumerable type.
Defines basic traits for the scalar field type.
BLAS(void)
Default constructor.
void updateFlops(int addflops) const
Increment Flop count for this object.
CompObject()
Default constructor.
Object(int tracebackModeIn=-1)
Default Constructor.
This class creates and provides basic support for TriDi matrix of templated type.
void checkIndex(OrdinalType rowIndex, OrdinalType colIndex=0) const
int reshape(OrdinalType numRowsCols)
Reshaping method for changing the size of a SerialTriDiMatrix, keeping the entries.
virtual void print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream << operator inherited from the Object class.
ScalarType scalarType
Typedef for scalar type.
bool operator==(const SerialTriDiMatrix< OrdinalType, ScalarType > &Operand) const
Equality of two matrices.
void copyMat(SerialTriDiMatrix< OrdinalType, ScalarType > matrix, OrdinalType startCol, ScalarType alpha=ScalarTraits< ScalarType >::zero())
SerialTriDiMatrix< OrdinalType, ScalarType > & assign(const SerialTriDiMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
int shape(OrdinalType numRows)
Shape method for changing the size of a SerialTriDiMatrix, initializing entries to zero.
int scale(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
SerialTriDiMatrix()
Default Constructor.
SerialTriDiMatrix< OrdinalType, ScalarType > & operator+=(const SerialTriDiMatrix< OrdinalType, ScalarType > &Source)
Add another matrix to this matrix.
SerialTriDiMatrix< OrdinalType, ScalarType > & operator-=(const SerialTriDiMatrix< OrdinalType, ScalarType > &Source)
Subtract another matrix from this matrix.
bool empty() const
Returns the column dimension of this matrix.
OrdinalType numRowsCols() const
Returns the row dimension of this matrix.
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
int shapeUninitialized(OrdinalType numRows)
Same as shape() except leaves uninitialized.
virtual ~SerialTriDiMatrix()
Destructor.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Set all values in the matrix to a constant value.
SerialTriDiMatrix< OrdinalType, ScalarType > & operator*=(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
SerialTriDiMatrix< OrdinalType, ScalarType > & operator=(const SerialTriDiMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
ScalarType & operator()(OrdinalType rowIndex, OrdinalType colIndex)
Element access method (non-const).
OrdinalType ordinalType
Typedef for ordinal type.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
bool operator!=(const SerialTriDiMatrix< OrdinalType, ScalarType > &Operand) const
Inequality of two matrices.
ScalarType * values() const
Column access method (non-const).
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
static T one()
Returns representation of one for this scalar type.
T magnitudeType
Mandatory typedef for result of magnitude.
static T zero()
Returns representation of zero for this scalar type.
static T conjugate(T a)
Returns the conjugate of the scalar type a.
static T squareroot(T x)
Returns a number of magnitudeType that is the square root of this scalar type x.
static const bool isComplex
Determines if scalar type is std::complex.