42 #ifndef _TEUCHOS_SERIALDENSEMATRIX_HPP_
43 #define _TEUCHOS_SERIALDENSEMATRIX_HPP_
68 template<
typename OrdinalType,
typename ScalarType>
230 ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex);
240 const ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex)
const;
260 const ScalarType*
operator [] (OrdinalType colIndex)
const;
294 int scale (
const ScalarType alpha );
386 virtual void print(std::ostream& os)
const;
391 void copyMat(ScalarType* inputMatrix, OrdinalType strideInput,
392 OrdinalType
numRows, OrdinalType
numCols, ScalarType* outputMatrix,
393 OrdinalType strideOutput, OrdinalType startRow, OrdinalType startCol,
396 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
409 template<
typename OrdinalType,
typename ScalarType>
411 :
CompObject(),
BLAS<OrdinalType,ScalarType>(), numRows_(0), numCols_(0), stride_(0), valuesCopied_(false), values_(0)
414 template<
typename OrdinalType,
typename ScalarType>
416 OrdinalType numRows_in, OrdinalType numCols_in,
bool zeroOut
418 :
CompObject(),
BLAS<OrdinalType,ScalarType>(), numRows_(numRows_in), numCols_(numCols_in), stride_(numRows_in)
426 template<
typename OrdinalType,
typename ScalarType>
428 DataAccess CV, ScalarType* values_in, OrdinalType stride_in, OrdinalType numRows_in,
429 OrdinalType numCols_in
431 :
CompObject(),
BLAS<OrdinalType,ScalarType>(), numRows_(numRows_in), numCols_(numCols_in), stride_(stride_in),
432 valuesCopied_(false), values_(values_in)
443 template<
typename OrdinalType,
typename ScalarType>
445 :
CompObject(),
BLAS<OrdinalType,ScalarType>(), numRows_(0), numCols_(0), stride_(0), valuesCopied_(true), values_(0)
463 values_ =
new ScalarType[newsize];
478 for (OrdinalType j=0; j<
numCols_; j++) {
479 for (OrdinalType i=0; i<
numRows_; i++) {
490 for (OrdinalType j=0; j<
numCols_; j++) {
491 for (OrdinalType i=0; i<
numRows_; i++) {
499 template<
typename OrdinalType,
typename ScalarType>
503 :
CompObject(), numRows_(Source.numRows_), numCols_(Source.numCols_), stride_(Source.stride_),
504 valuesCopied_(false), values_(Source.values_)
516 template<
typename OrdinalType,
typename ScalarType>
519 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType startRow,
522 :
CompObject(), numRows_(numRows_in), numCols_(numCols_in), stride_(Source.stride_),
523 valuesCopied_(false), values_(Source.values_)
538 template<
typename OrdinalType,
typename ScalarType>
548 template<
typename OrdinalType,
typename ScalarType>
550 OrdinalType numRows_in, OrdinalType numCols_in
554 numRows_ = numRows_in;
555 numCols_ = numCols_in;
557 values_ =
new ScalarType[stride_*numCols_];
559 valuesCopied_ =
true;
563 template<
typename OrdinalType,
typename ScalarType>
565 OrdinalType numRows_in, OrdinalType numCols_in
569 numRows_ = numRows_in;
570 numCols_ = numCols_in;
572 values_ =
new ScalarType[stride_*numCols_];
573 valuesCopied_ =
true;
577 template<
typename OrdinalType,
typename ScalarType>
579 OrdinalType numRows_in, OrdinalType numCols_in
583 ScalarType* values_tmp =
new ScalarType[numRows_in * numCols_in];
585 for(OrdinalType k = 0; k < numRows_in * numCols_in; k++)
587 values_tmp[k] = zero;
589 OrdinalType numRows_tmp =
TEUCHOS_MIN(numRows_, numRows_in);
590 OrdinalType numCols_tmp =
TEUCHOS_MIN(numCols_, numCols_in);
593 copyMat(values_, stride_, numRows_tmp, numCols_tmp, values_tmp,
597 numRows_ = numRows_in;
598 numCols_ = numCols_in;
600 values_ = values_tmp;
601 valuesCopied_ =
true;
609 template<
typename OrdinalType,
typename ScalarType>
613 for(OrdinalType j = 0; j < numCols_; j++)
615 for(OrdinalType i = 0; i < numRows_; i++)
617 values_[i + j*stride_] = value_in;
623 template<
typename OrdinalType,
typename ScalarType>
void
641 std::swap(values_ , B.
values_);
648 template<
typename OrdinalType,
typename ScalarType>
652 for(OrdinalType j = 0; j < numCols_; j++)
654 for(OrdinalType i = 0; i < numRows_; i++)
662 template<
typename OrdinalType,
typename ScalarType>
690 const OrdinalType newsize = stride_ * numCols_;
692 values_ =
new ScalarType[newsize];
693 valuesCopied_ =
true;
710 const OrdinalType newsize = stride_ * numCols_;
712 values_ =
new ScalarType[newsize];
713 valuesCopied_ =
true;
717 copyMat(Source.
values_, Source.
stride_, numRows_, numCols_, values_, stride_, 0, 0);
722 template<
typename OrdinalType,
typename ScalarType>
734 template<
typename OrdinalType,
typename ScalarType>
746 template<
typename OrdinalType,
typename ScalarType>
758 copyMat(Source.
values_, Source.
stride_, numRows_, numCols_, values_, stride_, 0, 0);
766 template<
typename OrdinalType,
typename ScalarType>
769 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
770 checkIndex( rowIndex, colIndex );
772 return(values_[colIndex * stride_ + rowIndex]);
775 template<
typename OrdinalType,
typename ScalarType>
778 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
779 checkIndex( rowIndex, colIndex );
781 return(values_[colIndex * stride_ + rowIndex]);
784 template<
typename OrdinalType,
typename ScalarType>
787 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
788 checkIndex( 0, colIndex );
790 return(values_ + colIndex * stride_);
793 template<
typename OrdinalType,
typename ScalarType>
796 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
797 checkIndex( 0, colIndex );
799 return(values_ + colIndex * stride_);
806 template<
typename OrdinalType,
typename ScalarType>
813 for(j = 0; j < numCols_; j++)
816 ptr = values_ + j * stride_;
817 for(i = 0; i < numRows_; i++)
828 if (flopCounter_!=0) updateFlops(numRows_ * numCols_);
832 template<
typename OrdinalType,
typename ScalarType>
838 for (i = 0; i < numRows_; i++) {
840 for (j=0; j< numCols_; j++) {
846 if (flopCounter_!=0) updateFlops(numRows_ * numCols_);
850 template<
typename OrdinalType,
typename ScalarType>
855 for (j = 0; j < numCols_; j++) {
856 for (i = 0; i < numRows_; i++) {
862 if (flopCounter_!=0) updateFlops(numRows_ * numCols_);
870 template<
typename OrdinalType,
typename ScalarType>
881 for(i = 0; i < numRows_; i++)
883 for(j = 0; j < numCols_; j++)
885 if((*
this)(i, j) != Operand(i, j))
895 template<
typename OrdinalType,
typename ScalarType>
898 return !((*this) == Operand);
905 template<
typename OrdinalType,
typename ScalarType>
908 this->scale( alpha );
912 template<
typename OrdinalType,
typename ScalarType>
918 for (j=0; j<numCols_; j++) {
919 ptr = values_ + j*stride_;
920 for (i=0; i<numRows_; i++) { *ptr = alpha * (*ptr); ptr++; }
923 if (flopCounter_!=0) updateFlops( numRows_*numCols_ );
927 template<
typename OrdinalType,
typename ScalarType>
938 for (j=0; j<numCols_; j++) {
939 ptr = values_ + j*stride_;
940 for (i=0; i<numRows_; i++) { *ptr = A(i,j) * (*ptr); ptr++; }
943 if (flopCounter_!=0) updateFlops( numRows_*numCols_ );
947 template<
typename OrdinalType,
typename ScalarType>
955 if ((numRows_ != A_nrows) || (A_ncols != B_nrows) || (numCols_ != B_ncols))
960 this->GEMM(transa, transb, numRows_, numCols_, A_ncols, alpha, A.
values(), A.
stride(), B.
values(), B.
stride(), beta, values_, stride_);
963 if (flopCounter_!=0) {
964 double nflops = 2 * numRows_;
972 template<
typename OrdinalType,
typename ScalarType>
980 if ((numRows_ != A_nrows) || (A_ncols != B_nrows) || (numCols_ != B_ncols)) {
984 if ((numRows_ != B_nrows) || (B_ncols != A_nrows) || (numCols_ != A_ncols)) {
991 this->SYMM(sideA, uplo, numRows_, numCols_, alpha, A.
values(), A.
stride(), B.
values(), B.
stride(), beta, values_, stride_);
994 if (flopCounter_!=0) {
995 double nflops = 2 * numRows_;
1003 template<
typename OrdinalType,
typename ScalarType>
1008 os <<
"Values_copied : yes" << std::endl;
1010 os <<
"Values_copied : no" << std::endl;
1011 os <<
"Rows : " << numRows_ << std::endl;
1012 os <<
"Columns : " << numCols_ << std::endl;
1013 os <<
"LDA : " << stride_ << std::endl;
1014 if(numRows_ == 0 || numCols_ == 0) {
1015 os <<
"(matrix is empty, no values to display)" << std::endl;
1017 for(OrdinalType i = 0; i < numRows_; i++) {
1018 for(OrdinalType j = 0; j < numCols_; j++){
1019 os << (*this)(i,j) <<
" ";
1030 template<
typename OrdinalType,
typename ScalarType>
1033 "SerialDenseMatrix<T>::checkIndex: "
1034 "Row index " << rowIndex <<
" out of range [0, "<< numRows_ <<
")");
1036 "SerialDenseMatrix<T>::checkIndex: "
1037 "Col index " << colIndex <<
" out of range [0, "<< numCols_ <<
")");
1040 template<
typename OrdinalType,
typename ScalarType>
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,
1055 OrdinalType startRow, OrdinalType startCol, ScalarType alpha
1059 ScalarType* ptr1 = 0;
1060 ScalarType* ptr2 = 0;
1061 for(j = 0; j < numCols_in; j++) {
1062 ptr1 = outputMatrix + (j * strideOutput);
1063 ptr2 = inputMatrix + (j + startCol) * strideInput + startRow;
1065 for(i = 0; i < numRows_in; i++)
1067 *ptr1++ += alpha*(*ptr2++);
1070 for(i = 0; i < numRows_in; i++)
1078 #ifndef TEUCHOS_HIDE_DEPRECATED_CODE
1079 template<
typename OrdinalType,
typename ScalarType>
1081 std::ostream& operator<< (std::ostream& os, const Teuchos::SerialDenseMatrix<OrdinalType, ScalarType>& obj)
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
ScalarType * values() const
Data array access method.
bool upper() const
Returns true if upper triangular part of this matrix has and will be used.
void checkIndex(OrdinalType rowIndex, OrdinalType colIndex=0) const
bool operator==(const SerialDenseMatrix< OrdinalType, ScalarType > &Operand) const
Equality of two matrices.
int shapeUninitialized(OrdinalType numRows, OrdinalType numCols)
Same as shape() except leaves uninitialized.
virtual void print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream << operator.
Templated interface class to BLAS routines.
SerialDenseMatrix< OrdinalType, ScalarType > & operator-=(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Subtract another matrix from this matrix.
SerialDenseMatrix< OrdinalType, ScalarType > & operator*=(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
void swap(SerialDenseMatrix< OrdinalType, ScalarType > &B)
Swap values between this matrix and incoming matrix.
ScalarType * values() const
Returns the pointer to the ScalarType data array contained in the object.
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
Multiply A * B and add them to this; this = beta * this + alpha*A*B.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
This class creates and provides basic support for symmetric, positive-definite dense matrices of temp...
int scale(const ScalarType alpha)
Scale this matrix by alpha; *this = alpha**this.
OrdinalType numRows() const
Returns the row dimension of this matrix.
Object for storing data and providing functionality that is common to all computational classes...
virtual ~SerialDenseMatrix()
Destructor.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
This structure defines some basic traits for a scalar field type.
SerialDenseMatrix< OrdinalType, ScalarType > & operator+=(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Add another matrix to this matrix.
#define TEUCHOS_CHK_ERR(a)
SerialDenseMatrix< OrdinalType, ScalarType > & operator=(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
Functionality and data that is common to all computational classes.
static T conjugate(T a)
Returns the conjugate of the scalar type a.
bool empty() const
Returns whether this matrix is empty.
ScalarType scalarType
Typedef for scalar type.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Set all values in the matrix to a constant value.
#define TEUCHOS_MAX(x, y)
SerialDenseMatrix()
Default Constructor.
bool operator!=(const SerialDenseMatrix< OrdinalType, ScalarType > &Operand) const
Inequality of two matrices.
TEUCHOSNUMERICS_LIB_DLL_EXPORT const char ESideChar[]
ScalarType & operator()(OrdinalType rowIndex, OrdinalType colIndex)
Element access method (non-const).
void copyMat(ScalarType *inputMatrix, OrdinalType strideInput, OrdinalType numRows, OrdinalType numCols, ScalarType *outputMatrix, OrdinalType strideOutput, OrdinalType startRow, OrdinalType startCol, ScalarType alpha=ScalarTraits< ScalarType >::zero())
Templated serial, dense, symmetric matrix class.
OrdinalType ordinalType
Typedef for ordinal type.
ScalarType * operator[](OrdinalType colIndex)
Column access method (non-const).
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
OrdinalType numCols() const
Returns the column dimension of this matrix.
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
int random()
Set all values in the matrix to be random numbers.
int reshape(OrdinalType numRows, OrdinalType numCols)
Reshaping method for changing the size of a SerialDenseMatrix, keeping the entries.
Defines basic traits for the scalar field type.
static T zero()
Returns representation of zero for this scalar type.
TEUCHOSNUMERICS_LIB_DLL_EXPORT const char ETranspChar[]
static T random()
Returns a random number (between -one() and +one()) of this scalar type.
OrdinalType stride() const
Returns the stride between the columns of this matrix in memory.
int shape(OrdinalType numRows, OrdinalType numCols)
Shape method for changing the size of a SerialDenseMatrix, initializing entries to zero...
OrdinalType numCols() const
Returns the column dimension of this matrix.
#define TEUCHOS_CHK_REF(a)
#define TEUCHOS_MIN(x, y)
SerialDenseMatrix< OrdinalType, ScalarType > & assign(const SerialDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
Teuchos::DataAccess Mode enumerable type.
OrdinalType stride() const
Returns the stride between the columns of this matrix in memory.
OrdinalType numRows() const
Returns the row dimension of this matrix.
This class creates and provides basic support for dense rectangular matrix of templated type...