61 #ifndef _TEUCHOS_SERIALDENSEMATRIX_HPP_ 62 #define _TEUCHOS_SERIALDENSEMATRIX_HPP_ 85 template<
typename OrdinalType,
typename ScalarType>
236 ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex);
246 const ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex)
const;
266 const ScalarType*
operator [] (OrdinalType colIndex)
const;
300 int scale (
const ScalarType alpha );
392 virtual void print(std::ostream& os)
const;
397 void copyMat(ScalarType* inputMatrix, OrdinalType strideInput,
398 OrdinalType
numRows, OrdinalType
numCols, ScalarType* outputMatrix,
399 OrdinalType strideOutput, OrdinalType startRow, OrdinalType startCol,
402 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
415 template<
typename OrdinalType,
typename ScalarType>
420 template<
typename OrdinalType,
typename ScalarType>
422 OrdinalType numRows_in, OrdinalType numCols_in,
bool zeroOut
432 template<
typename OrdinalType,
typename ScalarType>
434 DataAccess CV, ScalarType* values_in, OrdinalType stride_in, OrdinalType numRows_in,
435 OrdinalType numCols_in
449 template<
typename OrdinalType,
typename ScalarType>
450 SerialDenseMatrix<OrdinalType, ScalarType>::SerialDenseMatrix(
const SerialDenseMatrix<OrdinalType, ScalarType> &Source,
ETransp trans) :
CompObject(),
Object(
"Teuchos::SerialDenseMatrix"),
BLAS<OrdinalType,ScalarType>(),
numRows_(0),
numCols_(0),
stride_(0),
valuesCopied_(true),
values_(0)
466 for (OrdinalType j=0; j<
numCols_; j++) {
467 for (OrdinalType i=0; i<
numRows_; i++) {
478 for (OrdinalType j=0; j<
numCols_; j++) {
479 for (OrdinalType i=0; i<
numRows_; i++) {
486 template<
typename OrdinalType,
typename ScalarType>
489 OrdinalType numRows_in, OrdinalType numCols_in, OrdinalType startRow,
508 template<
typename OrdinalType,
typename ScalarType>
518 template<
typename OrdinalType,
typename ScalarType>
520 OrdinalType numRows_in, OrdinalType numCols_in
533 template<
typename OrdinalType,
typename ScalarType>
535 OrdinalType numRows_in, OrdinalType numCols_in
547 template<
typename OrdinalType,
typename ScalarType>
549 OrdinalType numRows_in, OrdinalType numCols_in
553 ScalarType* values_tmp =
new ScalarType[numRows_in * numCols_in];
555 for(OrdinalType k = 0; k < numRows_in * numCols_in; k++)
557 values_tmp[k] = zero;
579 template<
typename OrdinalType,
typename ScalarType>
583 for(OrdinalType j = 0; j <
numCols_; j++)
585 for(OrdinalType i = 0; i <
numRows_; i++)
593 template<
typename OrdinalType,
typename ScalarType>
597 for(OrdinalType j = 0; j <
numCols_; j++)
599 for(OrdinalType i = 0; i <
numRows_; i++)
607 template<
typename OrdinalType,
typename ScalarType>
637 values_ =
new ScalarType[newsize];
657 values_ =
new ScalarType[newsize];
667 template<
typename OrdinalType,
typename ScalarType>
679 template<
typename OrdinalType,
typename ScalarType>
691 template<
typename OrdinalType,
typename ScalarType>
711 template<
typename OrdinalType,
typename ScalarType>
714 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 720 template<
typename OrdinalType,
typename ScalarType>
723 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 729 template<
typename OrdinalType,
typename ScalarType>
732 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 738 template<
typename OrdinalType,
typename ScalarType>
741 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 751 template<
typename OrdinalType,
typename ScalarType>
776 template<
typename OrdinalType,
typename ScalarType>
793 template<
typename OrdinalType,
typename ScalarType>
812 template<
typename OrdinalType,
typename ScalarType>
827 if((*
this)(i, j) != Operand(i, j))
837 template<
typename OrdinalType,
typename ScalarType>
840 return !((*this) == Operand);
847 template<
typename OrdinalType,
typename ScalarType>
850 this->
scale( alpha );
854 template<
typename OrdinalType,
typename ScalarType>
862 for (i=0; i<
numRows_; i++) { *ptr = alpha * (*ptr); ptr++; }
868 template<
typename OrdinalType,
typename ScalarType>
881 for (i=0; i<
numRows_; i++) { *ptr = A(i,j) * (*ptr); ptr++; }
887 template<
typename OrdinalType,
typename ScalarType>
900 this->
GEMM(transa, transb,
numRows_,
numCols_, A_ncols, alpha, A.
values(), A.
stride(), B.
values(), B.
stride(), beta,
values_,
stride_);
908 template<
typename OrdinalType,
typename ScalarType>
916 if ((
numRows_ != A_nrows) || (A_ncols != B_nrows) || (
numCols_ != B_ncols)) {
920 if ((
numRows_ != B_nrows) || (B_ncols != A_nrows) || (
numCols_ != A_ncols)) {
927 this->
SYMM(sideA, uplo,
numRows_,
numCols_, alpha, A.
values(), A.
stride(), B.
values(), B.
stride(), beta,
values_,
stride_);
935 template<
typename OrdinalType,
typename ScalarType>
940 os <<
"Values_copied : yes" << std::endl;
942 os <<
"Values_copied : no" << std::endl;
943 os <<
"Rows : " <<
numRows_ << std::endl;
944 os <<
"Columns : " <<
numCols_ << std::endl;
945 os <<
"LDA : " <<
stride_ << std::endl;
947 os <<
"(matrix is empty, no values to display)" << std::endl;
949 for(OrdinalType i = 0; i <
numRows_; i++) {
950 for(OrdinalType j = 0; j <
numCols_; j++){
951 os << (*this)(i,j) <<
" ";
962 template<
typename OrdinalType,
typename ScalarType>
965 "SerialDenseMatrix<T>::checkIndex: " 966 "Row index " << rowIndex <<
" out of range [0, "<<
numRows_ <<
")");
968 "SerialDenseMatrix<T>::checkIndex: " 969 "Col index " << colIndex <<
" out of range [0, "<<
numCols_ <<
")");
972 template<
typename OrdinalType,
typename ScalarType>
983 template<
typename OrdinalType,
typename ScalarType>
985 ScalarType* inputMatrix, OrdinalType strideInput, OrdinalType numRows_in,
986 OrdinalType numCols_in, ScalarType* outputMatrix, OrdinalType strideOutput,
987 OrdinalType startRow, OrdinalType startCol, ScalarType alpha
991 ScalarType* ptr1 = 0;
992 ScalarType* ptr2 = 0;
993 for(j = 0; j < numCols_in; j++) {
994 ptr1 = outputMatrix + (j * strideOutput);
995 ptr2 = inputMatrix + (j + startCol) * strideInput + startRow;
997 for(i = 0; i < numRows_in; i++)
999 *ptr1++ += alpha*(*ptr2++);
1002 for(i = 0; i < numRows_in; i++)
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 inherited from the Object class...
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.
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)
void SYMM(ESide side, EUplo uplo, const OrdinalType m, const OrdinalType n, const alpha_type alpha, const A_type *A, const OrdinalType lda, const B_type *B, const OrdinalType ldb, const beta_type beta, ScalarType *C, const OrdinalType ldc) const
Performs the matrix-matrix operation: C <- alpha*A*B+beta*C or C <- alpha*B*A+beta*C where A is an m ...
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.
void GEMM(ETransp transa, ETransp transb, const OrdinalType m, const OrdinalType n, const OrdinalType k, const alpha_type alpha, const A_type *A, const OrdinalType lda, const B_type *B, const OrdinalType ldb, const beta_type beta, ScalarType *C, const OrdinalType ldc) const
General matrix-matrix multiply.
#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.
void updateFlops(int addflops) const
Increment Flop count for this object.
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...