43 #ifndef _TEUCHOS_SERIALSYMDENSEMATRIX_HPP_
44 #define _TEUCHOS_SERIALSYMDENSEMATRIX_HPP_
122 template<
typename OrdinalType,
typename ScalarType>
204 int shape(OrdinalType numRowsCols);
229 int reshape(OrdinalType numRowsCols);
300 ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex);
310 const ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex)
const;
404 virtual void print(std::ostream& os)
const;
412 void scale(
const ScalarType alpha );
415 void copyMat(
bool inputUpper, ScalarType* inputMatrix, OrdinalType inputStride,
416 OrdinalType numRowCols,
bool outputUpper, ScalarType* outputMatrix,
417 OrdinalType outputStride, OrdinalType startRowCol,
421 void copyUPLOMat(
bool inputUpper, ScalarType* inputMatrix,
422 OrdinalType inputStride, OrdinalType inputRows);
425 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
440 template<
typename OrdinalType,
typename ScalarType>
443 numRowCols_(0), stride_(0), valuesCopied_(false), values_(0), upper_(false), UPLO_(
'L')
446 template<
typename OrdinalType,
typename ScalarType>
449 numRowCols_(numRowCols_in), stride_(numRowCols_in), valuesCopied_(false), upper_(false), UPLO_(
'L')
457 template<
typename OrdinalType,
typename ScalarType>
459 DataAccess CV,
bool upper_in, ScalarType* values_in, OrdinalType stride_in, OrdinalType numRowCols_in
462 numRowCols_(numRowCols_in), stride_(stride_in), valuesCopied_(false),
463 values_(values_in), upper_(upper_in)
479 template<
typename OrdinalType,
typename ScalarType>
482 numRowCols_(Source.numRowCols_), stride_(0), valuesCopied_(true),
483 values_(0), upper_(Source.upper_), UPLO_(Source.UPLO_)
496 values_ =
new ScalarType[newsize];
506 template<
typename OrdinalType,
typename ScalarType>
509 ScalarType> &Source, OrdinalType numRowCols_in, OrdinalType startRowCol )
511 numRowCols_(numRowCols_in), stride_(Source.stride_), valuesCopied_(false), upper_(Source.upper_), UPLO_(Source.UPLO_)
526 template<
typename OrdinalType,
typename ScalarType>
536 template<
typename OrdinalType,
typename ScalarType>
540 numRowCols_ = numRowCols_in;
541 stride_ = numRowCols_;
542 values_ =
new ScalarType[stride_*numRowCols_];
544 valuesCopied_ =
true;
548 template<
typename OrdinalType,
typename ScalarType>
552 numRowCols_ = numRowCols_in;
553 stride_ = numRowCols_;
554 values_ =
new ScalarType[stride_*numRowCols_];
555 valuesCopied_ =
true;
559 template<
typename OrdinalType,
typename ScalarType>
563 ScalarType* values_tmp =
new ScalarType[numRowCols_in * numRowCols_in];
565 for(OrdinalType k = 0; k < numRowCols_in * numRowCols_in; k++)
567 values_tmp[k] = zero;
569 OrdinalType numRowCols_tmp =
TEUCHOS_MIN(numRowCols_, numRowCols_in);
572 copyMat(upper_, values_, stride_, numRowCols_tmp, upper_, values_tmp, numRowCols_in, 0);
575 numRowCols_ = numRowCols_in;
576 stride_ = numRowCols_;
577 values_ = values_tmp;
578 valuesCopied_ =
true;
586 template<
typename OrdinalType,
typename ScalarType>
590 if (upper_ !=
false) {
591 copyUPLOMat(
true, values_, stride_, numRowCols_ );
597 template<
typename OrdinalType,
typename ScalarType>
601 if (upper_ ==
false) {
602 copyUPLOMat(
false, values_, stride_, numRowCols_ );
608 template<
typename OrdinalType,
typename ScalarType>
612 if (fullMatrix ==
true) {
613 for(OrdinalType j = 0; j < numRowCols_; j++)
615 for(OrdinalType i = 0; i < numRowCols_; i++)
617 values_[i + j*stride_] = value_in;
624 for(OrdinalType j = 0; j < numRowCols_; j++) {
625 for(OrdinalType i = 0; i <= j; i++) {
626 values_[i + j*stride_] = value_in;
631 for(OrdinalType j = 0; j < numRowCols_; j++) {
632 for(OrdinalType i = j; i < numRowCols_; i++) {
633 values_[i + j*stride_] = value_in;
641 template<
typename OrdinalType,
typename ScalarType>
void
645 std::swap(values_ , B.
values_);
649 std::swap(upper_, B.
upper_);
650 std::swap(UPLO_, B.
UPLO_);
653 template<
typename OrdinalType,
typename ScalarType>
661 for(OrdinalType j = 0; j < numRowCols_; j++) {
662 for(OrdinalType i = 0; i < j; i++) {
670 for(OrdinalType j = 0; j < numRowCols_; j++) {
671 for(OrdinalType i = j+1; i < numRowCols_; i++) {
680 for(OrdinalType i = 0; i < numRowCols_; i++) {
681 values_[i + i*stride_] = diagSum[i] + bias;
686 template<
typename OrdinalType,
typename ScalarType>
707 UPLO_ = Source.
UPLO_;
715 UPLO_ = Source.
UPLO_;
716 const OrdinalType newsize = stride_ * numRowCols_;
718 values_ =
new ScalarType[newsize];
719 valuesCopied_ =
true;
730 UPLO_ = Source.
UPLO_;
737 UPLO_ = Source.
UPLO_;
738 const OrdinalType newsize = stride_ * numRowCols_;
740 values_ =
new ScalarType[newsize];
741 valuesCopied_ =
true;
750 template<
typename OrdinalType,
typename ScalarType>
757 template<
typename OrdinalType,
typename ScalarType>
769 template<
typename OrdinalType,
typename ScalarType>
781 template<
typename OrdinalType,
typename ScalarType>
795 copyMat(Source.
upper_, Source.
values_, Source.
stride_, numRowCols_, upper_, values_, stride_, 0 );
803 template<
typename OrdinalType,
typename ScalarType>
806 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
807 checkIndex( rowIndex, colIndex );
809 if ( rowIndex <= colIndex ) {
812 return(values_[colIndex * stride_ + rowIndex]);
814 return(values_[rowIndex * stride_ + colIndex]);
819 return(values_[rowIndex * stride_ + colIndex]);
821 return(values_[colIndex * stride_ + rowIndex]);
825 template<
typename OrdinalType,
typename ScalarType>
828 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
829 checkIndex( rowIndex, colIndex );
831 if ( rowIndex <= colIndex ) {
834 return(values_[colIndex * stride_ + rowIndex]);
836 return(values_[rowIndex * stride_ + colIndex]);
841 return(values_[rowIndex * stride_ + colIndex]);
843 return(values_[colIndex * stride_ + rowIndex]);
851 template<
typename OrdinalType,
typename ScalarType>
857 template<
typename OrdinalType,
typename ScalarType>
868 for (j=0; j<numRowCols_; j++) {
870 ptr = values_ + j*stride_;
871 for (i=0; i<j; i++) {
874 ptr = values_ + j + j*stride_;
875 for (i=j; i<numRowCols_; i++) {
883 for (j=0; j<numRowCols_; j++) {
885 ptr = values_ + j + j*stride_;
886 for (i=j; i<numRowCols_; i++) {
890 for (i=0; i<j; i++) {
900 template<
typename OrdinalType,
typename ScalarType>
910 for (j = 0; j < numRowCols_; j++) {
911 for (i = 0; i < j; i++) {
918 for (j = 0; j < numRowCols_; j++) {
920 for (i = j+1; i < numRowCols_; i++) {
933 template<
typename OrdinalType,
typename ScalarType>
942 for(i = 0; i < numRowCols_; i++) {
943 for(j = 0; j < numRowCols_; j++) {
944 if((*
this)(i, j) != Operand(i, j)) {
953 template<
typename OrdinalType,
typename ScalarType>
956 return !((*this) == Operand);
963 template<
typename OrdinalType,
typename ScalarType>
970 for (j=0; j<numRowCols_; j++) {
971 ptr = values_ + j*stride_;
972 for (i=0; i<= j; i++) { *ptr = alpha * (*ptr); ptr++; }
976 for (j=0; j<numRowCols_; j++) {
977 ptr = values_ + j*stride_ + j;
978 for (i=j; i<numRowCols_; i++) { *ptr = alpha * (*ptr); ptr++; }
1012 template<
typename OrdinalType,
typename ScalarType>
1017 os <<
"Values_copied : yes" << std::endl;
1019 os <<
"Values_copied : no" << std::endl;
1020 os <<
"Rows / Columns : " << numRowCols_ << std::endl;
1021 os <<
"LDA : " << stride_ << std::endl;
1023 os <<
"Storage: Upper" << std::endl;
1025 os <<
"Storage: Lower" << std::endl;
1026 if(numRowCols_ == 0) {
1027 os <<
"(matrix is empty, no values to display)" << std::endl;
1029 for(OrdinalType i = 0; i < numRowCols_; i++) {
1030 for(OrdinalType j = 0; j < numRowCols_; j++){
1031 os << (*this)(i,j) <<
" ";
1042 template<
typename OrdinalType,
typename ScalarType>
1045 "SerialSymDenseMatrix<T>::checkIndex: "
1046 "Row index " << rowIndex <<
" out of range [0, "<< numRowCols_ <<
")");
1048 "SerialSymDenseMatrix<T>::checkIndex: "
1049 "Col index " << colIndex <<
" out of range [0, "<< numRowCols_ <<
")");
1052 template<
typename OrdinalType,
typename ScalarType>
1059 valuesCopied_ =
false;
1063 template<
typename OrdinalType,
typename ScalarType>
1065 bool inputUpper, ScalarType* inputMatrix,
1066 OrdinalType inputStride, OrdinalType numRowCols_in,
1067 bool outputUpper, ScalarType* outputMatrix,
1068 OrdinalType outputStride, OrdinalType startRowCol,
1073 ScalarType* ptr1 = 0;
1074 ScalarType* ptr2 = 0;
1076 for (j = 0; j < numRowCols_in; j++) {
1077 if (inputUpper ==
true) {
1079 ptr2 = inputMatrix + (j + startRowCol) * inputStride + startRowCol;
1080 if (outputUpper ==
true) {
1082 ptr1 = outputMatrix + j*outputStride;
1084 for(i = 0; i <= j; i++) {
1085 *ptr1++ += alpha*(*ptr2++);
1088 for(i = 0; i <= j; i++) {
1096 ptr1 = outputMatrix + j;
1098 for(i = 0; i <= j; i++) {
1099 *ptr1 += alpha*(*ptr2++);
1100 ptr1 += outputStride;
1103 for(i = 0; i <= j; i++) {
1105 ptr1 += outputStride;
1112 ptr2 = inputMatrix + (startRowCol+j) * inputStride + startRowCol + j;
1113 if (outputUpper ==
true) {
1116 ptr1 = outputMatrix + j*outputStride + j;
1118 for(i = j; i < numRowCols_in; i++) {
1119 *ptr1 += alpha*(*ptr2++);
1120 ptr1 += outputStride;
1123 for(i = j; i < numRowCols_in; i++) {
1125 ptr1 += outputStride;
1131 ptr1 = outputMatrix + j*outputStride + j;
1133 for(i = j; i < numRowCols_in; i++) {
1134 *ptr1++ += alpha*(*ptr2++);
1137 for(i = j; i < numRowCols_in; i++) {
1146 template<
typename OrdinalType,
typename ScalarType>
1148 bool inputUpper, ScalarType* inputMatrix,
1149 OrdinalType inputStride, OrdinalType inputRows
1153 ScalarType * ptr1 = 0;
1154 ScalarType * ptr2 = 0;
1157 for (j=1; j<inputRows; j++) {
1158 ptr1 = inputMatrix + j;
1159 ptr2 = inputMatrix + j*inputStride;
1160 for (i=0; i<j; i++) {
1167 for (i=1; i<inputRows; i++) {
1168 ptr1 = inputMatrix + i;
1169 ptr2 = inputMatrix + i*inputStride;
1170 for (j=0; j<i; j++) {
1178 #ifndef TEUCHOS_HIDE_DEPRECATED_CODE
1179 template<
typename OrdinalType,
typename ScalarType>
1181 std::ostream& operator<< (std::ostream& os, const Teuchos::SerialSymDenseMatrix<OrdinalType, ScalarType>& obj)
bool upper() const
Returns true if upper triangular part of this matrix has and will be used.
void copyUPLOMat(bool inputUpper, ScalarType *inputMatrix, OrdinalType inputStride, OrdinalType inputRows)
SerialSymDenseMatrix()
Default constructor; defines a zero size object.
virtual void print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream << operator.
Templated interface class to BLAS routines.
ScalarType * values() const
Returns the pointer to the ScalarType data array contained in the object.
ScalarType & operator()(OrdinalType rowIndex, OrdinalType colIndex)
Element access method (non-const).
void swap(SerialSymDenseMatrix< OrdinalType, ScalarType > &B)
Swap values between this matrix and incoming matrix.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
int shape(OrdinalType numRowsCols)
Set dimensions of a Teuchos::SerialSymDenseMatrix object; init values to zero.
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...
OrdinalType numRows() const
Returns the row dimension of this matrix.
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
Object for storing data and providing functionality that is common to all computational classes...
int reshape(OrdinalType numRowsCols)
Reshape a Teuchos::SerialSymDenseMatrix object.
This structure defines some basic traits for a scalar field type.
void setLower()
Specify that the lower triangle of the this matrix should be used.
void setUpper()
Specify that the upper triangle of the this matrix should be used.
Functionality and data that is common to all computational classes.
void checkIndex(OrdinalType rowIndex, OrdinalType colIndex=0) const
SerialSymDenseMatrix< OrdinalType, ScalarType > & operator*=(const ScalarType alpha)
Inplace scalar-matrix product A = alpha*A.
bool operator==(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Operand) const
Equality of two matrices.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero(), bool fullMatrix=false)
Set all values in the matrix to a constant value.
SerialSymDenseMatrix< OrdinalType, ScalarType > & operator+=(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source)
Add another matrix to this matrix.
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
#define TEUCHOS_MAX(x, y)
int random(const ScalarType bias=0.1 *Teuchos::ScalarTraits< ScalarType >::one())
Set all values in the active area (upper/lower triangle) of this matrix to be random numbers...
char UPLO() const
Returns character value of UPLO used by LAPACK routines.
virtual ~SerialSymDenseMatrix()
Teuchos::SerialSymDenseMatrix destructor.
void scale(const ScalarType alpha)
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
SerialSymDenseMatrix< OrdinalType, ScalarType > & operator-=(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source)
Subtract another matrix from this matrix.
OrdinalType ordinalType
Typedef for ordinal type.
SerialSymDenseMatrix< OrdinalType, ScalarType > & operator=(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
int shapeUninitialized(OrdinalType numRowsCols)
Set dimensions of a Teuchos::SerialSymDenseMatrix object; don't initialize values.
Defines basic traits for the scalar field type.
static T zero()
Returns representation of zero for this scalar type.
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.
OrdinalType numCols() const
Returns the column dimension of this matrix.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
#define TEUCHOS_CHK_REF(a)
SerialSymDenseMatrix< OrdinalType, ScalarType > & assign(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
bool operator!=(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Operand) const
Inequality of two matrices.
#define TEUCHOS_MIN(x, y)
Teuchos::DataAccess Mode enumerable type.
bool empty() const
Returns whether this matrix is empty.
void copyMat(bool inputUpper, ScalarType *inputMatrix, OrdinalType inputStride, OrdinalType numRowCols, bool outputUpper, ScalarType *outputMatrix, OrdinalType outputStride, OrdinalType startRowCol, ScalarType alpha=ScalarTraits< ScalarType >::zero())
ScalarType scalarType
Typedef for scalar type.