60 if (set_object_label) {
61 SetLabel(
"Epetra::SerialDenseMatrix");
67 bool set_object_label)
78 if (set_object_label) {
79 SetLabel(
"Epetra::SerialDenseMatrix");
86 int errorcode =
Shape(NumRows, NumCols);
88 throw ReportError(
"Shape returned non-zero value", errorcode);
93 int NumRows,
int NumCols,
94 bool set_object_label)
105 if (set_object_label) {
106 SetLabel(
"Epetra::SerialDenseMatrix");
109 throw ReportError(
"Null pointer passed as A parameter.", -3);
119 const int newsize =
LDA_ *
N_;
121 A_ =
new double[newsize];
144 const int newsize =
LDA_ *
N_;
146 A_ =
new double[newsize];
158 if(NumRows < 0 || NumCols < 0)
162 const int newsize = NumRows * NumCols;
166 A_tmp =
new double[newsize];
167 for (
int k = 0; k < newsize; k++)
187 if(NumRows < 0 || NumCols < 0)
194 const int newsize =
LDA_ *
N_;
196 A_ =
new double[newsize];
197 for (
int k = 0; k < newsize; k++)
228 throw ReportError(
"operator= type mismatch (lhs = " + std::string(
Label()) +
229 ", rhs = " + std::string(Source.
Label()) +
").", -5);
247 const int newsize =
LDA_ *
N_;
249 A_ =
new double[newsize];
258 if((Source.
M_ <=
LDA_) && (Source.
N_ ==
N_)) {
267 const int newsize =
LDA_ *
N_;
269 A_ =
new double[newsize];
284 if (
M_ != rhs.
M_ ||
N_ != rhs.
N_)
return(
false);
286 const double* A_tmp =
A_;
287 const double* rhsA = rhs.
A_;
289 for(
int j=0; j<
N_; ++j) {
291 int rhsOffset = j*rhs.
LDA_;
292 for(
int i=0; i<
M_; ++i) {
304 if (
M() != Source.
M())
306 " is different than row dimension of target = " +
toString(
LDA()), -1);
307 if (
N() != Source.
N())
309 " is different than column dimension of target = " +
toString(
N()), -2);
324 double* tptr = Target;
325 const double* sptr = Source;
327 for(
int j=0; j<NumCols; ++j) {
328 for(i=0; i<NumRows; ++i) {
337 for(
int j=0; j<NumCols; ++j) {
338 for(i=0; i<NumRows; ++i) {
374 for (j=0; j<
N_; j++) {
377 for (i=0; i<
M_; i++) sum += std::abs(*ptr++);
393 for (i=0; i<
M_; i++) {
396 for (j=0; j<
N_; j++) {
397 sum += std::abs(*ptr);
411 for (j=0; j<
N_; j++) {
413 for (i=0; i<
M_; i++) { *ptr = ScalarA * (*ptr); ptr++; }
423 double ScalarThis ) {
429 int A_nrows = (TransA==
'T') ? A_in.
N() : A_in.
M();
430 int A_ncols = (TransA==
'T') ? A_in.
M() : A_in.
N();
431 int B_nrows = (TransB==
'T') ? B.
N() : B.
M();
432 int B_ncols = (TransB==
'T') ? B.
M() : B.
N();
435 A_ncols != B_nrows ||
440 GEMM(TransA, TransB,
M_,
N_, A_ncols, ScalarAB, A_in.
A(), A_in.
LDA(),
442 long int nflops = 2*
M_;
445 if (ScalarAB != 1.0) nflops +=
M_*
N_;
446 if (ScalarThis != 0.0) nflops +=
M_*
N_;
466 if (y_ncols != x_ncols || y_nrows != A_ncols) y.
Reshape(A_ncols, x_ncols);
470 if (y_ncols != x_ncols || y_nrows != A_nrows) y.
Reshape(A_nrows, x_ncols);
473 double scalar0 = 0.0;
474 double scalar1 = 1.0;
478 err = y.
Multiply(
'T',
'N', scalar1, *
this, x, scalar0);
481 err = y.
Multiply(
'N',
'N', scalar1, *
this, x, scalar0);
497 double ScalarThis ) {
505 else if (SideA==
'L') {
506 if (
M_ != A_in.
M() ||
517 long int nflops = 2*
M_;
520 if (ScalarAB != 1.0) nflops +=
M_*
N_;
521 if (ScalarThis != 0.0) nflops +=
M_*
N_;
530 os <<
"Data access mode: Copy" << std::endl;
532 os <<
"Data access mode: View" << std::endl;
534 os <<
"A_Copied: yes" << std::endl;
536 os <<
"A_Copied: no" << std::endl;
537 os <<
"Rows(M): " <<
M_ << std::endl;
538 os <<
"Columns(N): " <<
N_ << std::endl;
539 os <<
"LDA: " <<
LDA_ << std::endl;
540 if(
M_ == 0 ||
N_ == 0)
541 os <<
"(matrix is empty, no values to display)" << std::endl;
543 for(
int i = 0; i <
M_; i++) {
544 for(
int j = 0; j <
N_; j++){
545 os << (*this)(i,j) <<
" ";
555 for(
int j = 0; j <
N_; j++) {
556 double* arrayPtr =
A_ + (j *
LDA_);
557 for(
int i = 0; i <
M_; i++) {
virtual ~Epetra_SerialDenseMatrix()
Epetra_SerialDenseMatrix destructor.
virtual double NormInf() const
Computes the Infinity-Norm of the this matrix.
void GEMM(const char TRANSA, const char TRANSB, const int M, const int N, const int K, const float ALPHA, const float *A, const int LDA, const float *B, const int LDB, const float BETA, float *C, const int LDC) const
Epetra_BLAS matrix-matrix multiply function (SGEMM)
void CopyMat(const double *Source, int Source_LDA, int NumRows, int NumCols, double *Target, int Target_LDA, bool add=false)
int Random()
Set matrix values to random numbers.
virtual int Apply(const Epetra_SerialDenseMatrix &X, Epetra_SerialDenseMatrix &Y)
Returns the result of a Epetra_SerialDenseOperator applied to a Epetra_SerialDenseMatrix X in Y...
Epetra_SerialDenseMatrix & operator+=(const Epetra_SerialDenseMatrix &Source)
Add one matrix to another.
virtual void SetLabel(const char *const Label)
Epetra_Object Label definition using char *.
#define EPETRA_CHK_ERR(a)
virtual double NormOne() const
Computes the 1-Norm of the this matrix.
Epetra_SerialDenseMatrix: A class for constructing and using real double precision general dense matr...
Epetra_SerialSymDenseMatrix: A class for constructing and using symmetric positive definite dense mat...
double * A() const
Returns pointer to the this matrix.
Epetra_Util: The Epetra Util Wrapper Class.
std::string toString(const int &x) const
Epetra_Object: The base Epetra class.
void SYMM(const char SIDE, const char UPLO, const int M, const int N, const float ALPHA, const float *A, const int LDA, const float *B, const int LDB, const float BETA, float *C, const int LDC) const
Epetra_BLAS symmetric matrix-matrix multiply function (SSYMM)
Epetra_SerialDenseMatrix & operator=(const Epetra_SerialDenseMatrix &Source)
Value copy from one matrix to another.
Epetra_CompObject: Functionality and data that is common to all computational classes.
char UPLO() const
Returns character value of UPLO used by LAPACK routines.
int Reshape(int NumRows, int NumCols)
Reshape a Epetra_SerialDenseMatrix object.
const double Epetra_MinDouble
int Scale(double ScalarA)
Inplace scalar-matrix product A = a A.
int LDA() const
Returns the leading dimension of the this matrix.
virtual void Print(std::ostream &os) const
Print service methods; defines behavior of ostream << operator.
int Multiply(char TransA, char TransB, double ScalarAB, const Epetra_SerialDenseMatrix &A, const Epetra_SerialDenseMatrix &B, double ScalarThis)
Matrix-Matrix multiplication, this = ScalarThis*this + ScalarAB*A*B.
double RandomDouble()
Returns a random double on the interval (-1.0,1.0)
virtual const char * Label() const
Returns a character string describing the operator.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual int ReportError(const std::string Message, int ErrorCode) const
Error reporting method.
int N() const
Returns column dimension of system.
int Shape(int NumRows, int NumCols)
Set dimensions of a Epetra_SerialDenseMatrix object; init values to zero.
int M() const
Returns row dimension of system.
void UpdateFlops(int Flops_in) const
Increment Flop count for this object.
Epetra_SerialDenseMatrix(bool set_object_label=true)
Default constructor; defines a zero size object.
bool operator==(const Epetra_SerialDenseMatrix &rhs) const
Comparison operator.