43 #ifndef _TEUCHOS_SERIALSYMDENSEMATRIX_HPP_
44 #define _TEUCHOS_SERIALSYMDENSEMATRIX_HPP_
121 template<
typename OrdinalType,
typename ScalarType>
203 int shape(OrdinalType numRowsCols);
228 int reshape(OrdinalType numRowsCols);
293 ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex);
303 const ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex)
const;
397 virtual void print(std::ostream& os)
const;
405 void scale(
const ScalarType alpha );
408 void copyMat(
bool inputUpper, ScalarType* inputMatrix, OrdinalType inputStride,
409 OrdinalType numRowCols,
bool outputUpper, ScalarType* outputMatrix,
410 OrdinalType outputStride, OrdinalType startRowCol,
414 void copyUPLOMat(
bool inputUpper, ScalarType* inputMatrix,
415 OrdinalType inputStride, OrdinalType inputRows);
418 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
433 template<
typename OrdinalType,
typename ScalarType>
436 numRowCols_(0), stride_(0), valuesCopied_(false), values_(0), upper_(false), UPLO_(
'L')
439 template<
typename OrdinalType,
typename ScalarType>
442 numRowCols_(numRowCols_in), stride_(numRowCols_in), valuesCopied_(false), upper_(false), UPLO_(
'L')
450 template<
typename OrdinalType,
typename ScalarType>
452 DataAccess CV,
bool upper_in, ScalarType* values_in, OrdinalType stride_in, OrdinalType numRowCols_in
455 numRowCols_(numRowCols_in), stride_(stride_in), valuesCopied_(false),
456 values_(values_in), upper_(upper_in)
472 template<
typename OrdinalType,
typename ScalarType>
475 numRowCols_(Source.numRowCols_), stride_(0), valuesCopied_(true),
476 values_(0), upper_(Source.upper_), UPLO_(Source.UPLO_)
489 values_ =
new ScalarType[newsize];
499 template<
typename OrdinalType,
typename ScalarType>
502 ScalarType> &Source, OrdinalType numRowCols_in, OrdinalType startRowCol )
504 numRowCols_(numRowCols_in), stride_(Source.stride_), valuesCopied_(false), upper_(Source.upper_), UPLO_(Source.UPLO_)
519 template<
typename OrdinalType,
typename ScalarType>
529 template<
typename OrdinalType,
typename ScalarType>
533 numRowCols_ = numRowCols_in;
534 stride_ = numRowCols_;
535 values_ =
new ScalarType[stride_*numRowCols_];
537 valuesCopied_ =
true;
541 template<
typename OrdinalType,
typename ScalarType>
545 numRowCols_ = numRowCols_in;
546 stride_ = numRowCols_;
547 values_ =
new ScalarType[stride_*numRowCols_];
548 valuesCopied_ =
true;
552 template<
typename OrdinalType,
typename ScalarType>
556 ScalarType* values_tmp =
new ScalarType[numRowCols_in * numRowCols_in];
558 for(OrdinalType k = 0; k < numRowCols_in * numRowCols_in; k++)
560 values_tmp[k] = zero;
562 OrdinalType numRowCols_tmp =
TEUCHOS_MIN(numRowCols_, numRowCols_in);
565 copyMat(upper_, values_, stride_, numRowCols_tmp, upper_, values_tmp, numRowCols_in, 0);
568 numRowCols_ = numRowCols_in;
569 stride_ = numRowCols_;
570 values_ = values_tmp;
571 valuesCopied_ =
true;
579 template<
typename OrdinalType,
typename ScalarType>
583 if (upper_ !=
false) {
584 copyUPLOMat(
true, values_, stride_, numRowCols_ );
590 template<
typename OrdinalType,
typename ScalarType>
594 if (upper_ ==
false) {
595 copyUPLOMat(
false, values_, stride_, numRowCols_ );
601 template<
typename OrdinalType,
typename ScalarType>
605 if (fullMatrix ==
true) {
606 for(OrdinalType j = 0; j < numRowCols_; j++)
608 for(OrdinalType i = 0; i < numRowCols_; i++)
610 values_[i + j*stride_] = value_in;
617 for(OrdinalType j = 0; j < numRowCols_; j++) {
618 for(OrdinalType i = 0; i <= j; i++) {
619 values_[i + j*stride_] = value_in;
624 for(OrdinalType j = 0; j < numRowCols_; j++) {
625 for(OrdinalType i = j; i < numRowCols_; i++) {
626 values_[i + j*stride_] = value_in;
634 template<
typename OrdinalType,
typename ScalarType>
642 for(OrdinalType j = 0; j < numRowCols_; j++) {
643 for(OrdinalType i = 0; i < j; i++) {
651 for(OrdinalType j = 0; j < numRowCols_; j++) {
652 for(OrdinalType i = j+1; i < numRowCols_; i++) {
661 for(OrdinalType i = 0; i < numRowCols_; i++) {
662 values_[i + i*stride_] = diagSum[i] + bias;
667 template<
typename OrdinalType,
typename ScalarType>
688 UPLO_ = Source.
UPLO_;
696 UPLO_ = Source.
UPLO_;
697 const OrdinalType newsize = stride_ * numRowCols_;
699 values_ =
new ScalarType[newsize];
700 valuesCopied_ =
true;
711 UPLO_ = Source.
UPLO_;
718 UPLO_ = Source.
UPLO_;
719 const OrdinalType newsize = stride_ * numRowCols_;
721 values_ =
new ScalarType[newsize];
722 valuesCopied_ =
true;
731 template<
typename OrdinalType,
typename ScalarType>
738 template<
typename OrdinalType,
typename ScalarType>
750 template<
typename OrdinalType,
typename ScalarType>
762 template<
typename OrdinalType,
typename ScalarType>
776 copyMat(Source.
upper_, Source.
values_, Source.
stride_, numRowCols_, upper_, values_, stride_, 0 );
784 template<
typename OrdinalType,
typename ScalarType>
787 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
788 checkIndex( rowIndex, colIndex );
790 if ( rowIndex <= colIndex ) {
793 return(values_[colIndex * stride_ + rowIndex]);
795 return(values_[rowIndex * stride_ + colIndex]);
800 return(values_[rowIndex * stride_ + colIndex]);
802 return(values_[colIndex * stride_ + rowIndex]);
806 template<
typename OrdinalType,
typename ScalarType>
809 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
810 checkIndex( rowIndex, colIndex );
812 if ( rowIndex <= colIndex ) {
815 return(values_[colIndex * stride_ + rowIndex]);
817 return(values_[rowIndex * stride_ + colIndex]);
822 return(values_[rowIndex * stride_ + colIndex]);
824 return(values_[colIndex * stride_ + rowIndex]);
832 template<
typename OrdinalType,
typename ScalarType>
838 template<
typename OrdinalType,
typename ScalarType>
849 for (j=0; j<numRowCols_; j++) {
851 ptr = values_ + j*stride_;
852 for (i=0; i<j; i++) {
855 ptr = values_ + j + j*stride_;
856 for (i=j; i<numRowCols_; i++) {
864 for (j=0; j<numRowCols_; j++) {
866 ptr = values_ + j + j*stride_;
867 for (i=j; i<numRowCols_; i++) {
871 for (i=0; i<j; i++) {
881 template<
typename OrdinalType,
typename ScalarType>
891 for (j = 0; j < numRowCols_; j++) {
892 for (i = 0; i < j; i++) {
899 for (j = 0; j < numRowCols_; j++) {
901 for (i = j+1; i < numRowCols_; i++) {
914 template<
typename OrdinalType,
typename ScalarType>
923 for(i = 0; i < numRowCols_; i++) {
924 for(j = 0; j < numRowCols_; j++) {
925 if((*
this)(i, j) != Operand(i, j)) {
934 template<
typename OrdinalType,
typename ScalarType>
937 return !((*this) == Operand);
944 template<
typename OrdinalType,
typename ScalarType>
951 for (j=0; j<numRowCols_; j++) {
952 ptr = values_ + j*stride_;
953 for (i=0; i<= j; i++) { *ptr = alpha * (*ptr); ptr++; }
957 for (j=0; j<numRowCols_; j++) {
958 ptr = values_ + j*stride_ + j;
959 for (i=j; i<numRowCols_; i++) { *ptr = alpha * (*ptr); ptr++; }
993 template<
typename OrdinalType,
typename ScalarType>
998 os <<
"Values_copied : yes" << std::endl;
1000 os <<
"Values_copied : no" << std::endl;
1001 os <<
"Rows / Columns : " << numRowCols_ << std::endl;
1002 os <<
"LDA : " << stride_ << std::endl;
1004 os <<
"Storage: Upper" << std::endl;
1006 os <<
"Storage: Lower" << std::endl;
1007 if(numRowCols_ == 0) {
1008 os <<
"(matrix is empty, no values to display)" << std::endl;
1010 for(OrdinalType i = 0; i < numRowCols_; i++) {
1011 for(OrdinalType j = 0; j < numRowCols_; j++){
1012 os << (*this)(i,j) <<
" ";
1023 template<
typename OrdinalType,
typename ScalarType>
1026 "SerialSymDenseMatrix<T>::checkIndex: "
1027 "Row index " << rowIndex <<
" out of range [0, "<< numRowCols_ <<
")");
1029 "SerialSymDenseMatrix<T>::checkIndex: "
1030 "Col index " << colIndex <<
" out of range [0, "<< numRowCols_ <<
")");
1033 template<
typename OrdinalType,
typename ScalarType>
1040 valuesCopied_ =
false;
1044 template<
typename OrdinalType,
typename ScalarType>
1046 bool inputUpper, ScalarType* inputMatrix,
1047 OrdinalType inputStride, OrdinalType numRowCols_in,
1048 bool outputUpper, ScalarType* outputMatrix,
1049 OrdinalType outputStride, OrdinalType startRowCol,
1054 ScalarType* ptr1 = 0;
1055 ScalarType* ptr2 = 0;
1057 for (j = 0; j < numRowCols_in; j++) {
1058 if (inputUpper ==
true) {
1060 ptr2 = inputMatrix + (j + startRowCol) * inputStride + startRowCol;
1061 if (outputUpper ==
true) {
1063 ptr1 = outputMatrix + j*outputStride;
1065 for(i = 0; i <= j; i++) {
1066 *ptr1++ += alpha*(*ptr2++);
1069 for(i = 0; i <= j; i++) {
1077 ptr1 = outputMatrix + j;
1079 for(i = 0; i <= j; i++) {
1080 *ptr1 += alpha*(*ptr2++);
1081 ptr1 += outputStride;
1084 for(i = 0; i <= j; i++) {
1086 ptr1 += outputStride;
1093 ptr2 = inputMatrix + (startRowCol+j) * inputStride + startRowCol + j;
1094 if (outputUpper ==
true) {
1097 ptr1 = outputMatrix + j*outputStride + j;
1099 for(i = j; i < numRowCols_in; i++) {
1100 *ptr1 += alpha*(*ptr2++);
1101 ptr1 += outputStride;
1104 for(i = j; i < numRowCols_in; i++) {
1106 ptr1 += outputStride;
1112 ptr1 = outputMatrix + j*outputStride + j;
1114 for(i = j; i < numRowCols_in; i++) {
1115 *ptr1++ += alpha*(*ptr2++);
1118 for(i = j; i < numRowCols_in; i++) {
1127 template<
typename OrdinalType,
typename ScalarType>
1129 bool inputUpper, ScalarType* inputMatrix,
1130 OrdinalType inputStride, OrdinalType inputRows
1134 ScalarType * ptr1 = 0;
1135 ScalarType * ptr2 = 0;
1138 for (j=1; j<inputRows; j++) {
1139 ptr1 = inputMatrix + j;
1140 ptr2 = inputMatrix + j*inputStride;
1141 for (i=0; i<j; i++) {
1148 for (i=1; i<inputRows; i++) {
1149 ptr1 = inputMatrix + i;
1150 ptr2 = inputMatrix + i*inputStride;
1151 for (j=0; j<i; j++) {