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 #ifndef TEUCHOS_HIDE_DEPRECATED_CODE
406 virtual void print(std::ostream& os)
const;
408 virtual std::ostream&
print(std::ostream& os)
const;
416 void scale(
const ScalarType alpha );
419 void copyMat(
bool inputUpper, ScalarType* inputMatrix, OrdinalType inputStride,
420 OrdinalType numRowCols,
bool outputUpper, ScalarType* outputMatrix,
421 OrdinalType outputStride, OrdinalType startRowCol,
425 void copyUPLOMat(
bool inputUpper, ScalarType* inputMatrix,
426 OrdinalType inputStride, OrdinalType inputRows);
429 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
444 template<
typename OrdinalType,
typename ScalarType>
447 numRowCols_(0), stride_(0), valuesCopied_(false), values_(0), upper_(false), UPLO_(
'L')
450 template<
typename OrdinalType,
typename ScalarType>
453 numRowCols_(numRowCols_in), stride_(numRowCols_in), valuesCopied_(false), upper_(false), UPLO_(
'L')
461 template<
typename OrdinalType,
typename ScalarType>
463 DataAccess CV,
bool upper_in, ScalarType* values_in, OrdinalType stride_in, OrdinalType numRowCols_in
466 numRowCols_(numRowCols_in), stride_(stride_in), valuesCopied_(false),
467 values_(values_in), upper_(upper_in)
483 template<
typename OrdinalType,
typename ScalarType>
486 numRowCols_(Source.numRowCols_), stride_(0), valuesCopied_(true),
487 values_(0), upper_(Source.upper_), UPLO_(Source.UPLO_)
500 values_ =
new ScalarType[newsize];
510 template<
typename OrdinalType,
typename ScalarType>
513 ScalarType> &Source, OrdinalType numRowCols_in, OrdinalType startRowCol )
515 numRowCols_(numRowCols_in), stride_(Source.stride_), valuesCopied_(false), upper_(Source.upper_), UPLO_(Source.UPLO_)
530 template<
typename OrdinalType,
typename ScalarType>
540 template<
typename OrdinalType,
typename ScalarType>
544 numRowCols_ = numRowCols_in;
545 stride_ = numRowCols_;
546 values_ =
new ScalarType[stride_*numRowCols_];
548 valuesCopied_ =
true;
552 template<
typename OrdinalType,
typename ScalarType>
556 numRowCols_ = numRowCols_in;
557 stride_ = numRowCols_;
558 values_ =
new ScalarType[stride_*numRowCols_];
559 valuesCopied_ =
true;
563 template<
typename OrdinalType,
typename ScalarType>
567 ScalarType* values_tmp =
new ScalarType[numRowCols_in * numRowCols_in];
569 for(OrdinalType k = 0; k < numRowCols_in * numRowCols_in; k++)
571 values_tmp[k] = zero;
573 OrdinalType numRowCols_tmp =
TEUCHOS_MIN(numRowCols_, numRowCols_in);
576 copyMat(upper_, values_, stride_, numRowCols_tmp, upper_, values_tmp, numRowCols_in, 0);
579 numRowCols_ = numRowCols_in;
580 stride_ = numRowCols_;
581 values_ = values_tmp;
582 valuesCopied_ =
true;
590 template<
typename OrdinalType,
typename ScalarType>
594 if (upper_ !=
false) {
595 copyUPLOMat(
true, values_, stride_, numRowCols_ );
601 template<
typename OrdinalType,
typename ScalarType>
605 if (upper_ ==
false) {
606 copyUPLOMat(
false, values_, stride_, numRowCols_ );
612 template<
typename OrdinalType,
typename ScalarType>
616 if (fullMatrix ==
true) {
617 for(OrdinalType j = 0; j < numRowCols_; j++)
619 for(OrdinalType i = 0; i < numRowCols_; i++)
621 values_[i + j*stride_] = value_in;
628 for(OrdinalType j = 0; j < numRowCols_; j++) {
629 for(OrdinalType i = 0; i <= j; i++) {
630 values_[i + j*stride_] = value_in;
635 for(OrdinalType j = 0; j < numRowCols_; j++) {
636 for(OrdinalType i = j; i < numRowCols_; i++) {
637 values_[i + j*stride_] = value_in;
645 template<
typename OrdinalType,
typename ScalarType>
void
649 std::swap(values_ , B.
values_);
653 std::swap(upper_, B.
upper_);
654 std::swap(UPLO_, B.
UPLO_);
657 template<
typename OrdinalType,
typename ScalarType>
665 for(OrdinalType j = 0; j < numRowCols_; j++) {
666 for(OrdinalType i = 0; i < j; i++) {
674 for(OrdinalType j = 0; j < numRowCols_; j++) {
675 for(OrdinalType i = j+1; i < numRowCols_; i++) {
684 for(OrdinalType i = 0; i < numRowCols_; i++) {
685 values_[i + i*stride_] = diagSum[i] + bias;
690 template<
typename OrdinalType,
typename ScalarType>
711 UPLO_ = Source.
UPLO_;
719 UPLO_ = Source.
UPLO_;
720 const OrdinalType newsize = stride_ * numRowCols_;
722 values_ =
new ScalarType[newsize];
723 valuesCopied_ =
true;
734 UPLO_ = Source.
UPLO_;
741 UPLO_ = Source.
UPLO_;
742 const OrdinalType newsize = stride_ * numRowCols_;
744 values_ =
new ScalarType[newsize];
745 valuesCopied_ =
true;
754 template<
typename OrdinalType,
typename ScalarType>
761 template<
typename OrdinalType,
typename ScalarType>
773 template<
typename OrdinalType,
typename ScalarType>
785 template<
typename OrdinalType,
typename ScalarType>
799 copyMat(Source.
upper_, Source.
values_, Source.
stride_, numRowCols_, upper_, values_, stride_, 0 );
807 template<
typename OrdinalType,
typename ScalarType>
810 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
811 checkIndex( rowIndex, colIndex );
813 if ( rowIndex <= colIndex ) {
816 return(values_[colIndex * stride_ + rowIndex]);
818 return(values_[rowIndex * stride_ + colIndex]);
823 return(values_[rowIndex * stride_ + colIndex]);
825 return(values_[colIndex * stride_ + rowIndex]);
829 template<
typename OrdinalType,
typename ScalarType>
832 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
833 checkIndex( rowIndex, colIndex );
835 if ( rowIndex <= colIndex ) {
838 return(values_[colIndex * stride_ + rowIndex]);
840 return(values_[rowIndex * stride_ + colIndex]);
845 return(values_[rowIndex * stride_ + colIndex]);
847 return(values_[colIndex * stride_ + rowIndex]);
855 template<
typename OrdinalType,
typename ScalarType>
861 template<
typename OrdinalType,
typename ScalarType>
872 for (j=0; j<numRowCols_; j++) {
874 ptr = values_ + j*stride_;
875 for (i=0; i<j; i++) {
878 ptr = values_ + j + j*stride_;
879 for (i=j; i<numRowCols_; i++) {
887 for (j=0; j<numRowCols_; j++) {
889 ptr = values_ + j + j*stride_;
890 for (i=j; i<numRowCols_; i++) {
894 for (i=0; i<j; i++) {
904 template<
typename OrdinalType,
typename ScalarType>
914 for (j = 0; j < numRowCols_; j++) {
915 for (i = 0; i < j; i++) {
922 for (j = 0; j < numRowCols_; j++) {
924 for (i = j+1; i < numRowCols_; i++) {
937 template<
typename OrdinalType,
typename ScalarType>
946 for(i = 0; i < numRowCols_; i++) {
947 for(j = 0; j < numRowCols_; j++) {
948 if((*
this)(i, j) != Operand(i, j)) {
957 template<
typename OrdinalType,
typename ScalarType>
960 return !((*this) == Operand);
967 template<
typename OrdinalType,
typename ScalarType>
974 for (j=0; j<numRowCols_; j++) {
975 ptr = values_ + j*stride_;
976 for (i=0; i<= j; i++) { *ptr = alpha * (*ptr); ptr++; }
980 for (j=0; j<numRowCols_; j++) {
981 ptr = values_ + j*stride_ + j;
982 for (i=j; i<numRowCols_; i++) { *ptr = alpha * (*ptr); ptr++; }
1016 template<
typename OrdinalType,
typename ScalarType>
1017 #ifndef TEUCHOS_HIDE_DEPRECATED_CODE
1025 os <<
"Values_copied : yes" << std::endl;
1027 os <<
"Values_copied : no" << std::endl;
1028 os <<
"Rows / Columns : " << numRowCols_ << std::endl;
1029 os <<
"LDA : " << stride_ << std::endl;
1031 os <<
"Storage: Upper" << std::endl;
1033 os <<
"Storage: Lower" << std::endl;
1034 if(numRowCols_ == 0) {
1035 os <<
"(matrix is empty, no values to display)" << std::endl;
1037 for(OrdinalType i = 0; i < numRowCols_; i++) {
1038 for(OrdinalType j = 0; j < numRowCols_; j++){
1039 os << (*this)(i,j) <<
" ";
1044 #ifdef TEUCHOS_HIDE_DEPRECATED_CODE
1053 template<
typename OrdinalType,
typename ScalarType>
1056 "SerialSymDenseMatrix<T>::checkIndex: "
1057 "Row index " << rowIndex <<
" out of range [0, "<< numRowCols_ <<
")");
1059 "SerialSymDenseMatrix<T>::checkIndex: "
1060 "Col index " << colIndex <<
" out of range [0, "<< numRowCols_ <<
")");
1063 template<
typename OrdinalType,
typename ScalarType>
1070 valuesCopied_ =
false;
1074 template<
typename OrdinalType,
typename ScalarType>
1076 bool inputUpper, ScalarType* inputMatrix,
1077 OrdinalType inputStride, OrdinalType numRowCols_in,
1078 bool outputUpper, ScalarType* outputMatrix,
1079 OrdinalType outputStride, OrdinalType startRowCol,
1084 ScalarType* ptr1 = 0;
1085 ScalarType* ptr2 = 0;
1087 for (j = 0; j < numRowCols_in; j++) {
1088 if (inputUpper ==
true) {
1090 ptr2 = inputMatrix + (j + startRowCol) * inputStride + startRowCol;
1091 if (outputUpper ==
true) {
1093 ptr1 = outputMatrix + j*outputStride;
1095 for(i = 0; i <= j; i++) {
1096 *ptr1++ += alpha*(*ptr2++);
1099 for(i = 0; i <= j; i++) {
1107 ptr1 = outputMatrix + j;
1109 for(i = 0; i <= j; i++) {
1110 *ptr1 += alpha*(*ptr2++);
1111 ptr1 += outputStride;
1114 for(i = 0; i <= j; i++) {
1116 ptr1 += outputStride;
1123 ptr2 = inputMatrix + (startRowCol+j) * inputStride + startRowCol + j;
1124 if (outputUpper ==
true) {
1127 ptr1 = outputMatrix + j*outputStride + j;
1129 for(i = j; i < numRowCols_in; i++) {
1130 *ptr1 += alpha*(*ptr2++);
1131 ptr1 += outputStride;
1134 for(i = j; i < numRowCols_in; i++) {
1136 ptr1 += outputStride;
1142 ptr1 = outputMatrix + j*outputStride + j;
1144 for(i = j; i < numRowCols_in; i++) {
1145 *ptr1++ += alpha*(*ptr2++);
1148 for(i = j; i < numRowCols_in; i++) {
1157 template<
typename OrdinalType,
typename ScalarType>
1159 bool inputUpper, ScalarType* inputMatrix,
1160 OrdinalType inputStride, OrdinalType inputRows
1164 ScalarType * ptr1 = 0;
1165 ScalarType * ptr2 = 0;
1168 for (j=1; j<inputRows; j++) {
1169 ptr1 = inputMatrix + j;
1170 ptr2 = inputMatrix + j*inputStride;
1171 for (i=0; i<j; i++) {
1178 for (i=1; i<inputRows; i++) {
1179 ptr1 = inputMatrix + i;
1180 ptr2 = inputMatrix + i*inputStride;
1181 for (j=0; j<i; j++) {
1189 #ifndef TEUCHOS_HIDE_DEPRECATED_CODE
1190 template<
typename OrdinalType,
typename ScalarType>
1192 std::ostream& operator<< (std::ostream& os, const Teuchos::SerialSymDenseMatrix<OrdinalType, ScalarType>& obj)
1200 template<
typename OrdinalType,
typename ScalarType>
1210 template<
typename OrdinalType,
typename ScalarType>
1215 printer.
obj.print(out);
1220 template<
typename OrdinalType,
typename ScalarType>
1221 SerialSymDenseMatrixPrinter<OrdinalType,ScalarType>
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)
Ostream manipulator for SerialSymDenseMatrix.
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.
SerialSymDenseMatrixPrinter(const SerialSymDenseMatrix< OrdinalType, ScalarType > &obj_in)
SerialBandDenseMatrixPrinter< OrdinalType, ScalarType > printMat(const SerialBandDenseMatrix< OrdinalType, ScalarType > &obj)
Return SerialBandDenseMatrix ostream manipulator Use as:
ScalarType * values() const
Returns the pointer to the ScalarType data array contained in the object.
const SerialSymDenseMatrix< OrdinalType, ScalarType > & obj
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
std::ostream & operator<<(std::ostream &os, BigUInt< n > a)
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.