41#ifndef _TEUCHOS_SERIALSYMDENSEMATRIX_HPP_
42#define _TEUCHOS_SERIALSYMDENSEMATRIX_HPP_
52#include "Teuchos_Assert.hpp"
120template<
typename OrdinalType,
typename ScalarType>
321 bool upper()
const {
return(upper_);};
324 char UPLO()
const {
return(UPLO_);};
383 bool empty()
const {
return(numRowCols_ == 0); }
403 virtual std::ostream&
print(std::ostream& os)
const;
430#pragma GCC diagnostic push
431#pragma GCC diagnostic ignored "-Wvla"
433#pragma GCC diagnostic pop
436 OrdinalType numRowCols_ = 0;
437 OrdinalType stride_ = 0;
438 bool valuesCopied_ =
false;
439 ScalarType* values_ =
nullptr;
448template<
typename OrdinalType,
typename ScalarType>
452 values_ = allocateValues(stride_, numRowCols_);
453 valuesCopied_ =
true;
460template<
typename OrdinalType,
typename ScalarType>
474 stride_ = numRowCols_;
475 values_ = allocateValues(stride_, numRowCols_);
477 valuesCopied_ =
true;
481template<
typename OrdinalType,
typename ScalarType>
483 : numRowCols_(Source.numRowCols_), stride_(0), valuesCopied_(
true),
484 values_(0), upper_(Source.upper_), UPLO_(Source.UPLO_)
486 if (!Source.valuesCopied_)
488 stride_ = Source.stride_;
489 values_ = Source.values_;
490 valuesCopied_ =
false;
494 stride_ = numRowCols_;
495 if(stride_ > 0 && numRowCols_ > 0) {
496 values_ = allocateValues(stride_, numRowCols_);
497 copyMat(Source.upper_, Source.values_, Source.stride_, numRowCols_, upper_, values_, stride_, 0);
502 valuesCopied_ =
false;
507template<
typename OrdinalType,
typename ScalarType>
512 numRowCols_(
numRowCols_in), stride_(Source.stride_), valuesCopied_(
false), upper_(Source.upper_), UPLO_(Source.UPLO_)
519 valuesCopied_ =
true;
527template<
typename OrdinalType,
typename ScalarType>
537template<
typename OrdinalType,
typename ScalarType>
542 stride_ = numRowCols_;
543 values_ = allocateValues(stride_, numRowCols_);
545 valuesCopied_ =
true;
549template<
typename OrdinalType,
typename ScalarType>
554 stride_ = numRowCols_;
555 values_ = allocateValues(stride_, numRowCols_);
556 valuesCopied_ =
true;
560template<
typename OrdinalType,
typename ScalarType>
577 stride_ = numRowCols_;
579 valuesCopied_ =
true;
587template<
typename OrdinalType,
typename ScalarType>
591 if (upper_ !=
false) {
592 copyUPLOMat(
true, values_, stride_, numRowCols_ );
598template<
typename OrdinalType,
typename ScalarType>
602 if (upper_ ==
false) {
603 copyUPLOMat(
false, values_, stride_, numRowCols_ );
609template<
typename OrdinalType,
typename ScalarType>
642template<
typename OrdinalType,
typename ScalarType>
void
646 std::swap(values_ ,
B.values_);
647 std::swap(numRowCols_,
B.numRowCols_);
648 std::swap(stride_,
B.stride_);
649 std::swap(valuesCopied_,
B.valuesCopied_);
650 std::swap(upper_,
B.upper_);
651 std::swap(UPLO_,
B.UPLO_);
654template<
typename OrdinalType,
typename ScalarType>
687template<
typename OrdinalType,
typename ScalarType>
693 if((!valuesCopied_) && (!Source.valuesCopied_) && (values_ == Source.values_)) {
694 upper_ = Source.upper_;
699 if (!Source.valuesCopied_) {
704 numRowCols_ = Source.numRowCols_;
705 stride_ = Source.stride_;
706 values_ = Source.values_;
707 upper_ = Source.upper_;
708 UPLO_ = Source.UPLO_;
713 numRowCols_ = Source.numRowCols_;
714 stride_ = Source.numRowCols_;
715 upper_ = Source.upper_;
716 UPLO_ = Source.UPLO_;
717 if(stride_ > 0 && numRowCols_ > 0) {
718 values_ = allocateValues(stride_, numRowCols_);
719 valuesCopied_ =
true;
727 if((Source.numRowCols_ <= stride_) && (Source.numRowCols_ == numRowCols_)) {
728 numRowCols_ = Source.numRowCols_;
729 upper_ = Source.upper_;
730 UPLO_ = Source.UPLO_;
734 numRowCols_ = Source.numRowCols_;
735 stride_ = Source.numRowCols_;
736 upper_ = Source.upper_;
737 UPLO_ = Source.UPLO_;
738 if(stride_ > 0 && numRowCols_ > 0) {
739 values_ = allocateValues(stride_, numRowCols_);
740 valuesCopied_ =
true;
744 copyMat(Source.upper_, Source.values_, Source.stride_, Source.numRowCols_, upper_, values_, stride_, 0);
749template<
typename OrdinalType,
typename ScalarType>
756template<
typename OrdinalType,
typename ScalarType>
760 if ((numRowCols_ != Source.numRowCols_))
762 TEUCHOS_CHK_REF(*
this);
768template<
typename OrdinalType,
typename ScalarType>
772 if ((numRowCols_ != Source.numRowCols_))
774 TEUCHOS_CHK_REF(*
this);
780template<
typename OrdinalType,
typename ScalarType>
784 if((!valuesCopied_) && (!Source.valuesCopied_) && (values_ == Source.values_)) {
785 upper_ = Source.upper_;
790 if ((numRowCols_ != Source.numRowCols_))
792 TEUCHOS_CHK_REF(*
this);
794 copyMat(Source.upper_, Source.values_, Source.stride_, numRowCols_, upper_, values_, stride_, 0 );
802template<
typename OrdinalType,
typename ScalarType>
805#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
806 checkIndex( rowIndex, colIndex );
808 if ( rowIndex <= colIndex ) {
811 return(values_[colIndex * stride_ + rowIndex]);
813 return(values_[rowIndex * stride_ + colIndex]);
818 return(values_[rowIndex * stride_ + colIndex]);
820 return(values_[colIndex * stride_ + rowIndex]);
824template<
typename OrdinalType,
typename ScalarType>
827#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
828 checkIndex( rowIndex, colIndex );
830 if ( rowIndex <= colIndex ) {
833 return(values_[colIndex * stride_ + rowIndex]);
835 return(values_[rowIndex * stride_ + colIndex]);
840 return(values_[rowIndex * stride_ + colIndex]);
842 return(values_[colIndex * stride_ + rowIndex]);
850template<
typename OrdinalType,
typename ScalarType>
856template<
typename OrdinalType,
typename ScalarType>
867 for (
j=0;
j<numRowCols_;
j++) {
869 ptr = values_ +
j*stride_;
870 for (
i=0;
i<
j;
i++) {
873 ptr = values_ +
j +
j*stride_;
874 for (
i=
j;
i<numRowCols_;
i++) {
882 for (
j=0;
j<numRowCols_;
j++) {
884 ptr = values_ +
j +
j*stride_;
885 for (
i=
j;
i<numRowCols_;
i++) {
889 for (
i=0;
i<
j;
i++) {
899template<
typename OrdinalType,
typename ScalarType>
909 for (
j = 0;
j < numRowCols_;
j++) {
910 for (
i = 0;
i <
j;
i++) {
917 for (
j = 0;
j < numRowCols_;
j++) {
919 for (
i =
j+1;
i < numRowCols_;
i++) {
932template<
typename OrdinalType,
typename ScalarType>
936 if((numRowCols_ !=
Operand.numRowCols_)) {
941 for(
i = 0;
i < numRowCols_;
i++) {
942 for(
j = 0;
j < numRowCols_;
j++) {
952template<
typename OrdinalType,
typename ScalarType>
962template<
typename OrdinalType,
typename ScalarType>
969 for (
j=0;
j<numRowCols_;
j++) {
970 ptr = values_ +
j*stride_;
975 for (
j=0;
j<numRowCols_;
j++) {
976 ptr = values_ +
j*stride_ +
j;
1011template<
typename OrdinalType,
typename ScalarType>
1016 os <<
"Values_copied : yes" << std::endl;
1018 os <<
"Values_copied : no" << std::endl;
1019 os <<
"Rows / Columns : " << numRowCols_ << std::endl;
1020 os <<
"LDA : " << stride_ << std::endl;
1022 os <<
"Storage: Upper" << std::endl;
1024 os <<
"Storage: Lower" << std::endl;
1025 if(numRowCols_ == 0) {
1026 os <<
"(matrix is empty, no values to display)" << std::endl;
1030 os << (*this)(
i,
j) <<
" ";
1042template<
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_ <<
")");
1052template<
typename OrdinalType,
typename ScalarType>
1053void SerialSymDenseMatrix<OrdinalType, ScalarType>::deleteArrays(
void)
1059 valuesCopied_ =
false;
1063template<
typename OrdinalType,
typename ScalarType>
1064void SerialSymDenseMatrix<OrdinalType, ScalarType>::copyMat(
1065 bool inputUpper, ScalarType* inputMatrix,
1066 OrdinalType inputStride, OrdinalType numRowCols_in,
1067 bool outputUpper, ScalarType* outputMatrix,
1068 OrdinalType outputStride, OrdinalType startRowCol,
1084 for(
i = 0;
i <=
j;
i++) {
1088 for(
i = 0;
i <=
j;
i++) {
1098 for(
i = 0;
i <=
j;
i++) {
1103 for(
i = 0;
i <=
j;
i++) {
1146template<
typename OrdinalType,
typename ScalarType>
1147void SerialSymDenseMatrix<OrdinalType, ScalarType>::copyUPLOMat(
1148 bool inputUpper, ScalarType* inputMatrix,
1149 OrdinalType inputStride, OrdinalType inputRows
1160 for (
i=0;
i<
j;
i++) {
1170 for (
j=0;
j<
i;
j++) {
1179template<
typename OrdinalType,
typename ScalarType>
1189template<
typename OrdinalType,
typename ScalarType>
1199template<
typename OrdinalType,
typename ScalarType>
1200SerialSymDenseMatrixPrinter<OrdinalType,ScalarType>
Templated interface class to BLAS routines.
Object for storing data and providing functionality that is common to all computational classes.
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
Teuchos::DataAccess Mode enumerable type.
Defines basic traits for the scalar field type.
Functionality and data that is common to all computational classes.
Smart reference counting pointer class for automatic garbage collection.
RCP(ENull null_arg=null)
Initialize RCP<T> to NULL.
Ptr< T > ptr() const
Get a safer wrapper raw C++ pointer to the underlying object.
This class creates and provides basic support for symmetric, positive-definite dense matrices of temp...
SerialSymDenseMatrix()=default
Default constructor; defines a zero size object.
bool operator==(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Operand) const
Equality of two matrices.
int shapeUninitialized(OrdinalType numRowsCols)
Set dimensions of a Teuchos::SerialSymDenseMatrix object; don't initialize values.
int shape(OrdinalType numRowsCols)
Set dimensions of a Teuchos::SerialSymDenseMatrix object; init values to zero.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
ScalarType & operator()(OrdinalType rowIndex, OrdinalType colIndex)
Element access method (non-const).
OrdinalType stride() const
Returns the stride between the columns of this matrix in memory.
SerialSymDenseMatrix< OrdinalType, ScalarType > & operator-=(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source)
Subtract another matrix from this matrix.
virtual std::ostream & print(std::ostream &os) const
Print method. Defines the behavior of the std::ostream << operator.
SerialSymDenseMatrix< OrdinalType, ScalarType > & operator+=(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source)
Add another matrix to this matrix.
bool operator!=(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Operand) const
Inequality of two matrices.
void swap(SerialSymDenseMatrix< OrdinalType, ScalarType > &B)
Swap values between this matrix and incoming matrix.
OrdinalType numCols() const
Returns the column dimension of this matrix.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero(), bool fullMatrix=false)
Set all values in the matrix to a constant value.
virtual ~SerialSymDenseMatrix()
Teuchos::SerialSymDenseMatrix destructor.
char UPLO() const
Returns character value of UPLO used by LAPACK routines.
SerialSymDenseMatrix< OrdinalType, ScalarType > & operator*=(const ScalarType alpha)
Inplace scalar-matrix product A = alpha*A.
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.
ScalarType scalarType
Typedef for scalar type.
bool upper() const
Returns true if upper triangular part of this matrix has and will be used.
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
ScalarType * values() const
Returns the pointer to the ScalarType data array contained in the object.
SerialSymDenseMatrix< OrdinalType, ScalarType > & operator=(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
bool empty() const
Returns whether this matrix is empty.
SerialSymDenseMatrix< OrdinalType, ScalarType > & assign(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
void setLower()
Specify that the lower triangle of the this matrix should be used.
int reshape(OrdinalType numRowsCols)
Reshape a Teuchos::SerialSymDenseMatrix object.
OrdinalType numRows() const
Returns the row dimension of this matrix.
void setUpper()
Specify that the upper triangle of the this matrix should be used.
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
OrdinalType ordinalType
Typedef for ordinal type.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
SerialBandDenseMatrixPrinter< OrdinalType, ScalarType > printMat(const SerialBandDenseMatrix< OrdinalType, ScalarType > &obj)
Return SerialBandDenseMatrix ostream manipulator Use as:
This structure defines some basic traits for a scalar field type.
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
T magnitudeType
Mandatory typedef for result of magnitude.
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.
Ostream manipulator for SerialSymDenseMatrix.