Epetra_SerialDenseMatrix.h

Go to the documentation of this file.
00001 
00002 //@HEADER
00003 /*
00004 ************************************************************************
00005 
00006               Epetra: Linear Algebra Services Package 
00007                 Copyright (2001) Sandia Corporation
00008 
00009 Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00010 license for use of this work by or on behalf of the U.S. Government.
00011 
00012 This library is free software; you can redistribute it and/or modify
00013 it under the terms of the GNU Lesser General Public License as
00014 published by the Free Software Foundation; either version 2.1 of the
00015 License, or (at your option) any later version.
00016  
00017 This library is distributed in the hope that it will be useful, but
00018 WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 Lesser General Public License for more details.
00021  
00022 You should have received a copy of the GNU Lesser General Public
00023 License along with this library; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 USA
00026 Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00027 
00028 ************************************************************************
00029 */
00030 //@HEADER
00031 
00032 #ifndef EPETRA_SERIALDENSEMATRIX_H
00033 #define EPETRA_SERIALDENSEMATRIX_H
00034 
00035 #include "Epetra_Object.h" 
00036 #include "Epetra_CompObject.h"
00037 #include "Epetra_BLAS.h"
00038 #include "Epetra_SerialDenseOperator.h"
00039 class Epetra_SerialSymDenseMatrix;
00040 class Epetra_VbrMatrix;
00041 
00043 
00093 //=========================================================================
00094 class Epetra_SerialDenseMatrix : public Epetra_CompObject, public Epetra_Object, public Epetra_SerialDenseOperator, public Epetra_BLAS {
00095 
00096   public:
00097   
00099 
00100 
00101 
00106   Epetra_SerialDenseMatrix(bool set_object_label=true);
00107 
00109 
00120   Epetra_SerialDenseMatrix(int NumRows, int NumCols, bool set_object_label=true);
00121   
00123 
00138   Epetra_SerialDenseMatrix(Epetra_DataAccess CV, double* A, int LDA, int NumRows, int NumCols,
00139                            bool set_object_label=true);
00140   
00142   
00143   Epetra_SerialDenseMatrix(const Epetra_SerialDenseMatrix& Source);
00144 
00146   virtual ~Epetra_SerialDenseMatrix ();
00148 
00150 
00151 
00152 
00164   int Shape(int NumRows, int NumCols);
00165   
00167 
00180   int Reshape(int NumRows, int NumCols);
00182 
00184 
00185 
00187 
00206   int Multiply(char TransA, char TransB, double ScalarAB, 
00207          const Epetra_SerialDenseMatrix& A, 
00208          const Epetra_SerialDenseMatrix& B,
00209          double ScalarThis);
00210 
00212   /* This method is intended to imitate the semantics of the matrix-vector
00213     multiplication provided by Epetra's sparse matrices. The 'vector' arguments
00214     are actually matrices; this method will return an error if the
00215     dimensions of 'x' are not compatible. 'y' will be reshaped if necessary.
00216   */
00217   int Multiply(bool transA,
00218                const Epetra_SerialDenseMatrix& x,
00219                Epetra_SerialDenseMatrix& y);
00220 
00222 
00243   int Multiply(char SideA, double ScalarAB, 
00244          const Epetra_SerialSymDenseMatrix& A, 
00245          const Epetra_SerialDenseMatrix& B,
00246          double ScalarThis);
00247 
00249 
00257   int Scale(double ScalarA);
00258 
00260 
00263   virtual double NormOne() const;
00264 
00266   virtual double NormInf() const;
00267 
00269 
00271 
00272 
00274 
00280     Epetra_SerialDenseMatrix & operator = (const Epetra_SerialDenseMatrix& Source);
00281 
00283 
00290     Epetra_SerialDenseMatrix & operator += (const Epetra_SerialDenseMatrix& Source);
00291 
00293 
00302       double& operator () (int RowIndex, int ColIndex);
00303 
00305 
00314     const double& operator () (int RowIndex, int ColIndex) const;
00315 
00317 
00327     double* operator [] (int ColIndex);
00328 
00330 
00340     const double* operator [] (int ColIndex) const;
00341     
00343 
00349   int Random();
00350 
00352   int M() const {return(M_);};
00353 
00355   int N() const {return(N_);};
00356 
00358   double* A() const {return(A_);};
00359 
00361   double* A() {return(A_);};
00362 
00364   int LDA() const {return(LDA_);};
00365 
00367   Epetra_DataAccess CV() const {return(CV_);};
00369   
00371 
00372 
00373   virtual void Print(ostream& os) const;
00375 
00377 
00378 
00380 
00383   virtual double OneNorm() const {return(NormOne());};
00384 
00386   virtual double InfNorm() const {return(NormInf());};
00388 
00390 
00391  
00393 
00402     virtual int SetUseTranspose(bool UseTranspose) { UseTranspose_ = UseTranspose; return (0); }
00403  
00405 
00413   virtual int Apply(const Epetra_SerialDenseMatrix& X, Epetra_SerialDenseMatrix& Y);
00414  
00416 
00425     virtual int ApplyInverse(const Epetra_SerialDenseMatrix & X, Epetra_SerialDenseMatrix & Y)
00426     {
00427       (void)X;//prevents unused variable compiler warning
00428       (void)Y;
00429       return (-1);
00430     }
00431  
00433     virtual const char * Label() const { return Epetra_Object::Label(); }
00434  
00436     virtual bool UseTranspose() const { return UseTranspose_; }
00437  
00439     virtual bool HasNormInf() const { return true; }
00440 
00442     virtual int RowDim() const { return M(); } 
00443  
00445     virtual int ColDim() const { return N(); } 
00447 
00448  protected:
00449 
00450   void CopyMat(double* Source, int Source_LDA, int NumRows, int NumCols,
00451                double* Target, int Target_LDA, bool add=false);
00452   void CleanupData();
00453 
00454   int M_;
00455   int N_;
00456   bool A_Copied_;
00457   Epetra_DataAccess CV_;
00458 
00459   //For performance reasons, it's better if Epetra_VbrMatrix can access the
00460   //LDA_ and A_ members of this class directly without going through an
00461   //accessor method. Rather than making them public members, we'll make
00462   //Epetra_VbrMatrix a friend class.
00463 
00464   friend class Epetra_VbrMatrix;
00465 
00466   int LDA_;
00467   double* A_;
00468 
00469   bool UseTranspose_;
00470 };
00471 
00472 // inlined definitions of op() and op[]
00473 //=========================================================================
00474 inline double& Epetra_SerialDenseMatrix::operator () (int RowIndex, int ColIndex) {
00475 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
00476   if (RowIndex >= M_ || RowIndex < 0)
00477     throw ReportError("Row index = " +toString(RowIndex) + 
00478                       " Out of Range 0 - " + toString(M_-1),-1);
00479   if (ColIndex >= N_ || ColIndex < 0) 
00480     throw ReportError("Column index = " +toString(ColIndex) + 
00481                       " Out of Range 0 - " + toString(N_-1),-2);
00482 #endif
00483    return(A_[ColIndex*LDA_ + RowIndex]);
00484 }
00485 //=========================================================================
00486 inline const double& Epetra_SerialDenseMatrix::operator () (int RowIndex, int ColIndex) const {
00487 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
00488   if (RowIndex >= M_ || RowIndex < 0) 
00489     throw ReportError("Row index = " +toString(RowIndex) + 
00490                       " Out of Range 0 - " + toString(M_-1),-1);
00491   if (ColIndex >= N_ || ColIndex < 0) 
00492     throw ReportError("Column index = " +toString(ColIndex) + 
00493                       " Out of Range 0 - " + toString(N_-1),-2);
00494 #endif
00495   return(A_[ColIndex*LDA_ + RowIndex]);
00496 }
00497 //=========================================================================
00498 inline double* Epetra_SerialDenseMatrix::operator [] (int ColIndex) {
00499 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
00500   if (ColIndex >= N_ || ColIndex < 0) 
00501     throw ReportError("Column index = " +toString(ColIndex) + 
00502                       " Out of Range 0 - " + toString(N_-1),-2);
00503 #endif
00504   return(A_ + ColIndex*LDA_);
00505 }
00506 //=========================================================================
00507 inline const double* Epetra_SerialDenseMatrix::operator [] (int ColIndex) const {
00508 #ifdef HAVE_EPETRA_ARRAY_BOUNDS_CHECK
00509   if (ColIndex >= N_ || ColIndex < 0) 
00510     throw ReportError("Column index = " +toString(ColIndex) + 
00511                       " Out of Range 0 - " + toString(N_-1),-2);
00512 #endif
00513   return(A_+ ColIndex*LDA_);
00514 }
00515 //=========================================================================
00516 
00517 #endif /* EPETRA_SERIALDENSEMATRIX_H */

Generated on Thu Sep 18 12:37:58 2008 for Epetra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1