10#ifndef _TEUCHOS_SERIALTRIDIMATRIX_HPP_
11#define _TEUCHOS_SERIALTRIDIMATRIX_HPP_
21#include "Teuchos_Assert.hpp"
33template<
typename OrdinalType,
typename ScalarType>
213 ScalarType* DL()
const {
return DL_;}
214 ScalarType* DU()
const {
return DU_;}
215 ScalarType* DU2()
const {
return DU2_;}
226 SerialTriDiMatrix<OrdinalType, ScalarType>&
operator+= (
const SerialTriDiMatrix<OrdinalType, ScalarType>& Source);
232 SerialTriDiMatrix<OrdinalType, ScalarType>&
operator-= (
const SerialTriDiMatrix<OrdinalType, ScalarType>& Source);
238 SerialTriDiMatrix<OrdinalType, ScalarType>&
operator*= (
const ScalarType alpha);
245 int scale (
const ScalarType alpha );
254 int scale (
const SerialTriDiMatrix<OrdinalType, ScalarType>& A );
296 bool operator== (
const SerialTriDiMatrix<OrdinalType, ScalarType> &Operand)
const;
302 bool operator!= (
const SerialTriDiMatrix<OrdinalType, ScalarType> &Operand)
const;
319 bool empty()
const {
return(numRowsCols_ == 0); }
338 virtual void print(std::ostream& os)
const;
362template<
typename OrdinalType,
typename ScalarType>
367 valuesCopied_(
false),
375template<
typename OrdinalType,
typename ScalarType>
382 D_ = DL_ + (numRowsCols_-1);
383 DU_ = D_ + numRowsCols_;
384 DU2_ = DU_ + (numRowsCols_-1);
386 valuesCopied_ =
true;
391template<
typename OrdinalType,
typename ScalarType>
399 valuesCopied_ =
true;
404 valuesCopied_ =
false;
407 D_ = DL_ + (numRowsCols_-1);
408 DU_ = D_ + numRowsCols_;
409 DU2_ = DU_ + (numRowsCols_-1);
416template<
typename OrdinalType,
typename ScalarType>
420 numRowsCols_ = Source.numRowsCols_;
425 D_ = DL_+ (numRowsCols_-1);
426 DU_ = D_ + numRowsCols_;
427 DU2_ = DU_ + (numRowsCols_-1);
429 copyMat(Source, 0, 0);
433 numRowsCols_ = Source.numRowsCols_;
437 D_ = DL_+(numRowsCols_-1);
438 DU_ = D_ + numRowsCols_;
439 DU2_ = DU_ + (numRowsCols_-1);
442 if(min > Source.numRowsCols_) min = Source.numRowsCols_;
457 numRowsCols_ = Source.numRowsCols_;
461 if(min > Source.numRowsCols_) min = Source.numRowsCols_;
463 D_[
i] = Source.D_[
i];
465 DL_[
i] = Source.DL_[
i];
466 DU_[
i] = Source.DU_[
i];
469 DU2_[
i] = Source.DU2_[
i];
475template<
typename OrdinalType,
typename ScalarType>
480 valuesCopied_(
false), values_(Source.values_) {
486 valuesCopied_ =
true;
495template<
typename OrdinalType,
typename ScalarType>
505template<
typename OrdinalType,
typename ScalarType>
514 valuesCopied_ =
true;
518template<
typename OrdinalType,
typename ScalarType>
525 valuesCopied_ =
true;
529template<
typename OrdinalType,
typename ScalarType>
567 valuesCopied_ =
true;
575template<
typename OrdinalType,
typename ScalarType>
601template<
typename OrdinalType,
typename ScalarType>
607 if((!valuesCopied_) && (!Source.valuesCopied_) && (values_ == Source.values_))
611 if (!Source.valuesCopied_) {
616 numRowsCols_ = Source.numRowsCols_;
617 values_ = Source.values_;
622 numRowsCols_ = Source.numRowsCols_;
623 const OrdinalType numvals = ( Source.numRowsCols_ == 1) ? 1 : 4*(Source.numRowsCols_ - 1);
626 valuesCopied_ =
true;
636 numRowsCols_ = Source.numRowsCols_;
637 const OrdinalType numvals = ( Source.numRowsCols_ == 1) ? 1 : 4*(Source.numRowsCols_ - 1);
640 valuesCopied_ =
true;
645 D_ = DL_ + (numRowsCols_-1);
646 DU_ = D_ + numRowsCols_;
647 DU2_ = DU_ + (numRowsCols_-1);
649 OrdinalType min = TEUCHOS_MIN(numRowsCols_, Source.numRowsCols_);
651 D_[
i] = Source.D()[
i];
654 DL_[
i] = Source.DL()[
i];
655 DU_[
i] = Source.DU()[
i];
658 DU2_[
i] = Source.DU2()[
i];
669template<
typename OrdinalType,
typename ScalarType>
673 if ((numRowsCols_ != Source.numRowsCols_) )
675 TEUCHOS_CHK_REF(*
this);
681template<
typename OrdinalType,
typename ScalarType>
685 if ((numRowsCols_ != Source.numRowsCols_) )
687 TEUCHOS_CHK_REF(*
this);
693template<
typename OrdinalType,
typename ScalarType>
698 if((!valuesCopied_) && (!Source.valuesCopied_) && (values_ == Source.values_))
702 if ((numRowsCols_ != Source.numRowsCols_) )
704 TEUCHOS_CHK_REF(*
this);
706 copyMat(Source, 0, 0);
714template<
typename OrdinalType,
typename ScalarType>
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 ");
738template<
typename OrdinalType,
typename ScalarType>
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 ");
765template<
typename OrdinalType,
typename ScalarType>
774 for(
j = 0;
j < numRowsCols_;
j++)
786 updateFlops(numRowsCols_ * numRowsCols_);
790template<
typename OrdinalType,
typename ScalarType>
796 for (
i = 0;
i < numRowsCols_;
i++) {
798 for (
j=
i-1;
j<=
i+1;
j++) {
803 updateFlops(numRowsCols_ * numRowsCols_);
807template<
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) );
827template<
typename OrdinalType,
typename ScalarType>
832 if((numRowsCols_ !=
Operand.numRowsCols_) )
846template<
typename OrdinalType,
typename ScalarType>
855template<
typename OrdinalType,
typename ScalarType>
858 this->scale(
alpha );
862template<
typename OrdinalType,
typename ScalarType>
873template<
typename OrdinalType,
typename ScalarType>
879 if ((numRowsCols_ !=
A.numRowsCols_) )
885 values_[
j] =
A.values_ * values_[
j];
891template<
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)<<
" ";
942template<
typename OrdinalType,
typename ScalarType>
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]");
958template<
typename OrdinalType,
typename ScalarType>
959void SerialTriDiMatrix<OrdinalType, ScalarType>::deleteArrays(
void)
965 valuesCopied_ =
false;
969template<
typename OrdinalType,
typename ScalarType>
970void SerialTriDiMatrix<OrdinalType, ScalarType>::copyMat(SerialTriDiMatrix<OrdinalType, ScalarType> inputMatrix,
971 OrdinalType startRowCol,
975 OrdinalType max = inputMatrix.numRowsCols_;
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];
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.
Teuchos::DataAccess Mode enumerable type.
Defines basic traits for the scalar field type.
Functionality and data that is common to all computational classes.
Smart reference counting pointer class for automatic garbage collection.
This class creates and provides basic support for TriDi matrix of templated type.
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.
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.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
This structure defines some basic traits for a scalar field type.
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
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.