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 );
424 #ifndef TEUCHOS_HIDE_DEPRECATED_CODE
426 virtual void print(std::ostream& os)
const;
428 virtual std::ostream&
print(std::ostream& os)
const;
433 void copyMat(ScalarType* inputMatrix, OrdinalType strideInput,
434 OrdinalType
numRows, OrdinalType
numCols, ScalarType* outputMatrix,
437 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
452 template<
typename OrdinalType,
typename ScalarType>
455 BLAS<OrdinalType,ScalarType>(),
461 valuesCopied_ (false),
465 template<
typename OrdinalType,
typename ScalarType>
468 OrdinalType numCols_in,
473 BLAS<OrdinalType,ScalarType>(),
474 numRows_ (numRows_in),
475 numCols_ (numCols_in),
476 stride_ (kl_in+ku_in+1),
479 valuesCopied_ (true),
488 template<
typename OrdinalType,
typename ScalarType>
491 ScalarType* values_in,
492 OrdinalType stride_in,
493 OrdinalType numRows_in,
494 OrdinalType numCols_in,
498 BLAS<OrdinalType,ScalarType>(),
499 numRows_ (numRows_in),
500 numCols_ (numCols_in),
504 valuesCopied_ (false),
515 template<
typename OrdinalType,
typename ScalarType>
519 BLAS<OrdinalType,ScalarType>(),
525 valuesCopied_ (true),
545 for (OrdinalType j = 0; j <
numCols_; ++j) {
560 for (OrdinalType j=0; j<
numCols_; j++) {
569 template<
typename OrdinalType,
typename ScalarType>
573 OrdinalType numRows_in,
574 OrdinalType numCols_in,
575 OrdinalType startCol)
577 BLAS<OrdinalType,ScalarType>(),
578 numRows_ (numRows_in),
579 numCols_ (numCols_in),
580 stride_ (Source.stride_),
583 valuesCopied_ (false),
584 values_ (Source.values_)
596 template<
typename OrdinalType,
typename ScalarType>
606 template<
typename OrdinalType,
typename ScalarType>
608 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType kl_in, OrdinalType ku_in
612 numRows_ = numRows_in;
613 numCols_ = numCols_in;
617 values_ =
new ScalarType[stride_*numCols_];
619 valuesCopied_ =
true;
624 template<
typename OrdinalType,
typename ScalarType>
626 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType kl_in, OrdinalType ku_in
630 numRows_ = numRows_in;
631 numCols_ = numCols_in;
635 values_ =
new ScalarType[stride_*numCols_];
636 valuesCopied_ =
true;
641 template<
typename OrdinalType,
typename ScalarType>
643 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType kl_in, OrdinalType ku_in
648 ScalarType* values_tmp =
new ScalarType[(kl_in+ku_in+1) * numCols_in];
650 for(OrdinalType k = 0; k < (kl_in+ku_in+1) * numCols_in; k++) {
651 values_tmp[k] = zero;
653 OrdinalType numRows_tmp =
TEUCHOS_MIN(numRows_, numRows_in);
654 OrdinalType numCols_tmp =
TEUCHOS_MIN(numCols_, numCols_in);
656 copyMat(values_, stride_, numRows_tmp, numCols_tmp, values_tmp,
660 numRows_ = numRows_in;
661 numCols_ = numCols_in;
665 values_ = values_tmp;
666 valuesCopied_ =
true;
675 template<
typename OrdinalType,
typename ScalarType>
680 for(OrdinalType j = 0; j < numCols_; j++) {
682 values_[(ku_+i-j) + j*stride_] = value_in;
689 template<
typename OrdinalType,
typename ScalarType>
694 for(OrdinalType j = 0; j < numCols_; j++) {
703 template<
typename OrdinalType,
typename ScalarType>
735 const OrdinalType newsize = stride_ * numCols_;
737 values_ =
new ScalarType[newsize];
738 valuesCopied_ =
true;
757 const OrdinalType newsize = stride_ * numCols_;
759 values_ =
new ScalarType[newsize];
760 valuesCopied_ =
true;
764 copyMat(Source.
values_, Source.
stride_, numRows_, numCols_, values_, stride_, 0);
770 template<
typename OrdinalType,
typename ScalarType>
775 if ((numRows_ != Source.
numRows_) || (numCols_ != Source.
numCols_) || (kl_ != Source.
kl_) || (ku_ != Source.
ku_)) {
783 template<
typename OrdinalType,
typename ScalarType>
788 if ((numRows_ != Source.
numRows_) || (numCols_ != Source.
numCols_) || (kl_ != Source.
kl_) || (ku_ != Source.
ku_)) {
796 template<
typename OrdinalType,
typename ScalarType>
805 if ((numRows_ != Source.
numRows_) || (numCols_ != Source.
numCols_) || (kl_ != Source.
kl_) || (ku_ != Source.
ku_)) {
808 copyMat(Source.
values_, Source.
stride_, numRows_, numCols_, values_, stride_, 0);
817 template<
typename OrdinalType,
typename ScalarType>
820 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
821 checkIndex( rowIndex, colIndex );
823 return(values_[colIndex * stride_ + ku_+rowIndex-colIndex]);
826 template<
typename OrdinalType,
typename ScalarType>
829 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
830 checkIndex( rowIndex, colIndex );
832 return(values_[colIndex * stride_ + ku_+rowIndex-colIndex]);
835 template<
typename OrdinalType,
typename ScalarType>
838 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
839 checkIndex( 0, colIndex );
841 return(values_ + colIndex * stride_);
844 template<
typename OrdinalType,
typename ScalarType>
847 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
848 checkIndex( 0, colIndex );
850 return(values_ + colIndex * stride_);
857 template<
typename OrdinalType,
typename ScalarType>
865 for(j = 0; j < numCols_; j++) {
867 ptr = values_ + j * stride_ +
TEUCHOS_MAX(0, ku_-j);
876 updateFlops((kl_+ku_+1) * numCols_);
881 template<
typename OrdinalType,
typename ScalarType>
887 for (i = 0; i < numRows_; i++) {
894 updateFlops((kl_+ku_+1) * numCols_);
899 template<
typename OrdinalType,
typename ScalarType>
905 for (j = 0; j < numCols_; j++) {
911 updateFlops((kl_+ku_+1) * numCols_);
920 template<
typename OrdinalType,
typename ScalarType>
925 if((numRows_ != Operand.
numRows_) || (numCols_ != Operand.
numCols_) || (kl_ != Operand.
kl_) || (ku_ != Operand.
ku_)) {
929 for(j = 0; j < numCols_; j++) {
931 if((*
this)(i, j) != Operand(i, j)) {
941 template<
typename OrdinalType,
typename ScalarType>
944 return !((*this) == Operand);
951 template<
typename OrdinalType,
typename ScalarType>
954 this->scale( alpha );
958 template<
typename OrdinalType,
typename ScalarType>
965 for (j=0; j<numCols_; j++) {
968 *ptr = alpha * (*ptr); ptr++;
971 updateFlops( (kl_+ku_+1)*numCols_ );
976 template<
typename OrdinalType,
typename ScalarType>
987 for (j=0; j<numCols_; j++) {
990 *ptr = A(i,j) * (*ptr); ptr++;
993 updateFlops( (kl_+ku_+1)*numCols_ );
998 template<
typename OrdinalType,
typename ScalarType>
999 #ifndef TEUCHOS_HIDE_DEPRECATED_CODE
1007 os <<
"Values_copied : yes" << std::endl;
1009 os <<
"Values_copied : no" << std::endl;
1010 os <<
"Rows : " << numRows_ << std::endl;
1011 os <<
"Columns : " << numCols_ << std::endl;
1012 os <<
"Lower Bandwidth : " << kl_ << std::endl;
1013 os <<
"Upper Bandwidth : " << ku_ << std::endl;
1014 os <<
"LDA : " << stride_ << std::endl;
1015 if(numRows_ == 0 || numCols_ == 0) {
1016 os <<
"(matrix is empty, no values to display)" << std::endl;
1019 for(OrdinalType i = 0; i < numRows_; i++) {
1021 os << (*this)(i,j) <<
" ";
1026 #ifdef TEUCHOS_HIDE_DEPRECATED_CODE
1035 template<
typename OrdinalType,
typename ScalarType>
1041 "SerialBandDenseMatrix<T>::checkIndex: "
1042 "Row index " << rowIndex <<
" out of range [0, "<< numRows_ <<
")");
1044 "SerialBandDenseMatrix<T>::checkIndex: "
1045 "Col index " << colIndex <<
" out of range [0, "<< numCols_ <<
")");
1049 template<
typename OrdinalType,
typename ScalarType>
1052 if (valuesCopied_) {
1055 valuesCopied_ =
false;
1059 template<
typename OrdinalType,
typename ScalarType>
1061 ScalarType* inputMatrix, OrdinalType strideInput, OrdinalType numRows_in,
1062 OrdinalType numCols_in, ScalarType* outputMatrix, OrdinalType strideOutput, OrdinalType startCol, ScalarType alpha
1066 ScalarType* ptr1 = 0;
1067 ScalarType* ptr2 = 0;
1069 for(j = 0; j < numCols_in; j++) {
1070 ptr1 = outputMatrix + (j * strideOutput) +
TEUCHOS_MAX(0, ku_-j);
1071 ptr2 = inputMatrix + (j + startCol) * strideInput +
TEUCHOS_MAX(0, ku_-j);
1074 *ptr1++ += alpha*(*ptr2++);
1084 #ifndef TEUCHOS_HIDE_DEPRECATED_CODE
1085 template<
typename OrdinalType,
typename ScalarType>
1087 std::ostream& operator<< (std::ostream& os, const Teuchos::SerialBandDenseMatrix<OrdinalType, ScalarType>& obj)
1095 template<
typename OrdinalType,
typename ScalarType>
1105 template<
typename OrdinalType,
typename ScalarType>
1110 printer.
obj.print(out);
1115 template<
typename OrdinalType,
typename ScalarType>
1116 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...
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.
virtual void print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream << operator.
#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.