|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects
Version of the Day
|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #ifndef ABSTRACT_LINALG_PACK_MATRIX_WITH_OP_H 00043 #define ABSTRACT_LINALG_PACK_MATRIX_WITH_OP_H 00044 00045 #include <iosfwd> 00046 00047 #include "AbstractLinAlgPack_MatrixBase.hpp" 00048 #include "Teuchos_RCP.hpp" 00049 00050 namespace AbstractLinAlgPack { 00051 00129 class MatrixOp : public virtual MatrixBase { 00130 public: 00131 00134 00136 friend 00137 void Mt_S( MatrixOp* mwo_lhs, value_type alpha ); 00139 friend 00140 void Mp_StM( 00141 MatrixOp* mwo_lhs, value_type alpha, const MatrixOp& M_rhs 00142 , BLAS_Cpp::Transp trans_rhs); 00144 friend 00145 void Mp_StMtP( 00146 MatrixOp* mwo_lhs, value_type alpha 00147 ,const MatrixOp& M_rhs, BLAS_Cpp::Transp M_trans 00148 ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans 00149 ); 00151 friend 00152 void Mp_StPtM( 00153 MatrixOp* mwo_lhs, value_type alpha 00154 ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans 00155 ,const MatrixOp& M_rhs, BLAS_Cpp::Transp M_trans 00156 ); 00158 friend 00159 void Mp_StPtMtP( 00160 MatrixOp* mwo_lhs, value_type alpha 00161 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00162 ,const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs 00163 ,const GenPermMatrixSlice& P_rhs2, BLAS_Cpp::Transp P_rhs2_trans 00164 ); 00166 friend 00167 void Vp_StMtV( 00168 VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1 00169 ,BLAS_Cpp::Transp trans_rhs1, const Vector& v_rhs2, value_type beta 00170 ); 00172 friend 00173 void Vp_StMtV( 00174 VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1 00175 ,BLAS_Cpp::Transp trans_rhs1, const SpVectorSlice& sv_rhs2, value_type beta 00176 ); 00178 friend 00179 void Vp_StPtMtV( 00180 VectorMutable* v_lhs, value_type alpha 00181 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00182 ,const MatrixOp& M_rhs2, BLAS_Cpp::Transp M_rhs2_trans 00183 ,const Vector& v_rhs3, value_type beta 00184 ); 00186 friend 00187 void Vp_StPtMtV( 00188 VectorMutable* v_lhs, value_type alpha 00189 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00190 ,const MatrixOp& M_rhs2, BLAS_Cpp::Transp M_rhs2_trans 00191 ,const SpVectorSlice& sv_rhs3, value_type beta 00192 ); 00194 friend 00195 value_type transVtMtV( 00196 const Vector& v_rhs1, const MatrixOp& M_rhs2 00197 ,BLAS_Cpp::Transp trans_rhs2, const Vector& v_rhs3 00198 ); 00200 friend 00201 value_type transVtMtV( 00202 const SpVectorSlice& sv_rhs1, const MatrixOp& M_rhs2 00203 ,BLAS_Cpp::Transp trans_rhs2, const SpVectorSlice& sv_rhs3 00204 ); 00206 friend 00207 void syr2k( 00208 const MatrixOp& M, BLAS_Cpp::Transp M_trans, value_type alpha 00209 ,const GenPermMatrixSlice& P1, BLAS_Cpp::Transp P1_trans 00210 ,const GenPermMatrixSlice& P2, BLAS_Cpp::Transp P2_trans 00211 ,value_type beta, MatrixSymOp* symwo_lhs 00212 ); 00214 friend 00215 void Mp_StMtM( 00216 MatrixOp* mwo_lhs, value_type alpha 00217 ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1 00218 ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2 00219 ,value_type beta 00220 ); 00222 friend 00223 void syrk( 00224 const MatrixOp &mwo_rhs 00225 ,BLAS_Cpp::Transp M_trans 00226 ,value_type alpha 00227 ,value_type beta 00228 ,MatrixSymOp *sym_lhs 00229 ); 00230 00232 00235 00236 #ifndef DOXYGEN_COMPILE 00237 00238 typedef Teuchos::RCP<const MatrixOp> mat_ptr_t; 00240 typedef Teuchos::RCP<MatrixOp> mat_mut_ptr_t; 00241 #endif 00242 00244 enum EMatNormType { 00245 MAT_NORM_INF 00246 ,MAT_NORM_2 00247 ,MAT_NORM_1 00248 ,MAT_NORM_FORB 00249 }; 00250 00252 struct MatNorm { 00253 MatNorm(value_type _value, EMatNormType _type) : value(_value), type(_type) {} 00254 value_type value; 00255 EMatNormType type; 00256 }; 00257 00259 class MethodNotImplemented : public std::runtime_error 00260 {public: MethodNotImplemented(const std::string& what_arg) : std::runtime_error(what_arg) {}}; 00261 00263 class IncompatibleMatrices : public std::logic_error 00264 {public: IncompatibleMatrices(const std::string& what_arg) : std::logic_error(what_arg) {}}; 00265 00267 00270 00280 virtual void zero_out(); 00281 00290 virtual void Mt_S( value_type alpha ); 00291 00299 virtual MatrixOp& operator=(const MatrixOp& mwo_rhs); 00300 00302 00305 00318 virtual mat_mut_ptr_t clone(); 00319 00325 virtual mat_ptr_t clone() const; 00326 00328 00331 00338 virtual std::ostream& output(std::ostream& out) const; 00339 00341 00344 00375 const MatNorm calc_norm( 00376 EMatNormType requested_norm_type = MAT_NORM_1 00377 ,bool allow_replacement = false 00378 ) const; 00379 00381 00384 00400 virtual mat_ptr_t sub_view(const Range1D& row_rng, const Range1D& col_rng) const; 00401 00404 mat_ptr_t sub_view( 00405 const index_type& rl, const index_type& ru 00406 ,const index_type& cl, const index_type& cu 00407 ) const; 00408 00410 00413 00454 virtual mat_ptr_t perm_view( 00455 const Permutation *P_row 00456 ,const index_type row_part[] 00457 ,int num_row_part 00458 ,const Permutation *P_col 00459 ,const index_type col_part[] 00460 ,int num_col_part 00461 ) const; 00462 00492 virtual mat_ptr_t perm_view_update( 00493 const Permutation *P_row 00494 ,const index_type row_part[] 00495 ,int num_row_part 00496 ,const Permutation *P_col 00497 ,const index_type col_part[] 00498 ,int num_col_part 00499 ,const mat_ptr_t &perm_view 00500 ) const; 00501 00503 00504 #ifdef TEMPLATE_FRIENDS_NOT_SUPPORTED 00505 public: 00506 #else 00507 protected: 00508 #endif 00509 00512 00520 virtual bool Mp_StM( 00521 MatrixOp* mwo_lhs, value_type alpha 00522 ,BLAS_Cpp::Transp trans_rhs 00523 ) const; 00524 00532 virtual bool Mp_StM( 00533 value_type alpha,const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs 00534 ); 00535 00543 virtual bool Mp_StMtP( 00544 MatrixOp* mwo_lhs, value_type alpha 00545 ,BLAS_Cpp::Transp M_trans 00546 ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans 00547 ) const; 00548 00556 virtual bool Mp_StMtP( 00557 value_type alpha 00558 ,const MatrixOp& mwo_rhs, BLAS_Cpp::Transp M_trans 00559 ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans 00560 ); 00561 00569 virtual bool Mp_StPtM( 00570 MatrixOp* mwo_lhs, value_type alpha 00571 ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans 00572 ,BLAS_Cpp::Transp M_trans 00573 ) const; 00574 00582 virtual bool Mp_StPtM( 00583 value_type alpha 00584 ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans 00585 ,const MatrixOp& mwo_rhs, BLAS_Cpp::Transp M_trans 00586 ); 00587 00595 virtual bool Mp_StPtMtP( 00596 MatrixOp* mwo_lhs, value_type alpha 00597 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00598 ,BLAS_Cpp::Transp M_trans 00599 ,const GenPermMatrixSlice& P_rhs2, BLAS_Cpp::Transp P_rhs2_trans 00600 ) const; 00601 00609 virtual bool Mp_StPtMtP( 00610 value_type alpha 00611 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00612 ,const MatrixOp& mwo_rhs, BLAS_Cpp::Transp M_trans 00613 ,const GenPermMatrixSlice& P_rhs2, BLAS_Cpp::Transp P_rhs2_trans 00614 ); 00615 00616 // end Level-1 BLAS 00618 00621 00623 virtual void Vp_StMtV( 00624 VectorMutable* v_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1 00625 ,const Vector& v_rhs2, value_type beta 00626 ) const = 0; 00627 00629 virtual void Vp_StMtV( 00630 VectorMutable* v_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1 00631 ,const SpVectorSlice& sv_rhs2, value_type beta 00632 ) const; 00633 00635 virtual void Vp_StPtMtV( 00636 VectorMutable* v_lhs, value_type alpha 00637 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00638 ,BLAS_Cpp::Transp M_rhs2_trans 00639 ,const Vector& v_rhs3, value_type beta 00640 ) const; 00641 00643 virtual void Vp_StPtMtV( 00644 VectorMutable* v_lhs, value_type alpha 00645 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00646 ,BLAS_Cpp::Transp M_rhs2_trans 00647 ,const SpVectorSlice& sv_rhs3, value_type beta 00648 ) const; 00649 00651 virtual value_type transVtMtV( 00652 const Vector& v_rhs1, BLAS_Cpp::Transp trans_rhs2 00653 ,const Vector& v_rhs3 00654 ) const; 00655 00657 virtual value_type transVtMtV( 00658 const SpVectorSlice& sv_rhs1, BLAS_Cpp::Transp trans_rhs2 00659 ,const SpVectorSlice& sv_rhs3 00660 ) const; 00661 00673 virtual void syr2k( 00674 BLAS_Cpp::Transp M_trans, value_type alpha 00675 ,const GenPermMatrixSlice& P1, BLAS_Cpp::Transp P1_trans 00676 ,const GenPermMatrixSlice& P2, BLAS_Cpp::Transp P2_trans 00677 ,value_type beta, MatrixSymOp* symwo_lhs 00678 ) const; 00679 00681 00684 00693 virtual bool Mp_StMtM( 00694 MatrixOp* mwo_lhs, value_type alpha 00695 ,BLAS_Cpp::Transp trans_rhs1 00696 ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2 00697 ,value_type beta 00698 ) const; 00699 00708 virtual bool Mp_StMtM( 00709 MatrixOp* mwo_lhs, value_type alpha 00710 ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1 00711 ,BLAS_Cpp::Transp trans_rhs2 00712 ,value_type beta 00713 ) const; 00714 00723 virtual bool Mp_StMtM( 00724 value_type alpha 00725 ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1 00726 ,const MatrixOp& mwo_rhs2,BLAS_Cpp::Transp trans_rhs2 00727 ,value_type beta 00728 ); 00729 00741 virtual bool syrk( 00742 BLAS_Cpp::Transp M_trans 00743 ,value_type alpha 00744 ,value_type beta 00745 ,MatrixSymOp *sym_lhs 00746 ) const; 00747 00759 virtual bool syrk( 00760 const MatrixOp &mwo_rhs 00761 ,BLAS_Cpp::Transp M_trans 00762 ,value_type alpha 00763 ,value_type beta 00764 ); 00765 00766 // end Level-3 BLAS 00768 00769 }; // end class MatrixOp 00770 00771 // //////////////////////////////////////////////////////////////////////////////////////////////// 00781 00784 00785 // 00792 void Mt_S( MatrixOp* mwo_lhs, value_type alpha ); 00793 00794 // 00809 void Mp_StM( 00810 MatrixOp* mwo_lhs, value_type alpha, const MatrixOp& M_rhs 00811 , BLAS_Cpp::Transp trans_rhs); 00812 00819 void Mp_StMtP( 00820 MatrixOp* mwo_lhs, value_type alpha 00821 ,const MatrixOp& M_rhs, BLAS_Cpp::Transp M_trans 00822 ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans 00823 ); 00824 00831 void Mp_StPtM( 00832 MatrixOp* mwo_lhs, value_type alpha 00833 ,const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans 00834 ,const MatrixOp& M_rhs, BLAS_Cpp::Transp M_trans 00835 ); 00836 00843 void Mp_StPtMtP( 00844 MatrixOp* mwo_lhs, value_type alpha 00845 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00846 ,const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs 00847 ,const GenPermMatrixSlice& P_rhs2, BLAS_Cpp::Transp P_rhs2_trans 00848 ); 00849 00850 // end Level-1 BLAS 00852 00855 00857 inline void Vp_StMtV( 00858 VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1 00859 ,BLAS_Cpp::Transp trans_rhs1, const Vector& v_rhs2, value_type beta = 1.0 00860 ) 00861 { 00862 M_rhs1.Vp_StMtV(v_lhs,alpha,trans_rhs1,v_rhs2,beta); 00863 } 00864 00866 inline void Vp_StMtV( 00867 VectorMutable* v_lhs, value_type alpha, const MatrixOp& M_rhs1 00868 ,BLAS_Cpp::Transp trans_rhs1, const SpVectorSlice& sv_rhs2, value_type beta = 1.0 00869 ) 00870 { 00871 M_rhs1.Vp_StMtV(v_lhs,alpha,trans_rhs1,sv_rhs2,beta); 00872 } 00873 00875 inline void Vp_StPtMtV( 00876 VectorMutable* v_lhs, value_type alpha 00877 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00878 ,const MatrixOp& M_rhs2, BLAS_Cpp::Transp M_rhs2_trans 00879 ,const Vector& v_rhs3, value_type beta = 1.0 00880 ) 00881 { 00882 M_rhs2.Vp_StPtMtV(v_lhs,alpha,P_rhs1,P_rhs1_trans,M_rhs2_trans,v_rhs3,beta); 00883 } 00884 00886 inline void Vp_StPtMtV( 00887 VectorMutable* v_lhs, value_type alpha 00888 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00889 ,const MatrixOp& M_rhs2, BLAS_Cpp::Transp M_rhs2_trans 00890 ,const SpVectorSlice& sv_rhs3, value_type beta = 1.0 00891 ) 00892 { 00893 M_rhs2.Vp_StPtMtV(v_lhs,alpha,P_rhs1,P_rhs1_trans,M_rhs2_trans,sv_rhs3,beta); 00894 } 00895 00897 inline value_type transVtMtV( 00898 const Vector& v_rhs1, const MatrixOp& M_rhs2 00899 ,BLAS_Cpp::Transp trans_rhs2, const Vector& v_rhs3 00900 ) 00901 { 00902 return M_rhs2.transVtMtV(v_rhs1,trans_rhs2,v_rhs3); 00903 } 00904 00906 inline value_type transVtMtV( 00907 const SpVectorSlice& sv_rhs1, const MatrixOp& M_rhs2 00908 ,BLAS_Cpp::Transp trans_rhs2, const SpVectorSlice& sv_rhs3 00909 ) 00910 { 00911 return M_rhs2.transVtMtV(sv_rhs1,trans_rhs2,sv_rhs3); 00912 } 00913 00915 inline void syr2k( 00916 const MatrixOp& M, BLAS_Cpp::Transp M_trans, value_type alpha 00917 ,const GenPermMatrixSlice& P1, BLAS_Cpp::Transp P1_trans 00918 ,const GenPermMatrixSlice& P2, BLAS_Cpp::Transp P2_trans 00919 ,value_type beta, MatrixSymOp* symwo_lhs 00920 ) 00921 { 00922 M.syr2k(M_trans,alpha,P1,P1_trans,P2,P2_trans,beta,symwo_lhs); 00923 } 00924 00925 // end Level-2 BLAS 00927 00930 00943 void Mp_StMtM( 00944 MatrixOp* mwo_lhs, value_type alpha 00945 ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1 00946 ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2 00947 ,value_type beta = 1.0 00948 ); 00949 00956 void syrk( 00957 const MatrixOp &mwo_rhs 00958 ,BLAS_Cpp::Transp M_trans 00959 ,value_type alpha 00960 ,value_type beta 00961 ,MatrixSymOp *sym_lhs 00962 ); 00963 00964 // end Level-3 BLAS 00966 00967 // end non-member functions 00969 00970 // ////////////////////////////////////////////////// 00971 // Inlined methods for MatrixOp 00972 00973 inline 00974 MatrixOp::mat_ptr_t 00975 MatrixOp::sub_view( 00976 const index_type& rl, const index_type& ru 00977 ,const index_type& cl, const index_type& cu 00978 ) const 00979 { 00980 return this->sub_view(Range1D(rl,ru),Range1D(cl,cu)); 00981 } 00982 00983 } // end namespace AbstractLinAlgPack 00984 00985 #endif // ABSTRACT_LINALG_PACK_MATRIX_WITH_OP_H
1.7.6.1