42 #ifndef _TEUCHOS_SERIALBANDDENSEMATRIX_HPP_
43 #define _TEUCHOS_SERIALBANDDENSEMATRIX_HPP_
132 template<
typename OrdinalType,
typename ScalarType>
293 ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex);
303 const ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex)
const;
323 const ScalarType*
operator [] (OrdinalType colIndex)
const;
357 int scale (
const ScalarType alpha );
426 virtual std::ostream&
print(std::ostream& os)
const;
431 void copyMat(ScalarType* inputMatrix, OrdinalType strideInput,
432 OrdinalType
numRows, OrdinalType
numCols, ScalarType* outputMatrix,
435 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
450 template<
typename OrdinalType,
typename ScalarType>
453 BLAS<OrdinalType,ScalarType>(),
459 valuesCopied_ (false),
463 template<
typename OrdinalType,
typename ScalarType>
466 OrdinalType numCols_in,
471 BLAS<OrdinalType,ScalarType>(),
472 numRows_ (numRows_in),
473 numCols_ (numCols_in),
474 stride_ (kl_in+ku_in+1),
477 valuesCopied_ (true),
486 template<
typename OrdinalType,
typename ScalarType>
489 ScalarType* values_in,
490 OrdinalType stride_in,
491 OrdinalType numRows_in,
492 OrdinalType numCols_in,
496 BLAS<OrdinalType,ScalarType>(),
497 numRows_ (numRows_in),
498 numCols_ (numCols_in),
502 valuesCopied_ (false),
513 template<
typename OrdinalType,
typename ScalarType>
517 BLAS<OrdinalType,ScalarType>(),
523 valuesCopied_ (true),
543 for (OrdinalType j = 0; j <
numCols_; ++j) {
558 for (OrdinalType j=0; j<
numCols_; j++) {
567 template<
typename OrdinalType,
typename ScalarType>
571 OrdinalType numRows_in,
572 OrdinalType numCols_in,
573 OrdinalType startCol)
575 BLAS<OrdinalType,ScalarType>(),
576 numRows_ (numRows_in),
577 numCols_ (numCols_in),
578 stride_ (Source.stride_),
581 valuesCopied_ (false),
582 values_ (Source.values_)
594 template<
typename OrdinalType,
typename ScalarType>
604 template<
typename OrdinalType,
typename ScalarType>
606 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType kl_in, OrdinalType ku_in
610 numRows_ = numRows_in;
611 numCols_ = numCols_in;
615 values_ =
new ScalarType[stride_*numCols_];
617 valuesCopied_ =
true;
622 template<
typename OrdinalType,
typename ScalarType>
624 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType kl_in, OrdinalType ku_in
628 numRows_ = numRows_in;
629 numCols_ = numCols_in;
633 values_ =
new ScalarType[stride_*numCols_];
634 valuesCopied_ =
true;
639 template<
typename OrdinalType,
typename ScalarType>
641 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType kl_in, OrdinalType ku_in
646 ScalarType* values_tmp =
new ScalarType[(kl_in+ku_in+1) * numCols_in];
648 for(OrdinalType k = 0; k < (kl_in+ku_in+1) * numCols_in; k++) {
649 values_tmp[k] = zero;
651 OrdinalType numRows_tmp =
TEUCHOS_MIN(numRows_, numRows_in);
652 OrdinalType numCols_tmp =
TEUCHOS_MIN(numCols_, numCols_in);
654 copyMat(values_, stride_, numRows_tmp, numCols_tmp, values_tmp,
658 numRows_ = numRows_in;
659 numCols_ = numCols_in;
663 values_ = values_tmp;
664 valuesCopied_ =
true;
673 template<
typename OrdinalType,
typename ScalarType>
678 for(OrdinalType j = 0; j < numCols_; j++) {
680 values_[(ku_+i-j) + j*stride_] = value_in;
687 template<
typename OrdinalType,
typename ScalarType>
692 for(OrdinalType j = 0; j < numCols_; j++) {
701 template<
typename OrdinalType,
typename ScalarType>
733 const OrdinalType newsize = stride_ * numCols_;
735 values_ =
new ScalarType[newsize];
736 valuesCopied_ =
true;
755 const OrdinalType newsize = stride_ * numCols_;
757 values_ =
new ScalarType[newsize];
758 valuesCopied_ =
true;
762 copyMat(Source.
values_, Source.
stride_, numRows_, numCols_, values_, stride_, 0);
768 template<
typename OrdinalType,
typename ScalarType>
773 if ((numRows_ != Source.
numRows_) || (numCols_ != Source.
numCols_) || (kl_ != Source.
kl_) || (ku_ != Source.
ku_)) {
781 template<
typename OrdinalType,
typename ScalarType>
786 if ((numRows_ != Source.
numRows_) || (numCols_ != Source.
numCols_) || (kl_ != Source.
kl_) || (ku_ != Source.
ku_)) {
794 template<
typename OrdinalType,
typename ScalarType>
803 if ((numRows_ != Source.
numRows_) || (numCols_ != Source.
numCols_) || (kl_ != Source.
kl_) || (ku_ != Source.
ku_)) {
806 copyMat(Source.
values_, Source.
stride_, numRows_, numCols_, values_, stride_, 0);
815 template<
typename OrdinalType,
typename ScalarType>
818 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
819 checkIndex( rowIndex, colIndex );
821 return(values_[colIndex * stride_ + ku_+rowIndex-colIndex]);
824 template<
typename OrdinalType,
typename ScalarType>
827 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
828 checkIndex( rowIndex, colIndex );
830 return(values_[colIndex * stride_ + ku_+rowIndex-colIndex]);
833 template<
typename OrdinalType,
typename ScalarType>
836 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
837 checkIndex( 0, colIndex );
839 return(values_ + colIndex * stride_);
842 template<
typename OrdinalType,
typename ScalarType>
845 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
846 checkIndex( 0, colIndex );
848 return(values_ + colIndex * stride_);
855 template<
typename OrdinalType,
typename ScalarType>
863 for(j = 0; j < numCols_; j++) {
865 ptr = values_ + j * stride_ +
TEUCHOS_MAX(0, ku_-j);
874 updateFlops((kl_+ku_+1) * numCols_);
879 template<
typename OrdinalType,
typename ScalarType>
885 for (i = 0; i < numRows_; i++) {
892 updateFlops((kl_+ku_+1) * numCols_);
897 template<
typename OrdinalType,
typename ScalarType>
903 for (j = 0; j < numCols_; j++) {
909 updateFlops((kl_+ku_+1) * numCols_);
918 template<
typename OrdinalType,
typename ScalarType>
923 if((numRows_ != Operand.
numRows_) || (numCols_ != Operand.
numCols_) || (kl_ != Operand.
kl_) || (ku_ != Operand.
ku_)) {
927 for(j = 0; j < numCols_; j++) {
929 if((*
this)(i, j) != Operand(i, j)) {
939 template<
typename OrdinalType,
typename ScalarType>
942 return !((*this) == Operand);
949 template<
typename OrdinalType,
typename ScalarType>
952 this->scale( alpha );
956 template<
typename OrdinalType,
typename ScalarType>
963 for (j=0; j<numCols_; j++) {
966 *ptr = alpha * (*ptr); ptr++;
969 updateFlops( (kl_+ku_+1)*numCols_ );
974 template<
typename OrdinalType,
typename ScalarType>
985 for (j=0; j<numCols_; j++) {
988 *ptr = A(i,j) * (*ptr); ptr++;
991 updateFlops( (kl_+ku_+1)*numCols_ );
996 template<
typename OrdinalType,
typename ScalarType>
1001 os <<
"Values_copied : yes" << std::endl;
1003 os <<
"Values_copied : no" << std::endl;
1004 os <<
"Rows : " << numRows_ << std::endl;
1005 os <<
"Columns : " << numCols_ << std::endl;
1006 os <<
"Lower Bandwidth : " << kl_ << std::endl;
1007 os <<
"Upper Bandwidth : " << ku_ << std::endl;
1008 os <<
"LDA : " << stride_ << std::endl;
1009 if(numRows_ == 0 || numCols_ == 0) {
1010 os <<
"(matrix is empty, no values to display)" << std::endl;
1013 for(OrdinalType i = 0; i < numRows_; i++) {
1015 os << (*this)(i,j) <<
" ";
1027 template<
typename OrdinalType,
typename ScalarType>
1033 "SerialBandDenseMatrix<T>::checkIndex: "
1034 "Row index " << rowIndex <<
" out of range [0, "<< numRows_ <<
")");
1036 "SerialBandDenseMatrix<T>::checkIndex: "
1037 "Col index " << colIndex <<
" out of range [0, "<< numCols_ <<
")");
1041 template<
typename OrdinalType,
typename ScalarType>
1044 if (valuesCopied_) {
1047 valuesCopied_ =
false;
1051 template<
typename OrdinalType,
typename ScalarType>
1053 ScalarType* inputMatrix, OrdinalType strideInput, OrdinalType numRows_in,
1054 OrdinalType numCols_in, ScalarType* outputMatrix, OrdinalType strideOutput, OrdinalType startCol, ScalarType alpha
1058 ScalarType* ptr1 = 0;
1059 ScalarType* ptr2 = 0;
1061 for(j = 0; j < numCols_in; j++) {
1062 ptr1 = outputMatrix + (j * strideOutput) +
TEUCHOS_MAX(0, ku_-j);
1063 ptr2 = inputMatrix + (j + startCol) * strideInput +
TEUCHOS_MAX(0, ku_-j);
1066 *ptr1++ += alpha*(*ptr2++);
1077 template<
typename OrdinalType,
typename ScalarType>
1087 template<
typename OrdinalType,
typename ScalarType>
1092 printer.
obj.print(out);
1097 template<
typename OrdinalType,
typename ScalarType>
1098 SerialBandDenseMatrixPrinter<OrdinalType,ScalarType>
bool empty() const
Returns whether this matrix is empty.
OrdinalType numRows() const
Returns the row dimension of this matrix.
SerialBandDenseMatrix< OrdinalType, ScalarType > & operator+=(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Source)
Add another matrix to this matrix.
ScalarType & operator()(OrdinalType rowIndex, OrdinalType colIndex)
Element access method (non-const).
int scale(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
int shape(OrdinalType numRows, OrdinalType numCols, OrdinalType kl, OrdinalType ku)
Shape method for changing the size of a SerialBandDenseMatrix, initializing entries to zero...
const SerialBandDenseMatrix< OrdinalType, ScalarType > & obj
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
Ostream manipulator for SerialBandDenseMatrix.
Templated interface class to BLAS routines.
SerialBandDenseMatrixPrinter< OrdinalType, ScalarType > printMat(const SerialBandDenseMatrix< OrdinalType, ScalarType > &obj)
Return SerialBandDenseMatrix ostream manipulator Use as:
SerialBandDenseMatrixPrinter(const SerialBandDenseMatrix< OrdinalType, ScalarType > &obj_in)
virtual ~SerialBandDenseMatrix()
Destructor.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
int reshape(OrdinalType numRows, OrdinalType numCols, OrdinalType kl, OrdinalType ku)
Reshaping method for changing the size of a SerialBandDenseMatrix, keeping the entries.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
SerialBandDenseMatrix< OrdinalType, ScalarType > & assign(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
Object for storing data and providing functionality that is common to all computational classes...
virtual std::ostream & print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream << operator.
This structure defines some basic traits for a scalar field type.
OrdinalType stride() const
Returns the stride between the columns of this matrix in memory.
#define TEUCHOS_CHK_ERR(a)
ScalarType * values() const
Data array access method.
Functionality and data that is common to all computational classes.
std::ostream & operator<<(std::ostream &os, BigUInt< n > a)
bool operator!=(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Operand) const
Inequality of two matrices.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
This class creates and provides basic support for banded dense matrices of templated type...
SerialBandDenseMatrix< OrdinalType, ScalarType > & operator*=(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
#define TEUCHOS_MAX(x, y)
SerialBandDenseMatrix< OrdinalType, ScalarType > & operator-=(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Source)
Subtract another matrix from this matrix.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Set all values in the matrix to a constant value.
int random()
Set all values in the matrix to be random numbers.
SerialBandDenseMatrix()
Default Constructor.
bool operator==(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Operand) const
Equality of two matrices.
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
OrdinalType ordinalType
Typedef for ordinal type.
SerialBandDenseMatrix< OrdinalType, ScalarType > & operator=(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
OrdinalType upperBandwidth() const
Returns the upper bandwidth of this matrix.
void copyMat(ScalarType *inputMatrix, OrdinalType strideInput, OrdinalType numRows, OrdinalType numCols, ScalarType *outputMatrix, OrdinalType strideOutput, OrdinalType startCol, ScalarType alpha=ScalarTraits< ScalarType >::zero())
Defines basic traits for the scalar field type.
static T zero()
Returns representation of zero for this scalar type.
OrdinalType lowerBandwidth() const
Returns the lower bandwidth of this matrix.
void checkIndex(OrdinalType rowIndex, OrdinalType colIndex=0) const
ScalarType * operator[](OrdinalType colIndex)
Column access method (non-const).
ScalarType scalarType
Typedef for scalar type.
#define TEUCHOS_CHK_REF(a)
OrdinalType numCols() const
Returns the column dimension of this matrix.
#define TEUCHOS_MIN(x, y)
Reference-counted pointer class and non-member templated function implementations.
int shapeUninitialized(OrdinalType numRows, OrdinalType numCols, OrdinalType kl, OrdinalType ku)
Same as shape() except leaves uninitialized.
Teuchos::DataAccess Mode enumerable type.