10 #ifndef _TEUCHOS_SERIALBANDDENSEMATRIX_HPP_
11 #define _TEUCHOS_SERIALBANDDENSEMATRIX_HPP_
100 template<
typename OrdinalType,
typename ScalarType>
261 ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex);
271 const ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex)
const;
291 const ScalarType*
operator [] (OrdinalType colIndex)
const;
325 int scale (
const ScalarType alpha );
394 virtual std::ostream&
print(std::ostream& os)
const;
399 void copyMat(ScalarType* inputMatrix, OrdinalType strideInput,
400 OrdinalType
numRows, OrdinalType
numCols, ScalarType* outputMatrix,
403 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
418 template<
typename OrdinalType,
typename ScalarType>
421 BLAS<OrdinalType,ScalarType>(),
427 valuesCopied_ (false),
431 template<
typename OrdinalType,
typename ScalarType>
434 OrdinalType numCols_in,
439 BLAS<OrdinalType,ScalarType>(),
440 numRows_ (numRows_in),
441 numCols_ (numCols_in),
442 stride_ (kl_in+ku_in+1),
445 valuesCopied_ (true),
454 template<
typename OrdinalType,
typename ScalarType>
457 ScalarType* values_in,
458 OrdinalType stride_in,
459 OrdinalType numRows_in,
460 OrdinalType numCols_in,
464 BLAS<OrdinalType,ScalarType>(),
465 numRows_ (numRows_in),
466 numCols_ (numCols_in),
470 valuesCopied_ (false),
481 template<
typename OrdinalType,
typename ScalarType>
485 BLAS<OrdinalType,ScalarType>(),
491 valuesCopied_ (true),
511 for (OrdinalType j = 0; j <
numCols_; ++j) {
526 for (OrdinalType j=0; j<
numCols_; j++) {
535 template<
typename OrdinalType,
typename ScalarType>
539 OrdinalType numRows_in,
540 OrdinalType numCols_in,
541 OrdinalType startCol)
543 BLAS<OrdinalType,ScalarType>(),
544 numRows_ (numRows_in),
545 numCols_ (numCols_in),
546 stride_ (Source.stride_),
549 valuesCopied_ (false),
550 values_ (Source.values_)
562 template<
typename OrdinalType,
typename ScalarType>
572 template<
typename OrdinalType,
typename ScalarType>
574 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType kl_in, OrdinalType ku_in
578 numRows_ = numRows_in;
579 numCols_ = numCols_in;
583 values_ =
new ScalarType[stride_*numCols_];
585 valuesCopied_ =
true;
590 template<
typename OrdinalType,
typename ScalarType>
592 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType kl_in, OrdinalType ku_in
596 numRows_ = numRows_in;
597 numCols_ = numCols_in;
601 values_ =
new ScalarType[stride_*numCols_];
602 valuesCopied_ =
true;
607 template<
typename OrdinalType,
typename ScalarType>
609 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType kl_in, OrdinalType ku_in
614 ScalarType* values_tmp =
new ScalarType[(kl_in+ku_in+1) * numCols_in];
616 for(OrdinalType k = 0; k < (kl_in+ku_in+1) * numCols_in; k++) {
617 values_tmp[k] = zero;
619 OrdinalType numRows_tmp =
TEUCHOS_MIN(numRows_, numRows_in);
620 OrdinalType numCols_tmp =
TEUCHOS_MIN(numCols_, numCols_in);
622 copyMat(values_, stride_, numRows_tmp, numCols_tmp, values_tmp,
626 numRows_ = numRows_in;
627 numCols_ = numCols_in;
631 values_ = values_tmp;
632 valuesCopied_ =
true;
641 template<
typename OrdinalType,
typename ScalarType>
646 for(OrdinalType j = 0; j < numCols_; j++) {
648 values_[(ku_+i-j) + j*stride_] = value_in;
655 template<
typename OrdinalType,
typename ScalarType>
660 for(OrdinalType j = 0; j < numCols_; j++) {
669 template<
typename OrdinalType,
typename ScalarType>
701 const OrdinalType newsize = stride_ * numCols_;
703 values_ =
new ScalarType[newsize];
704 valuesCopied_ =
true;
723 const OrdinalType newsize = stride_ * numCols_;
725 values_ =
new ScalarType[newsize];
726 valuesCopied_ =
true;
730 copyMat(Source.
values_, Source.
stride_, numRows_, numCols_, values_, stride_, 0);
736 template<
typename OrdinalType,
typename ScalarType>
741 if ((numRows_ != Source.
numRows_) || (numCols_ != Source.
numCols_) || (kl_ != Source.
kl_) || (ku_ != Source.
ku_)) {
749 template<
typename OrdinalType,
typename ScalarType>
754 if ((numRows_ != Source.
numRows_) || (numCols_ != Source.
numCols_) || (kl_ != Source.
kl_) || (ku_ != Source.
ku_)) {
762 template<
typename OrdinalType,
typename ScalarType>
771 if ((numRows_ != Source.
numRows_) || (numCols_ != Source.
numCols_) || (kl_ != Source.
kl_) || (ku_ != Source.
ku_)) {
774 copyMat(Source.
values_, Source.
stride_, numRows_, numCols_, values_, stride_, 0);
783 template<
typename OrdinalType,
typename ScalarType>
786 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
787 checkIndex( rowIndex, colIndex );
789 return(values_[colIndex * stride_ + ku_+rowIndex-colIndex]);
792 template<
typename OrdinalType,
typename ScalarType>
795 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
796 checkIndex( rowIndex, colIndex );
798 return(values_[colIndex * stride_ + ku_+rowIndex-colIndex]);
801 template<
typename OrdinalType,
typename ScalarType>
804 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
805 checkIndex( 0, colIndex );
807 return(values_ + colIndex * stride_);
810 template<
typename OrdinalType,
typename ScalarType>
813 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
814 checkIndex( 0, colIndex );
816 return(values_ + colIndex * stride_);
823 template<
typename OrdinalType,
typename ScalarType>
831 for(j = 0; j < numCols_; j++) {
833 ptr = values_ + j * stride_ +
TEUCHOS_MAX(0, ku_-j);
842 updateFlops((kl_+ku_+1) * numCols_);
847 template<
typename OrdinalType,
typename ScalarType>
853 for (i = 0; i < numRows_; i++) {
860 updateFlops((kl_+ku_+1) * numCols_);
865 template<
typename OrdinalType,
typename ScalarType>
871 for (j = 0; j < numCols_; j++) {
877 updateFlops((kl_+ku_+1) * numCols_);
886 template<
typename OrdinalType,
typename ScalarType>
891 if((numRows_ != Operand.
numRows_) || (numCols_ != Operand.
numCols_) || (kl_ != Operand.
kl_) || (ku_ != Operand.
ku_)) {
895 for(j = 0; j < numCols_; j++) {
897 if((*
this)(i, j) != Operand(i, j)) {
907 template<
typename OrdinalType,
typename ScalarType>
910 return !((*this) == Operand);
917 template<
typename OrdinalType,
typename ScalarType>
920 this->scale( alpha );
924 template<
typename OrdinalType,
typename ScalarType>
931 for (j=0; j<numCols_; j++) {
934 *ptr = alpha * (*ptr); ptr++;
937 updateFlops( (kl_+ku_+1)*numCols_ );
942 template<
typename OrdinalType,
typename ScalarType>
953 for (j=0; j<numCols_; j++) {
956 *ptr = A(i,j) * (*ptr); ptr++;
959 updateFlops( (kl_+ku_+1)*numCols_ );
964 template<
typename OrdinalType,
typename ScalarType>
969 os <<
"Values_copied : yes" << std::endl;
971 os <<
"Values_copied : no" << std::endl;
972 os <<
"Rows : " << numRows_ << std::endl;
973 os <<
"Columns : " << numCols_ << std::endl;
974 os <<
"Lower Bandwidth : " << kl_ << std::endl;
975 os <<
"Upper Bandwidth : " << ku_ << std::endl;
976 os <<
"LDA : " << stride_ << std::endl;
977 if(numRows_ == 0 || numCols_ == 0) {
978 os <<
"(matrix is empty, no values to display)" << std::endl;
981 for(OrdinalType i = 0; i < numRows_; i++) {
983 os << (*this)(i,j) <<
" ";
995 template<
typename OrdinalType,
typename ScalarType>
1001 "SerialBandDenseMatrix<T>::checkIndex: "
1002 "Row index " << rowIndex <<
" out of range [0, "<< numRows_ <<
")");
1004 "SerialBandDenseMatrix<T>::checkIndex: "
1005 "Col index " << colIndex <<
" out of range [0, "<< numCols_ <<
")");
1009 template<
typename OrdinalType,
typename ScalarType>
1012 if (valuesCopied_) {
1015 valuesCopied_ =
false;
1019 template<
typename OrdinalType,
typename ScalarType>
1021 ScalarType* inputMatrix, OrdinalType strideInput, OrdinalType numRows_in,
1022 OrdinalType numCols_in, ScalarType* outputMatrix, OrdinalType strideOutput, OrdinalType startCol, ScalarType alpha
1026 ScalarType* ptr1 = 0;
1027 ScalarType* ptr2 = 0;
1029 for(j = 0; j < numCols_in; j++) {
1030 ptr1 = outputMatrix + (j * strideOutput) +
TEUCHOS_MAX(0, ku_-j);
1031 ptr2 = inputMatrix + (j + startCol) * strideInput +
TEUCHOS_MAX(0, ku_-j);
1034 *ptr1++ += alpha*(*ptr2++);
1045 template<
typename OrdinalType,
typename ScalarType>
1055 template<
typename OrdinalType,
typename ScalarType>
1060 printer.
obj.print(out);
1065 template<
typename OrdinalType,
typename ScalarType>
1066 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.