41#ifndef _TEUCHOS_SERIALSYMDENSEMATRIX_HPP_
42#define _TEUCHOS_SERIALSYMDENSEMATRIX_HPP_
120template<
typename OrdinalType,
typename ScalarType>
298 ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex);
308 const ScalarType&
operator () (OrdinalType rowIndex, OrdinalType colIndex)
const;
403 virtual std::ostream&
print(std::ostream& os)
const;
410 void scale(
const ScalarType alpha );
413 void copyMat(
bool inputUpper, ScalarType* inputMatrix, OrdinalType inputStride,
414 OrdinalType numRowCols,
bool outputUpper, ScalarType* outputMatrix,
415 OrdinalType outputStride, OrdinalType startRowCol,
420 OrdinalType inputStride, OrdinalType inputRows);
423 void checkIndex( OrdinalType rowIndex, OrdinalType colIndex = 0 )
const;
430#pragma GCC diagnostic push
431#pragma GCC diagnostic ignored "-Wvla"
432 return new ScalarType[
size];
433#pragma GCC diagnostic pop
448template<
typename OrdinalType,
typename ScalarType>
460template<
typename OrdinalType,
typename ScalarType>
462 DataAccess CV,
bool upper_in, ScalarType* values_in, OrdinalType stride_in, OrdinalType numRowCols_in
481template<
typename OrdinalType,
typename ScalarType>
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>
510 ScalarType> &Source, OrdinalType numRowCols_in, OrdinalType startRowCol )
527template<
typename OrdinalType,
typename ScalarType>
537template<
typename OrdinalType,
typename ScalarType>
549template<
typename OrdinalType,
typename ScalarType>
560template<
typename OrdinalType,
typename ScalarType>
564 ScalarType* values_tmp =
allocateValues(numRowCols_in, numRowCols_in);
566 for(OrdinalType k = 0; k < numRowCols_in * numRowCols_in; k++)
568 values_tmp[k] = zero;
587template<
typename OrdinalType,
typename ScalarType>
598template<
typename OrdinalType,
typename ScalarType>
609template<
typename OrdinalType,
typename ScalarType>
613 if (fullMatrix ==
true) {
626 for(OrdinalType i = 0; i <= j; i++) {
642template<
typename OrdinalType,
typename ScalarType>
void
651 std::swap(
UPLO_,
B.UPLO_);
654template<
typename OrdinalType,
typename ScalarType>
663 for(OrdinalType i = 0; i < j; i++) {
687template<
typename OrdinalType,
typename ScalarType>
749template<
typename OrdinalType,
typename ScalarType>
756template<
typename OrdinalType,
typename ScalarType>
768template<
typename OrdinalType,
typename ScalarType>
780template<
typename OrdinalType,
typename ScalarType>
802template<
typename OrdinalType,
typename ScalarType>
805#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
808 if ( rowIndex <= colIndex ) {
824template<
typename OrdinalType,
typename ScalarType>
827#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
830 if ( rowIndex <= colIndex ) {
850template<
typename OrdinalType,
typename ScalarType>
856template<
typename OrdinalType,
typename ScalarType>
870 for (i=0; i<j; i++) {
889 for (i=0; i<j; i++) {
899template<
typename OrdinalType,
typename ScalarType>
910 for (i = 0; i < j; i++) {
932template<
typename OrdinalType,
typename ScalarType>
943 if((*
this)(i, j) != Operand(i, j)) {
952template<
typename OrdinalType,
typename ScalarType>
955 return !((*this) == Operand);
962template<
typename OrdinalType,
typename ScalarType>
971 for (i=0; i<= j; i++) { *
ptr = alpha * (*ptr);
ptr++; }
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;
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>
1063template<
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++) {
1146template<
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++) {
1179template<
typename OrdinalType,
typename ScalarType>
1189template<
typename OrdinalType,
typename ScalarType>
1194 printer.
obj.print(out);
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.
#define TEUCHOS_CHK_REF(a)
#define TEUCHOS_MIN(x, y)
#define TEUCHOS_MAX(x, y)
Teuchos::DataAccess Mode enumerable type.
Defines basic traits for the scalar field type.
SerialSymDenseMatrix()=default
Default constructor; defines a zero size object.
BLAS(void)
Default constructor.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
CompObject()
Default constructor.
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
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.
void scale(const ScalarType alpha)
ScalarType & operator()(OrdinalType rowIndex, OrdinalType colIndex)
Element access method (non-const).
SerialSymDenseMatrix(DataAccess CV, const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source, OrdinalType numRowCols, OrdinalType startRowCol=0)
Submatrix Copy Constructor.
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.
void copyUPLOMat(bool inputUpper, ScalarType *inputMatrix, OrdinalType inputStride, OrdinalType inputRows)
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.
static ScalarType * allocateValues(const OrdinalType numRows, const OrdinalType numCols)
virtual ~SerialSymDenseMatrix()
Teuchos::SerialSymDenseMatrix destructor.
SerialSymDenseMatrix(DataAccess CV, bool upper, ScalarType *values, OrdinalType stride, OrdinalType numRowsCols)
Set object values from two-dimensional array.
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.
SerialSymDenseMatrix(OrdinalType numRowsCols, bool zeroOut=true)
Basic constructor; defines a matrix of numRowsCols size and (optionally) initializes it.
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.
void checkIndex(OrdinalType rowIndex, OrdinalType colIndex=0) const
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.
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
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.
SerialSymDenseMatrix(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source)
Teuchos::SerialSymDenseMatrix copy constructor.
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.
std::ostream & operator<<(std::ostream &os, BigUInt< n > a)
SerialBandDenseMatrixPrinter< OrdinalType, ScalarType > printMat(const SerialBandDenseMatrix< OrdinalType, ScalarType > &obj)
Return SerialBandDenseMatrix ostream manipulator Use as:
static magnitudeType magnitude(T a)
Returns the magnitudeType of the scalar type a.
static T one()
Returns representation of one for this scalar type.
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.
static T squareroot(T x)
Returns a number of magnitudeType that is the square root of this scalar type x.
Ostream manipulator for SerialSymDenseMatrix.
const SerialSymDenseMatrix< OrdinalType, ScalarType > & obj
SerialSymDenseMatrixPrinter(const SerialSymDenseMatrix< OrdinalType, ScalarType > &obj_in)