10 #ifndef _TEUCHOS_SERIALTRIDIMATRIX_HPP_
11 #define _TEUCHOS_SERIALTRIDIMATRIX_HPP_
33 template<
typename OrdinalType,
typename ScalarType>
108 int shape(OrdinalType numRows);
176 ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex);
186 const ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex)
const;
212 ScalarType*
D()
const {
return D_;}
213 ScalarType*
DL()
const {
return DL_;}
214 ScalarType*
DU()
const {
return DU_;}
245 int scale (
const ScalarType alpha );
337 virtual void print(std::ostream& os)
const;
343 OrdinalType startCol,
346 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
362 template<
typename OrdinalType,
typename ScalarType>
367 valuesCopied_(false),
375 template<
typename OrdinalType,
typename ScalarType>
377 :
CompObject(), numRowsCols_(numRowsCols_in) {
380 values_ =
new ScalarType [numvals];
384 DU2_ = DU_ + (numRowsCols_-1);
391 template<
typename OrdinalType,
typename ScalarType>
394 valuesCopied_(false), values_(values_in)
398 values_ =
new ScalarType[numvals];
409 DU2_ = DU_ + (numRowsCols_-1);
416 template<
typename OrdinalType,
typename ScalarType>
423 values_ =
new ScalarType[numvals];
427 DU2_ = DU_ + (numRowsCols_-1);
435 values_ =
new ScalarType[numvals];
439 DU2_ = DU_ + (numRowsCols_-1);
444 for(OrdinalType i = 0 ; i< min ; ++i) {
459 values_ =
new ScalarType[numvals];
462 for(OrdinalType i = 0 ; i< min ; ++i) {
463 D_[i] = Source.
D_[i];
475 template<
typename OrdinalType,
typename ScalarType>
478 OrdinalType numRowsCols_in, OrdinalType startRow )
480 valuesCopied_(false), values_(Source.values_) {
484 values_ =
new ScalarType[numvals];
495 template<
typename OrdinalType,
typename ScalarType>
505 template<
typename OrdinalType,
typename ScalarType>
509 numRowsCols_ = numRowsCols_in;
510 const OrdinalType numvals = ( numRowsCols_ == 1) ? 1 : 4*(numRowsCols_-1);
511 values_ =
new ScalarType[numvals];
514 valuesCopied_ =
true;
518 template<
typename OrdinalType,
typename ScalarType>
522 numRowsCols_ = numRowsCols_in;
523 const OrdinalType numvals = ( numRowsCols_ == 1) ? 1 : 4*(numRowsCols_-1);
524 values_ =
new ScalarType[numvals];
525 valuesCopied_ =
true;
529 template<
typename OrdinalType,
typename ScalarType>
532 if(numRowsCols_in <1 ) {
537 const OrdinalType numvals = ( numRowsCols_in == 1) ? 1 : 4*(numRowsCols_in - 1);
538 ScalarType* values_tmp =
new ScalarType[numvals];
540 for(OrdinalType i= 0; i<numvals ; ++i)
541 values_tmp[i] = zero;
543 OrdinalType min =
TEUCHOS_MIN(numRowsCols_, numRowsCols_in);
544 ScalarType* dl = values_tmp;
545 ScalarType* d = values_tmp + (numRowsCols_in-1);
546 ScalarType* du = d+(numRowsCols_in);
547 ScalarType* du2 = du+(numRowsCols_in - 1);
550 for(OrdinalType i = 0 ; i< min ; ++i) {
559 numRowsCols_ = numRowsCols_in;
561 values_ = values_tmp;
567 valuesCopied_ =
true;
575 template<
typename OrdinalType,
typename ScalarType>
578 const OrdinalType numvals = (numRowsCols_ == 1) ? 1 : 4*(numRowsCols_-1);
580 for(OrdinalType i = 0; i<numvals ; ++i)
582 values_[i] = value_in;
601 template<
typename OrdinalType,
typename ScalarType>
625 values_ =
new ScalarType[numvals];
626 valuesCopied_ =
true;
639 values_ =
new ScalarType[numvals];
640 valuesCopied_ =
true;
645 D_ = DL_ + (numRowsCols_-1);
646 DU_ = D_ + numRowsCols_;
647 DU2_ = DU_ + (numRowsCols_-1);
650 for(OrdinalType i = 0 ; i < min ; ++i ) {
651 D_[i] = Source.
D()[i];
654 DL_[i] = Source.
DL()[i];
655 DU_[i] = Source.
DU()[i];
658 DU2_[i] = Source.
DU2()[i];
669 template<
typename OrdinalType,
typename ScalarType>
681 template<
typename OrdinalType,
typename ScalarType>
693 template<
typename OrdinalType,
typename ScalarType>
706 copyMat(Source, 0, 0);
714 template<
typename OrdinalType,
typename ScalarType>
717 OrdinalType diff = colIndex - rowIndex;
720 checkIndex( rowIndex, colIndex );
724 return DL_[colIndex];
728 return DU_[rowIndex];
730 return DU2_[rowIndex];
733 "SerialTriDiMatrix<T>::operator (row,col) "
734 "Index (" << rowIndex <<
","<<colIndex<<
") out of range ");
738 template<
typename OrdinalType,
typename ScalarType>
741 OrdinalType diff = colIndex - rowIndex;
743 checkIndex( rowIndex, colIndex );
747 return DL_[colIndex];
751 return DU_[rowIndex];
753 return DU2_[rowIndex];
756 "SerialTriDiMatrix<T>::operator (row,col) "
757 "Index (" << rowIndex <<
","<<colIndex<<
") out of range ");
765 template<
typename OrdinalType,
typename ScalarType>
774 for(j = 0; j < numRowsCols_; j++)
786 updateFlops(numRowsCols_ * numRowsCols_);
790 template<
typename OrdinalType,
typename ScalarType>
796 for (i = 0; i < numRowsCols_; i++) {
798 for (j=i-1; j<= i+1; j++) {
803 updateFlops(numRowsCols_ * numRowsCols_);
807 template<
typename OrdinalType,
typename ScalarType>
813 for (j = 0; j < numRowsCols_; j++) {
814 for (i = j-1; i <= j+1; i++) {
819 updateFlops( (numRowsCols_ == 1) ? 1 : 4*(numRowsCols_-1) );
827 template<
typename OrdinalType,
typename ScalarType>
830 bool allmatch =
true;
838 OrdinalType numvals = (numRowsCols_ == 1)? 1 : 4*(numRowsCols_ -1 );
840 for(OrdinalType i = 0; i< numvals; ++i)
841 allmatch &= (Operand.
values_[i] == values_[i]);
846 template<
typename OrdinalType,
typename ScalarType>
848 return !((*this) == Operand);
855 template<
typename OrdinalType,
typename ScalarType>
858 this->scale( alpha );
862 template<
typename OrdinalType,
typename ScalarType>
866 OrdinalType numvals = (numRowsCols_ == 1)? 1 : 4*(numRowsCols_ -1 );
867 for (i=0; i < numvals ; ++i ) {
873 template<
typename OrdinalType,
typename ScalarType>
883 OrdinalType numvals = (numRowsCols_ == 1)? 1 : 4*(numRowsCols_ -1 );
884 for (j=0; j<numvals; j++) {
885 values_[j] = A.
values_ * values_[j];
887 updateFlops( numvals );
891 template<
typename OrdinalType,
typename ScalarType>
896 os <<
"A_Copied: yes" << std::endl;
898 os <<
"A_Copied: no" << std::endl;
899 os <<
"Rows and Columns: " << numRowsCols_ << std::endl;
900 if(numRowsCols_ == 0) {
901 os <<
"(matrix is empty, no values to display)" << std::endl;
906 os <<
"DL: "<<std::endl;
907 for(
int i=0;i<numRowsCols_-1;++i)
910 os <<
"D: "<<std::endl;
911 for(
int i=0;i<numRowsCols_;++i)
914 os <<
"DU: "<<std::endl;
915 for(
int i=0;i<numRowsCols_-1;++i)
918 os <<
"DU2: "<<std::endl;
919 for(
int i=0;i<numRowsCols_-2;++i)
924 os <<
" square format:"<<std::endl;
925 for(
int i=0 ; i < numRowsCols_ ; ++i ) {
926 for(
int j=0;j<numRowsCols_;++j) {
927 if ( j >= i-1 && j <= i+1) {
928 os << (*this)(i,j)<<
" ";
942 template<
typename OrdinalType,
typename ScalarType>
945 OrdinalType diff = colIndex - rowIndex;
947 "SerialTriDiMatrix<T>::checkIndex: "
948 "Row index " << rowIndex <<
" out of range [0, "<< numRowsCols_ <<
"]");
951 "SerialTriDiMatrix<T>::checkIndex: "
952 "Col index " << colIndex <<
" out of range [0, "<< numRowsCols_ <<
"]");
954 "SerialTriDiMatrix<T>::checkIndex: "
955 "index difference " << diff <<
" out of range [-1, 2]");
958 template<
typename OrdinalType,
typename ScalarType>
965 valuesCopied_ =
false;
969 template<
typename OrdinalType,
typename ScalarType>
971 OrdinalType startRowCol,
976 if(max > numRowsCols_ ) max = numRowsCols_;
977 if(startRowCol > max )
return;
979 for(i = startRowCol ; i < max ; ++i) {
983 D()[i] += inputMatrix.
D()[i];
984 if(i<(max-1) && (i-1) >= startRowCol) {
985 DL()[i] += inputMatrix.
DL()[i];
986 DU()[i] += inputMatrix.
DU()[i];
988 if(i<(max-2) && (i-2) >= startRowCol) {
989 DU2()[i] += inputMatrix.
DU2()[i];
994 D()[i] = inputMatrix.
D()[i];
995 if(i<(max-1) && (i-1) >= startRowCol) {
996 DL()[i] = inputMatrix.
DL()[i];
997 DU()[i] = inputMatrix.
DU()[i];
999 if(i<(max-2) && (i-2) >= startRowCol) {
1000 DU2()[i] = inputMatrix.
DU2()[i];
ScalarType & operator()(OrdinalType rowIndex, OrdinalType colIndex)
Element access method (non-const).
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
void checkIndex(OrdinalType rowIndex, OrdinalType colIndex=0) const
int shape(OrdinalType numRows)
Shape method for changing the size of a SerialTriDiMatrix, initializing entries to zero...
OrdinalType numRowsCols() const
Returns the row dimension of this matrix.
ScalarType scalarType
Typedef for scalar type.
Templated interface class to BLAS routines.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
virtual void print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream << operator inherited from the Object class...
virtual ~SerialTriDiMatrix()
Destructor.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
SerialTriDiMatrix< OrdinalType, ScalarType > & operator=(const SerialTriDiMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
SerialTriDiMatrix< OrdinalType, ScalarType > & assign(const SerialTriDiMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
Object for storing data and providing functionality that is common to all computational classes...
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
This structure defines some basic traits for a scalar field type.
#define TEUCHOS_CHK_ERR(a)
This class creates and provides basic support for TriDi matrix of templated type. ...
ScalarType * values() const
Column access method (non-const).
Functionality and data that is common to all computational classes.
static T conjugate(T a)
Returns the conjugate of the scalar type a.
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
int scale(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
bool operator==(const SerialTriDiMatrix< OrdinalType, ScalarType > &Operand) const
Equality of two matrices.
SerialTriDiMatrix< OrdinalType, ScalarType > & operator*=(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
#define TEUCHOS_MAX(x, y)
bool empty() const
Returns the column dimension of this matrix.
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
SerialTriDiMatrix()
Default Constructor.
SerialTriDiMatrix< OrdinalType, ScalarType > & operator+=(const SerialTriDiMatrix< OrdinalType, ScalarType > &Source)
Add another matrix to this matrix.
OrdinalType ordinalType
Typedef for ordinal type.
Defines basic traits for the scalar field type.
static T zero()
Returns representation of zero for this scalar type.
void copyMat(SerialTriDiMatrix< OrdinalType, ScalarType > matrix, OrdinalType startCol, ScalarType alpha=ScalarTraits< ScalarType >::zero())
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Set all values in the matrix to a constant value.
#define TEUCHOS_CHK_REF(a)
int reshape(OrdinalType numRowsCols)
Reshaping method for changing the size of a SerialTriDiMatrix, keeping the entries.
bool operator!=(const SerialTriDiMatrix< OrdinalType, ScalarType > &Operand) const
Inequality of two matrices.
SerialTriDiMatrix< OrdinalType, ScalarType > & operator-=(const SerialTriDiMatrix< OrdinalType, ScalarType > &Source)
Subtract another matrix from this matrix.
#define TEUCHOS_MIN(x, y)
int shapeUninitialized(OrdinalType numRows)
Same as shape() except leaves uninitialized.
Teuchos::DataAccess Mode enumerable type.