10#ifndef _TEUCHOS_SERIALBANDDENSEMATRIX_HPP_
11#define _TEUCHOS_SERIALBANDDENSEMATRIX_HPP_
22#include "Teuchos_Assert.hpp"
100template<
typename OrdinalType,
typename ScalarType>
374 bool empty()
const {
return(numRows_ == 0 || numCols_ == 0); }
394 virtual std::ostream& print(std::ostream& os)
const;
418template<
typename OrdinalType,
typename ScalarType>
427 valuesCopied_ (
false),
431template<
typename OrdinalType,
typename ScalarType>
445 valuesCopied_ (
true),
454template<
typename OrdinalType,
typename ScalarType>
470 valuesCopied_ (
false),
477 valuesCopied_ =
true;
481template<
typename OrdinalType,
typename ScalarType>
491 valuesCopied_ (
true),
495 numRows_ = Source.numRows_;
496 numCols_ = Source.numCols_;
501 copyMat (Source.values_, Source.stride_, numRows_, numCols_,
502 values_, stride_, 0);
505 numRows_ = Source.numCols_;
506 numCols_ = Source.numRows_;
513 i <= TEUCHOS_MIN(numRows_-1,
j+kl_); ++
i) {
514 values_[
j*stride_ + (ku_+
i-
j)] =
520 numRows_ = Source.numCols_;
521 numCols_ = Source.numRows_;
528 i <= TEUCHOS_MIN(numRows_-1,
j+kl_); ++
i) {
529 values_[
j*stride_ + (ku_+
i-
j)] = Source.values_[
i*Source.stride_ + (Source.ku_+
j-
i)];
535template<
typename OrdinalType,
typename ScalarType>
546 stride_ (Source.stride_),
549 valuesCopied_ (
false),
550 values_ (Source.values_)
556 valuesCopied_ =
true;
558 values_ = values_ + (stride_ *
startCol);
562template<
typename OrdinalType,
typename ScalarType>
572template<
typename OrdinalType,
typename ScalarType>
585 valuesCopied_ =
true;
590template<
typename OrdinalType,
typename ScalarType>
602 valuesCopied_ =
true;
607template<
typename OrdinalType,
typename ScalarType>
632 valuesCopied_ =
true;
641template<
typename OrdinalType,
typename ScalarType>
647 for (
OrdinalType i=TEUCHOS_MAX(0,
j-ku_);
i<=TEUCHOS_MIN(numRows_-1,
j+kl_);
i++) {
655template<
typename OrdinalType,
typename ScalarType>
661 for (
OrdinalType i=TEUCHOS_MAX(0,
j-ku_);
i<=TEUCHOS_MIN(numRows_-1,
j+kl_);
i++) {
669template<
typename OrdinalType,
typename ScalarType>
678 if((!valuesCopied_) && (!Source.valuesCopied_) && (values_ == Source.values_))
682 if (!Source.valuesCopied_) {
687 numRows_ = Source.numRows_;
688 numCols_ = Source.numCols_;
691 stride_ = Source.stride_;
692 values_ = Source.values_;
696 numRows_ = Source.numRows_;
697 numCols_ = Source.numCols_;
704 valuesCopied_ =
true;
710 if((Source.numRows_ <= stride_) && (Source.numCols_ == numCols_)) {
711 numRows_ = Source.numRows_;
712 numCols_ = Source.numCols_;
718 numRows_ = Source.numRows_;
719 numCols_ = Source.numCols_;
726 valuesCopied_ =
true;
730 copyMat(Source.values_, Source.stride_, numRows_, numCols_, values_, stride_, 0);
736template<
typename OrdinalType,
typename ScalarType>
741 if ((numRows_ != Source.numRows_) || (numCols_ != Source.numCols_) || (kl_ != Source.kl_) || (ku_ != Source.ku_)) {
742 TEUCHOS_CHK_REF(*
this);
749template<
typename OrdinalType,
typename ScalarType>
754 if ((numRows_ != Source.numRows_) || (numCols_ != Source.numCols_) || (kl_ != Source.kl_) || (ku_ != Source.ku_)) {
755 TEUCHOS_CHK_REF(*
this);
762template<
typename OrdinalType,
typename ScalarType>
767 if((!valuesCopied_) && (!Source.valuesCopied_) && (values_ == Source.values_))
771 if ((numRows_ != Source.numRows_) || (numCols_ != Source.numCols_) || (kl_ != Source.kl_) || (ku_ != Source.ku_)) {
772 TEUCHOS_CHK_REF(*
this);
774 copyMat(Source.values_, Source.stride_, numRows_, numCols_, values_, stride_, 0);
783template<
typename OrdinalType,
typename ScalarType>
786#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
787 checkIndex( rowIndex, colIndex );
789 return(values_[colIndex * stride_ + ku_+rowIndex-colIndex]);
792template<
typename OrdinalType,
typename ScalarType>
795#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
796 checkIndex( rowIndex, colIndex );
798 return(values_[colIndex * stride_ + ku_+rowIndex-colIndex]);
801template<
typename OrdinalType,
typename ScalarType>
804#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
805 checkIndex( 0, colIndex );
807 return(values_ + colIndex * stride_);
810template<
typename OrdinalType,
typename ScalarType>
813#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
814 checkIndex( 0, colIndex );
816 return(values_ + colIndex * stride_);
823template<
typename OrdinalType,
typename ScalarType>
831 for(
j = 0;
j < numCols_;
j++) {
833 ptr = values_ +
j * stride_ + TEUCHOS_MAX(0, ku_-
j);
834 for (
i=TEUCHOS_MAX(0,
j-ku_);
i<=TEUCHOS_MIN(numRows_-1,
j+kl_);
i++) {
842 updateFlops((kl_+ku_+1) * numCols_);
847template<
typename OrdinalType,
typename ScalarType>
853 for (
i = 0;
i < numRows_;
i++) {
855 for (
j=TEUCHOS_MAX(0,
i-kl_);
j<=TEUCHOS_MIN(numCols_-1,
i+ku_);
j++) {
860 updateFlops((kl_+ku_+1) * numCols_);
865template<
typename OrdinalType,
typename ScalarType>
871 for (
j = 0;
j < numCols_;
j++) {
872 for (
i=TEUCHOS_MAX(0,
j-ku_);
i<=TEUCHOS_MIN(numRows_-1,
j+kl_);
i++) {
877 updateFlops((kl_+ku_+1) * numCols_);
886template<
typename OrdinalType,
typename ScalarType>
895 for(
j = 0;
j < numCols_;
j++) {
896 for (
i=TEUCHOS_MAX(0,
j-ku_);
i<=TEUCHOS_MIN(numRows_-1,
j+kl_);
i++) {
907template<
typename OrdinalType,
typename ScalarType>
917template<
typename OrdinalType,
typename ScalarType>
920 this->scale(
alpha );
924template<
typename OrdinalType,
typename ScalarType>
931 for (
j=0;
j<numCols_;
j++) {
932 ptr = values_ +
j*stride_ + TEUCHOS_MAX(0, ku_-
j);
933 for (
i=TEUCHOS_MAX(0,
j-ku_);
i<=TEUCHOS_MIN(numRows_-1,
j+kl_);
i++) {
937 updateFlops( (kl_+ku_+1)*numCols_ );
942template<
typename OrdinalType,
typename ScalarType>
950 if ((numRows_ !=
A.numRows_) || (numCols_ !=
A.numCols_) || (kl_ !=
A.kl_) || (ku_ !=
A.ku_)) {
953 for (
j=0;
j<numCols_;
j++) {
954 ptr = values_ +
j*stride_ + TEUCHOS_MAX(0, ku_-
j);
955 for (
i=TEUCHOS_MAX(0,
j-ku_);
i<=TEUCHOS_MIN(numRows_-1,
j+kl_);
i++) {
959 updateFlops( (kl_+ku_+1)*numCols_ );
964template<
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;
982 for (
OrdinalType j=TEUCHOS_MAX(0,
i-kl_);
j<=TEUCHOS_MIN(numCols_-1,
i+ku_);
j++) {
983 os << (*this)(
i,
j) <<
" ";
995template<
typename OrdinalType,
typename ScalarType>
999 rowIndex < TEUCHOS_MAX(0,colIndex-ku_) || rowIndex > TEUCHOS_MIN(numRows_-1,colIndex+kl_),
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_ <<
")");
1009template<
typename OrdinalType,
typename ScalarType>
1010void SerialBandDenseMatrix<OrdinalType, ScalarType>::deleteArrays(
void)
1012 if (valuesCopied_) {
1015 valuesCopied_ =
false;
1019template<
typename OrdinalType,
typename ScalarType>
1020void SerialBandDenseMatrix<OrdinalType, ScalarType>::copyMat(
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);
1033 for (i=TEUCHOS_MAX(0,j-ku_); i<=TEUCHOS_MIN(numRows_in-1,j+kl_); i++) {
1034 *ptr1++ += alpha*(*ptr2++);
1037 for (i=TEUCHOS_MAX(0,j-ku_); i<=TEUCHOS_MIN(numRows_in-1,j+kl_); i++) {
1045template<
typename OrdinalType,
typename ScalarType>
1055template<
typename OrdinalType,
typename ScalarType>
1065template<
typename OrdinalType,
typename ScalarType>
1066SerialBandDenseMatrixPrinter<OrdinalType,ScalarType>
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.
Reference-counted pointer class and non-member templated function implementations.
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.
Ptr< T > ptr() const
Get a safer wrapper raw C++ pointer to the underlying object.
This class creates and provides basic support for banded dense matrices of templated type.
SerialBandDenseMatrix< OrdinalType, ScalarType > & operator+=(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Source)
Add another matrix to this matrix.
virtual ~SerialBandDenseMatrix()
Destructor.
int shapeUninitialized(OrdinalType numRows, OrdinalType numCols, OrdinalType kl, OrdinalType ku)
Same as shape() except leaves uninitialized.
SerialBandDenseMatrix()
Default Constructor.
int random()
Set all values in the matrix to be random numbers.
OrdinalType numCols() const
Returns the column dimension of this matrix.
virtual std::ostream & print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream << operator.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
ScalarType scalarType
Typedef for scalar type.
SerialBandDenseMatrix< OrdinalType, ScalarType > & operator=(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
bool empty() const
Returns whether this matrix is empty.
OrdinalType ordinalType
Typedef for ordinal type.
ScalarType * values() const
Data array access method.
OrdinalType numRows() const
Returns the row dimension of this matrix.
int scale(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
SerialBandDenseMatrix< OrdinalType, ScalarType > & operator-=(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Source)
Subtract another matrix from this matrix.
ScalarType * operator[](OrdinalType colIndex)
Column access method (non-const).
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Set all values in the matrix to a constant value.
SerialBandDenseMatrix< OrdinalType, ScalarType > & operator*=(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
OrdinalType lowerBandwidth() const
Returns the lower bandwidth of this matrix.
bool operator==(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Operand) const
Equality of two matrices.
int reshape(OrdinalType numRows, OrdinalType numCols, OrdinalType kl, OrdinalType ku)
Reshaping method for changing the size of a SerialBandDenseMatrix, keeping the entries.
OrdinalType stride() const
Returns the stride between the columns of this matrix in memory.
SerialBandDenseMatrix< OrdinalType, ScalarType > & assign(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
bool operator!=(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Operand) const
Inequality of two matrices.
ScalarType & operator()(OrdinalType rowIndex, OrdinalType colIndex)
Element access method (non-const).
int shape(OrdinalType numRows, OrdinalType numCols, OrdinalType kl, OrdinalType ku)
Shape method for changing the size of a SerialBandDenseMatrix, initializing entries to zero.
OrdinalType upperBandwidth() const
Returns the upper bandwidth of this matrix.
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
#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,...
SerialBandDenseMatrixPrinter< OrdinalType, ScalarType > printMat(const SerialBandDenseMatrix< OrdinalType, ScalarType > &obj)
Return SerialBandDenseMatrix ostream manipulator Use as:
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.
Ostream manipulator for SerialBandDenseMatrix.