AbstractLinAlgPack_MatrixOp.hpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef ABSTRACT_LINALG_PACK_MATRIX_WITH_OP_H
00030 #define ABSTRACT_LINALG_PACK_MATRIX_WITH_OP_H
00031 
00032 #include <iosfwd>
00033 
00034 #include "AbstractLinAlgPack_MatrixBase.hpp"
00035 #include "Teuchos_RefCountPtr.hpp"
00036 
00037 namespace AbstractLinAlgPack {
00038 
00116 class MatrixOp : public virtual MatrixBase {
00117 public:
00118 
00121 
00123   friend
00124   void Mt_S( MatrixOp* mwo_lhs, value_type alpha );
00126   friend
00127   void Mp_StM(
00128     MatrixOp* mwo_lhs, value_type alpha, const MatrixOp& M_rhs
00129     , BLAS_Cpp::Transp trans_rhs);
00131   friend
00132   void Mp_StMtP(
00133     MatrixOp* mwo_lhs, value_type alpha
00134     ,const MatrixOp& M_rhs, BLAS_Cpp::Transp M_trans
00135     ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans
00136     );
00138   friend
00139   void Mp_StPtM(
00140     MatrixOp* mwo_lhs, value_type alpha
00141     ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans
00142     ,const MatrixOp& M_rhs, BLAS_Cpp::Transp M_trans
00143     );
00145   friend
00146   void Mp_StPtMtP(
00147     MatrixOp* mwo_lhs, value_type alpha
00148     ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00149     ,const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs
00150     ,const GenPermMatrixSlice& P_rhs2, BLAS_Cpp::Transp P_rhs2_trans
00151     );
00153   friend
00154   void Vp_StMtV(
00155     VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1
00156     ,BLAS_Cpp::Transp trans_rhs1, const Vector& v_rhs2, value_type beta
00157     );
00159   friend
00160   void Vp_StMtV(
00161     VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1
00162     ,BLAS_Cpp::Transp trans_rhs1, const SpVectorSlice& sv_rhs2, value_type beta
00163     );
00165   friend
00166   void Vp_StPtMtV(
00167     VectorMutable* v_lhs, value_type alpha
00168     ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00169     ,const MatrixOp& M_rhs2, BLAS_Cpp::Transp M_rhs2_trans
00170     ,const Vector& v_rhs3, value_type beta
00171     );
00173   friend
00174   void Vp_StPtMtV(
00175     VectorMutable* v_lhs, value_type alpha
00176     ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00177     ,const MatrixOp& M_rhs2, BLAS_Cpp::Transp M_rhs2_trans
00178     ,const SpVectorSlice& sv_rhs3, value_type beta
00179     );
00181   friend
00182   value_type transVtMtV(
00183     const Vector& v_rhs1, const MatrixOp& M_rhs2
00184     ,BLAS_Cpp::Transp trans_rhs2, const Vector& v_rhs3
00185     );
00187   friend
00188   value_type transVtMtV(
00189     const SpVectorSlice& sv_rhs1, const MatrixOp& M_rhs2
00190     ,BLAS_Cpp::Transp trans_rhs2, const SpVectorSlice& sv_rhs3
00191     );
00193   friend
00194   void syr2k(
00195     const MatrixOp& M, BLAS_Cpp::Transp M_trans, value_type alpha
00196     ,const GenPermMatrixSlice& P1, BLAS_Cpp::Transp P1_trans
00197     ,const GenPermMatrixSlice& P2, BLAS_Cpp::Transp P2_trans
00198     ,value_type beta, MatrixSymOp* symwo_lhs
00199     );
00201   friend
00202   void Mp_StMtM(
00203     MatrixOp* mwo_lhs, value_type alpha
00204     ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1
00205     ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2
00206     ,value_type beta
00207     );
00209   friend
00210   void syrk(
00211     const MatrixOp  &mwo_rhs
00212     ,BLAS_Cpp::Transp   M_trans
00213     ,value_type         alpha
00214     ,value_type         beta
00215     ,MatrixSymOp    *sym_lhs
00216     );
00217 
00219 
00222 
00223 #ifndef DOXYGEN_COMPILE
00224 
00225   typedef Teuchos::RefCountPtr<const MatrixOp>    mat_ptr_t;
00227   typedef Teuchos::RefCountPtr<MatrixOp>          mat_mut_ptr_t;
00228 #endif
00229 
00231   enum EMatNormType {
00232     MAT_NORM_INF        
00233     ,MAT_NORM_2         
00234     ,MAT_NORM_1         
00235     ,MAT_NORM_FORB      
00236   };
00237 
00239   struct MatNorm {
00240     MatNorm(value_type _value, EMatNormType _type) : value(_value), type(_type) {}
00241     value_type    value;
00242     EMatNormType  type;
00243   };
00244 
00246   class MethodNotImplemented : public std::runtime_error
00247   {public: MethodNotImplemented(const std::string& what_arg) : std::runtime_error(what_arg) {}};
00248 
00250   class IncompatibleMatrices : public std::logic_error
00251   {public: IncompatibleMatrices(const std::string& what_arg) : std::logic_error(what_arg) {}};
00252 
00254 
00257 
00267   virtual void zero_out();
00268 
00277   virtual void Mt_S( value_type alpha );
00278 
00286   virtual MatrixOp& operator=(const MatrixOp& mwo_rhs);
00287 
00289 
00292 
00305   virtual mat_mut_ptr_t clone();
00306 
00312   virtual mat_ptr_t clone() const;
00313 
00315 
00318 
00325   virtual std::ostream& output(std::ostream& out) const;
00326 
00328 
00331 
00362   const MatNorm calc_norm(
00363     EMatNormType  requested_norm_type = MAT_NORM_1
00364     ,bool         allow_replacement   = false
00365     ) const;
00366 
00368 
00371 
00387   virtual mat_ptr_t sub_view(const Range1D& row_rng, const Range1D& col_rng) const;
00388   
00391   mat_ptr_t sub_view(
00392     const index_type& rl, const index_type& ru
00393     ,const index_type& cl, const index_type& cu
00394     ) const;
00395 
00397   
00400 
00441   virtual mat_ptr_t perm_view(
00442     const Permutation          *P_row
00443     ,const index_type          row_part[]
00444     ,int                       num_row_part
00445     ,const Permutation         *P_col
00446     ,const index_type          col_part[]
00447     ,int                       num_col_part
00448     ) const;
00449 
00479   virtual mat_ptr_t perm_view_update(
00480     const Permutation          *P_row
00481     ,const index_type          row_part[]
00482     ,int                       num_row_part
00483     ,const Permutation         *P_col
00484     ,const index_type          col_part[]
00485     ,int                       num_col_part
00486     ,const mat_ptr_t           &perm_view
00487     ) const;
00488 
00490 
00491 protected:
00492 
00495 
00503   virtual bool Mp_StM(
00504     MatrixOp* mwo_lhs, value_type alpha
00505     ,BLAS_Cpp::Transp trans_rhs
00506     ) const;
00507 
00515   virtual bool Mp_StM(
00516     value_type alpha,const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs
00517     );
00518 
00526   virtual bool Mp_StMtP(
00527     MatrixOp* mwo_lhs, value_type alpha
00528     ,BLAS_Cpp::Transp M_trans
00529     ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans
00530     ) const;
00531 
00539   virtual bool Mp_StMtP(
00540     value_type alpha
00541     ,const MatrixOp& mwo_rhs, BLAS_Cpp::Transp M_trans
00542     ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans
00543     );
00544 
00552   virtual bool Mp_StPtM(
00553     MatrixOp* mwo_lhs, value_type alpha
00554     ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans
00555     ,BLAS_Cpp::Transp M_trans
00556     ) const;
00557 
00565   virtual bool Mp_StPtM(
00566     value_type alpha
00567     ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans
00568     ,const MatrixOp& mwo_rhs, BLAS_Cpp::Transp M_trans
00569     );
00570 
00578   virtual bool Mp_StPtMtP(
00579     MatrixOp* mwo_lhs, value_type alpha
00580     ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00581     ,BLAS_Cpp::Transp M_trans
00582     ,const GenPermMatrixSlice& P_rhs2, BLAS_Cpp::Transp P_rhs2_trans
00583     ) const;
00584 
00592   virtual bool Mp_StPtMtP(
00593     value_type alpha
00594     ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00595     ,const MatrixOp& mwo_rhs, BLAS_Cpp::Transp M_trans
00596     ,const GenPermMatrixSlice& P_rhs2, BLAS_Cpp::Transp P_rhs2_trans
00597     );
00598 
00599   //    end Level-1 BLAS
00601 
00604 
00606   virtual void Vp_StMtV(
00607     VectorMutable* v_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
00608     ,const Vector& v_rhs2, value_type beta
00609     ) const = 0;
00610 
00612   virtual void Vp_StMtV(
00613     VectorMutable* v_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
00614     ,const SpVectorSlice& sv_rhs2, value_type beta
00615     ) const;
00616 
00618   virtual void Vp_StPtMtV(
00619     VectorMutable* v_lhs, value_type alpha
00620     ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00621     ,BLAS_Cpp::Transp M_rhs2_trans
00622     ,const Vector& v_rhs3, value_type beta
00623     ) const;
00624 
00626   virtual void Vp_StPtMtV(
00627     VectorMutable* v_lhs, value_type alpha
00628     ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00629     ,BLAS_Cpp::Transp M_rhs2_trans
00630     ,const SpVectorSlice& sv_rhs3, value_type beta
00631     ) const;
00632 
00634   virtual value_type transVtMtV(
00635     const Vector& v_rhs1, BLAS_Cpp::Transp trans_rhs2
00636     ,const Vector& v_rhs3
00637     ) const;
00638 
00640   virtual value_type transVtMtV(
00641     const SpVectorSlice& sv_rhs1, BLAS_Cpp::Transp trans_rhs2
00642     ,const SpVectorSlice& sv_rhs3
00643     ) const;
00644 
00656   virtual void syr2k(
00657     BLAS_Cpp::Transp M_trans, value_type alpha
00658     ,const GenPermMatrixSlice& P1, BLAS_Cpp::Transp P1_trans
00659     ,const GenPermMatrixSlice& P2, BLAS_Cpp::Transp P2_trans
00660     ,value_type beta, MatrixSymOp* symwo_lhs
00661     ) const;
00662 
00664 
00667 
00676   virtual bool Mp_StMtM(
00677     MatrixOp* mwo_lhs, value_type alpha
00678     ,BLAS_Cpp::Transp trans_rhs1
00679     ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2
00680     ,value_type beta
00681     ) const;
00682 
00691   virtual bool Mp_StMtM(
00692     MatrixOp* mwo_lhs, value_type alpha
00693     ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1
00694     ,BLAS_Cpp::Transp trans_rhs2
00695     ,value_type beta
00696     ) const;
00697 
00706   virtual bool Mp_StMtM(
00707     value_type alpha
00708     ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1
00709     ,const MatrixOp& mwo_rhs2,BLAS_Cpp::Transp trans_rhs2
00710     ,value_type beta
00711     );
00712   
00724   virtual bool syrk(
00725     BLAS_Cpp::Transp   M_trans
00726     ,value_type        alpha
00727     ,value_type        beta
00728     ,MatrixSymOp      *sym_lhs
00729     ) const;
00730   
00742   virtual bool syrk(
00743     const MatrixOp      &mwo_rhs
00744     ,BLAS_Cpp::Transp   M_trans
00745     ,value_type         alpha
00746     ,value_type         beta
00747     );
00748 
00749   //    end Level-3 BLAS
00751 
00752 };  // end class MatrixOp
00753 
00754 // ////////////////////////////////////////////////////////////////////////////////////////////////
00764 
00767 
00768 //
00775 void Mt_S( MatrixOp* mwo_lhs, value_type alpha );
00776 
00777 //
00792 void Mp_StM(
00793   MatrixOp* mwo_lhs, value_type alpha, const MatrixOp& M_rhs
00794   , BLAS_Cpp::Transp trans_rhs);
00795 
00802 void Mp_StMtP(
00803   MatrixOp* mwo_lhs, value_type alpha
00804   ,const MatrixOp& M_rhs, BLAS_Cpp::Transp M_trans
00805   ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans
00806   );
00807 
00814 void Mp_StPtM(
00815   MatrixOp* mwo_lhs, value_type alpha
00816   ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans
00817   ,const MatrixOp& M_rhs, BLAS_Cpp::Transp M_trans
00818   );
00819 
00826 void Mp_StPtMtP(
00827   MatrixOp* mwo_lhs, value_type alpha
00828   ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00829   ,const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs
00830   ,const GenPermMatrixSlice& P_rhs2, BLAS_Cpp::Transp P_rhs2_trans
00831   );
00832 
00833 //    end Level-1 BLAS
00835 
00838 
00840 inline void Vp_StMtV(
00841   VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1
00842   ,BLAS_Cpp::Transp trans_rhs1, const Vector& v_rhs2, value_type beta = 1.0
00843   )
00844 {
00845   M_rhs1.Vp_StMtV(v_lhs,alpha,trans_rhs1,v_rhs2,beta);
00846 }
00847 
00849 inline void Vp_StMtV(
00850   VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1
00851   ,BLAS_Cpp::Transp trans_rhs1, const SpVectorSlice& sv_rhs2, value_type beta = 1.0
00852   )
00853 {
00854   M_rhs1.Vp_StMtV(v_lhs,alpha,trans_rhs1,sv_rhs2,beta);
00855 }
00856 
00858 inline void Vp_StPtMtV(
00859   VectorMutable* v_lhs, value_type alpha
00860   ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00861   ,const MatrixOp& M_rhs2, BLAS_Cpp::Transp M_rhs2_trans
00862   ,const Vector& v_rhs3, value_type beta = 1.0
00863   ) 
00864 {
00865   M_rhs2.Vp_StPtMtV(v_lhs,alpha,P_rhs1,P_rhs1_trans,M_rhs2_trans,v_rhs3,beta);
00866 }
00867 
00869 inline void Vp_StPtMtV(
00870   VectorMutable* v_lhs, value_type alpha
00871   ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans
00872   ,const MatrixOp& M_rhs2, BLAS_Cpp::Transp M_rhs2_trans
00873   ,const SpVectorSlice& sv_rhs3, value_type beta = 1.0
00874   )
00875 {
00876   M_rhs2.Vp_StPtMtV(v_lhs,alpha,P_rhs1,P_rhs1_trans,M_rhs2_trans,sv_rhs3,beta);
00877 }
00878 
00880 inline value_type transVtMtV(
00881   const Vector& v_rhs1, const MatrixOp& M_rhs2
00882   ,BLAS_Cpp::Transp trans_rhs2, const Vector& v_rhs3
00883   )
00884 {
00885   return M_rhs2.transVtMtV(v_rhs1,trans_rhs2,v_rhs3);
00886 }
00887 
00889 inline value_type transVtMtV(
00890   const SpVectorSlice& sv_rhs1, const MatrixOp& M_rhs2
00891   ,BLAS_Cpp::Transp trans_rhs2, const SpVectorSlice& sv_rhs3
00892   )
00893 {
00894   return M_rhs2.transVtMtV(sv_rhs1,trans_rhs2,sv_rhs3);
00895 }
00896 
00898 inline void syr2k(
00899   const MatrixOp& M, BLAS_Cpp::Transp M_trans, value_type alpha
00900   ,const GenPermMatrixSlice& P1, BLAS_Cpp::Transp P1_trans
00901   ,const GenPermMatrixSlice& P2, BLAS_Cpp::Transp P2_trans
00902   ,value_type beta, MatrixSymOp* symwo_lhs
00903   )
00904 {
00905   M.syr2k(M_trans,alpha,P1,P1_trans,P2,P2_trans,beta,symwo_lhs);
00906 }
00907 
00908 //    end Level-2 BLAS
00910 
00913 
00926 void Mp_StMtM(
00927   MatrixOp* mwo_lhs, value_type alpha
00928   ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1
00929   ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2
00930   ,value_type beta = 1.0
00931   );
00932 
00939 void syrk(
00940   const MatrixOp  &mwo_rhs
00941   ,BLAS_Cpp::Transp   M_trans
00942   ,value_type         alpha
00943   ,value_type         beta
00944   ,MatrixSymOp    *sym_lhs
00945   );
00946 
00947 //    end Level-3 BLAS
00949 
00950 //    end non-member functions
00952 
00953 // //////////////////////////////////////////////////
00954 // Inlined methods for MatrixOp
00955 
00956 inline
00957 MatrixOp::mat_ptr_t
00958 MatrixOp::sub_view(
00959   const index_type& rl, const index_type& ru
00960   ,const index_type& cl, const index_type& cu
00961   ) const
00962 {
00963   return this->sub_view(Range1D(rl,ru),Range1D(cl,cu));
00964 }
00965 
00966 } // end namespace AbstractLinAlgPack
00967 
00968 #endif  // ABSTRACT_LINALG_PACK_MATRIX_WITH_OP_H

Generated on Thu Sep 18 12:33:51 2008 for AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects by doxygen 1.3.9.1