11 #ifndef _TEUCHOS_SERIALSYMDENSEMATRIX_HPP_
12 #define _TEUCHOS_SERIALSYMDENSEMATRIX_HPP_
90 template<
typename OrdinalType,
typename ScalarType>
172 int shape(OrdinalType numRowsCols);
197 int reshape(OrdinalType numRowsCols);
268 ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex);
278 const ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex)
const;
294 char UPLO()
const {
return(UPLO_);};
372 virtual std::ostream&
print(std::ostream& os)
const;
380 void scale(
const ScalarType alpha );
383 void copyMat(
bool inputUpper, ScalarType* inputMatrix, OrdinalType inputStride,
384 OrdinalType numRowCols,
bool outputUpper, ScalarType* outputMatrix,
385 OrdinalType outputStride, OrdinalType startRowCol,
389 void copyUPLOMat(
bool inputUpper, ScalarType* inputMatrix,
390 OrdinalType inputStride, OrdinalType inputRows);
393 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
399 const size_t size = size_t(numRows) * size_t(numCols);
400 #pragma GCC diagnostic push
401 #pragma GCC diagnostic ignored "-Wvla"
402 return new ScalarType[size];
403 #pragma GCC diagnostic pop
418 template<
typename OrdinalType,
typename ScalarType>
420 : numRowCols_(numRowCols_in), stride_(numRowCols_in), valuesCopied_(false), upper_(false), UPLO_(
'L')
430 template<
typename OrdinalType,
typename ScalarType>
432 DataAccess CV,
bool upper_in, ScalarType* values_in, OrdinalType stride_in, OrdinalType numRowCols_in
434 : numRowCols_(numRowCols_in), stride_(stride_in), valuesCopied_(false),
435 values_(values_in), upper_(upper_in)
451 template<
typename OrdinalType,
typename ScalarType>
453 : numRowCols_(Source.numRowCols_), stride_(0), valuesCopied_(true),
454 values_(0), upper_(Source.upper_), UPLO_(Source.UPLO_)
477 template<
typename OrdinalType,
typename ScalarType>
480 ScalarType> &Source, OrdinalType numRowCols_in, OrdinalType startRowCol )
482 numRowCols_(numRowCols_in), stride_(Source.stride_), valuesCopied_(false), upper_(Source.upper_), UPLO_(Source.UPLO_)
497 template<
typename OrdinalType,
typename ScalarType>
507 template<
typename OrdinalType,
typename ScalarType>
511 numRowCols_ = numRowCols_in;
512 stride_ = numRowCols_;
513 values_ = allocateValues(stride_, numRowCols_);
515 valuesCopied_ =
true;
519 template<
typename OrdinalType,
typename ScalarType>
523 numRowCols_ = numRowCols_in;
524 stride_ = numRowCols_;
525 values_ = allocateValues(stride_, numRowCols_);
526 valuesCopied_ =
true;
530 template<
typename OrdinalType,
typename ScalarType>
534 ScalarType* values_tmp = allocateValues(numRowCols_in, numRowCols_in);
536 for(OrdinalType k = 0; k < numRowCols_in * numRowCols_in; k++)
538 values_tmp[k] = zero;
540 OrdinalType numRowCols_tmp =
TEUCHOS_MIN(numRowCols_, numRowCols_in);
543 copyMat(upper_, values_, stride_, numRowCols_tmp, upper_, values_tmp, numRowCols_in, 0);
546 numRowCols_ = numRowCols_in;
547 stride_ = numRowCols_;
548 values_ = values_tmp;
549 valuesCopied_ =
true;
557 template<
typename OrdinalType,
typename ScalarType>
561 if (upper_ !=
false) {
562 copyUPLOMat(
true, values_, stride_, numRowCols_ );
568 template<
typename OrdinalType,
typename ScalarType>
572 if (upper_ ==
false) {
573 copyUPLOMat(
false, values_, stride_, numRowCols_ );
579 template<
typename OrdinalType,
typename ScalarType>
583 if (fullMatrix ==
true) {
584 for(OrdinalType j = 0; j < numRowCols_; j++)
586 for(OrdinalType i = 0; i < numRowCols_; i++)
588 values_[i + j*stride_] = value_in;
595 for(OrdinalType j = 0; j < numRowCols_; j++) {
596 for(OrdinalType i = 0; i <= j; i++) {
597 values_[i + j*stride_] = value_in;
602 for(OrdinalType j = 0; j < numRowCols_; j++) {
603 for(OrdinalType i = j; i < numRowCols_; i++) {
604 values_[i + j*stride_] = value_in;
612 template<
typename OrdinalType,
typename ScalarType>
void
616 std::swap(values_ , B.
values_);
620 std::swap(upper_, B.
upper_);
621 std::swap(UPLO_, B.UPLO_);
624 template<
typename OrdinalType,
typename ScalarType>
632 for(OrdinalType j = 0; j < numRowCols_; j++) {
633 for(OrdinalType i = 0; i < j; i++) {
641 for(OrdinalType j = 0; j < numRowCols_; j++) {
642 for(OrdinalType i = j+1; i < numRowCols_; i++) {
651 for(OrdinalType i = 0; i < numRowCols_; i++) {
652 values_[i + i*stride_] = diagSum[i] + bias;
657 template<
typename OrdinalType,
typename ScalarType>
678 UPLO_ = Source.UPLO_;
686 UPLO_ = Source.UPLO_;
687 if(stride_ > 0 && numRowCols_ > 0) {
688 values_ = allocateValues(stride_, numRowCols_);
689 valuesCopied_ =
true;
700 UPLO_ = Source.UPLO_;
707 UPLO_ = Source.UPLO_;
708 if(stride_ > 0 && numRowCols_ > 0) {
709 values_ = allocateValues(stride_, numRowCols_);
710 valuesCopied_ =
true;
719 template<
typename OrdinalType,
typename ScalarType>
726 template<
typename OrdinalType,
typename ScalarType>
738 template<
typename OrdinalType,
typename ScalarType>
750 template<
typename OrdinalType,
typename ScalarType>
764 copyMat(Source.
upper_, Source.
values_, Source.
stride_, numRowCols_, upper_, values_, stride_, 0 );
772 template<
typename OrdinalType,
typename ScalarType>
775 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
776 checkIndex( rowIndex, colIndex );
778 if ( rowIndex <= colIndex ) {
781 return(values_[colIndex * stride_ + rowIndex]);
783 return(values_[rowIndex * stride_ + colIndex]);
788 return(values_[rowIndex * stride_ + colIndex]);
790 return(values_[colIndex * stride_ + rowIndex]);
794 template<
typename OrdinalType,
typename ScalarType>
797 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
798 checkIndex( rowIndex, colIndex );
800 if ( rowIndex <= colIndex ) {
803 return(values_[colIndex * stride_ + rowIndex]);
805 return(values_[rowIndex * stride_ + colIndex]);
810 return(values_[rowIndex * stride_ + colIndex]);
812 return(values_[colIndex * stride_ + rowIndex]);
820 template<
typename OrdinalType,
typename ScalarType>
826 template<
typename OrdinalType,
typename ScalarType>
837 for (j=0; j<numRowCols_; j++) {
839 ptr = values_ + j*stride_;
840 for (i=0; i<j; i++) {
843 ptr = values_ + j + j*stride_;
844 for (i=j; i<numRowCols_; i++) {
852 for (j=0; j<numRowCols_; j++) {
854 ptr = values_ + j + j*stride_;
855 for (i=j; i<numRowCols_; i++) {
859 for (i=0; i<j; i++) {
869 template<
typename OrdinalType,
typename ScalarType>
879 for (j = 0; j < numRowCols_; j++) {
880 for (i = 0; i < j; i++) {
887 for (j = 0; j < numRowCols_; j++) {
889 for (i = j+1; i < numRowCols_; i++) {
902 template<
typename OrdinalType,
typename ScalarType>
911 for(i = 0; i < numRowCols_; i++) {
912 for(j = 0; j < numRowCols_; j++) {
913 if((*
this)(i, j) != Operand(i, j)) {
922 template<
typename OrdinalType,
typename ScalarType>
925 return !((*this) == Operand);
932 template<
typename OrdinalType,
typename ScalarType>
939 for (j=0; j<numRowCols_; j++) {
940 ptr = values_ + j*stride_;
941 for (i=0; i<= j; i++) { *ptr = alpha * (*ptr); ptr++; }
945 for (j=0; j<numRowCols_; j++) {
946 ptr = values_ + j*stride_ + j;
947 for (i=j; i<numRowCols_; i++) { *ptr = alpha * (*ptr); ptr++; }
981 template<
typename OrdinalType,
typename ScalarType>
986 os <<
"Values_copied : yes" << std::endl;
988 os <<
"Values_copied : no" << std::endl;
989 os <<
"Rows / Columns : " << numRowCols_ << std::endl;
990 os <<
"LDA : " << stride_ << std::endl;
992 os <<
"Storage: Upper" << std::endl;
994 os <<
"Storage: Lower" << std::endl;
995 if(numRowCols_ == 0) {
996 os <<
"(matrix is empty, no values to display)" << std::endl;
998 for(OrdinalType i = 0; i < numRowCols_; i++) {
999 for(OrdinalType j = 0; j < numRowCols_; j++){
1000 os << (*this)(i,j) <<
" ";
1012 template<
typename OrdinalType,
typename ScalarType>
1015 "SerialSymDenseMatrix<T>::checkIndex: "
1016 "Row index " << rowIndex <<
" out of range [0, "<< numRowCols_ <<
")");
1018 "SerialSymDenseMatrix<T>::checkIndex: "
1019 "Col index " << colIndex <<
" out of range [0, "<< numRowCols_ <<
")");
1022 template<
typename OrdinalType,
typename ScalarType>
1029 valuesCopied_ =
false;
1033 template<
typename OrdinalType,
typename ScalarType>
1035 bool inputUpper, ScalarType* inputMatrix,
1036 OrdinalType inputStride, OrdinalType numRowCols_in,
1037 bool outputUpper, ScalarType* outputMatrix,
1038 OrdinalType outputStride, OrdinalType startRowCol,
1043 ScalarType* ptr1 = 0;
1044 ScalarType* ptr2 = 0;
1046 for (j = 0; j < numRowCols_in; j++) {
1047 if (inputUpper ==
true) {
1049 ptr2 = inputMatrix + (j + startRowCol) * inputStride + startRowCol;
1050 if (outputUpper ==
true) {
1052 ptr1 = outputMatrix + j*outputStride;
1054 for(i = 0; i <= j; i++) {
1055 *ptr1++ += alpha*(*ptr2++);
1058 for(i = 0; i <= j; i++) {
1066 ptr1 = outputMatrix + j;
1068 for(i = 0; i <= j; i++) {
1069 *ptr1 += alpha*(*ptr2++);
1070 ptr1 += outputStride;
1073 for(i = 0; i <= j; i++) {
1075 ptr1 += outputStride;
1082 ptr2 = inputMatrix + (startRowCol+j) * inputStride + startRowCol + j;
1083 if (outputUpper ==
true) {
1086 ptr1 = outputMatrix + j*outputStride + j;
1088 for(i = j; i < numRowCols_in; i++) {
1089 *ptr1 += alpha*(*ptr2++);
1090 ptr1 += outputStride;
1093 for(i = j; i < numRowCols_in; i++) {
1095 ptr1 += outputStride;
1101 ptr1 = outputMatrix + j*outputStride + j;
1103 for(i = j; i < numRowCols_in; i++) {
1104 *ptr1++ += alpha*(*ptr2++);
1107 for(i = j; i < numRowCols_in; i++) {
1116 template<
typename OrdinalType,
typename ScalarType>
1118 bool inputUpper, ScalarType* inputMatrix,
1119 OrdinalType inputStride, OrdinalType inputRows
1123 ScalarType * ptr1 = 0;
1124 ScalarType * ptr2 = 0;
1127 for (j=1; j<inputRows; j++) {
1128 ptr1 = inputMatrix + j;
1129 ptr2 = inputMatrix + j*inputStride;
1130 for (i=0; i<j; i++) {
1137 for (i=1; i<inputRows; i++) {
1138 ptr1 = inputMatrix + i;
1139 ptr2 = inputMatrix + i*inputStride;
1140 for (j=0; j<i; j++) {
1149 template<
typename OrdinalType,
typename ScalarType>
1159 template<
typename OrdinalType,
typename ScalarType>
1164 printer.
obj.print(out);
1169 template<
typename OrdinalType,
typename ScalarType>
1170 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
Default constructor; defines a zero size object.
static ScalarType * allocateValues(const OrdinalType numRows, const OrdinalType numCols)
Templated interface class to BLAS routines.
SerialSymDenseMatrixPrinter(const SerialSymDenseMatrix< OrdinalType, ScalarType > &obj_in)
virtual std::ostream & print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream << operator.
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.