|
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 // 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 #include "AbstractLinAlgPack_MatrixOpNonsingAggr.hpp" 00030 #include "AbstractLinAlgPack_MatrixOpOut.hpp" 00031 #include "AbstractLinAlgPack_VectorSpace.hpp" 00032 #include "AbstractLinAlgPack_LinAlgOpPack.hpp" 00033 #include "Teuchos_TestForException.hpp" 00034 #include "Teuchos_dyn_cast.hpp" 00035 00036 namespace AbstractLinAlgPack { 00037 00038 // Constructors / initializers 00039 00040 MatrixOpNonsingAggr::MatrixOpNonsingAggr() 00041 {} // Nothing to explicitly initialize 00042 00043 MatrixOpNonsingAggr::MatrixOpNonsingAggr( 00044 const mwo_ptr_t &mwo 00045 ,BLAS_Cpp::Transp mwo_trans 00046 ,const mns_ptr_t &mns 00047 ,BLAS_Cpp::Transp mns_trans 00048 ) 00049 { 00050 this->initialize(mwo,mwo_trans,mns,mns_trans); 00051 } 00052 00053 void MatrixOpNonsingAggr::initialize( 00054 const mwo_ptr_t &mwo 00055 ,BLAS_Cpp::Transp mwo_trans 00056 ,const mns_ptr_t &mns 00057 ,BLAS_Cpp::Transp mns_trans 00058 ) 00059 { 00060 #ifdef TEUCHOS_DEBUG 00061 TEST_FOR_EXCEPTION( 00062 mwo.get() == NULL, std::invalid_argument 00063 ,"MatrixOpNonsingAggr::initialize(...): Error!" ); 00064 TEST_FOR_EXCEPTION( 00065 mns.get() == NULL, std::invalid_argument 00066 ,"MatrixOpNonsingAggr::initialize(...): Error!" ); 00067 const size_type 00068 mwo_rows = mwo->rows(), 00069 mwo_cols = mwo->cols(), 00070 mns_rows = mns->rows(), 00071 mns_cols = mns->cols(); 00072 TEST_FOR_EXCEPTION( 00073 mwo_rows != mwo_cols, std::invalid_argument 00074 ,"MatrixOpNonsingAggr::initialize(...): Error!" ); 00075 TEST_FOR_EXCEPTION( 00076 mns_rows != mns_cols, std::invalid_argument 00077 ,"MatrixOpNonsingAggr::initialize(...): Error!" ); 00078 TEST_FOR_EXCEPTION( 00079 mwo_rows != mns_rows, std::invalid_argument 00080 ,"MatrixOpNonsingAggr::initialize(...): Error!" ); 00081 #endif 00082 mwo_ = mwo; 00083 mwo_trans_ = mwo_trans; 00084 mns_ = mns; 00085 mns_trans_ = mns_trans; 00086 } 00087 00088 void MatrixOpNonsingAggr::set_uninitialized() 00089 { 00090 namespace rcp = MemMngPack; 00091 mwo_ = Teuchos::null; 00092 mwo_trans_ = BLAS_Cpp::no_trans; 00093 mns_ = Teuchos::null; 00094 mns_trans_ = BLAS_Cpp::no_trans; 00095 } 00096 00097 // Overridden from MatrixBase 00098 00099 size_type MatrixOpNonsingAggr::rows() const 00100 { 00101 return mwo_.get() ? mwo_->rows() : 0; // square matrix! 00102 } 00103 00104 size_type MatrixOpNonsingAggr::cols() const 00105 { 00106 return mwo_.get() ? mwo_->rows() : 0; // square matrix! 00107 } 00108 00109 size_type MatrixOpNonsingAggr::nz() const 00110 { 00111 return mwo_.get() ? mwo_->nz() : 0; 00112 } 00113 00114 // Overridden from MatrixOp 00115 00116 const VectorSpace& MatrixOpNonsingAggr::space_cols() const 00117 { 00118 return mwo_trans_ == BLAS_Cpp::no_trans ? mwo_->space_cols() : mwo_->space_rows(); 00119 } 00120 00121 const VectorSpace& MatrixOpNonsingAggr::space_rows() const 00122 { 00123 return mwo_trans_ == BLAS_Cpp::no_trans ? mwo_->space_rows() : mwo_->space_cols(); 00124 } 00125 00126 MatrixOp::mat_ptr_t 00127 MatrixOpNonsingAggr::sub_view(const Range1D& row_rng, const Range1D& col_rng) const 00128 { 00129 return MatrixOp::sub_view(row_rng,col_rng); // ToDo: Speicalize! 00130 } 00131 00132 MatrixOp& MatrixOpNonsingAggr::operator=(const MatrixOp& M) 00133 { 00134 using Teuchos::dyn_cast; 00135 const MatrixOpNonsingAggr 00136 Mp = dyn_cast<const MatrixOpNonsingAggr>(M); 00137 if( this == &Mp ) 00138 return *this; // Assignment to self 00139 // Shallow copy is okay as long as client is careful! 00140 mwo_ = Mp.mwo_; 00141 mwo_trans_ = Mp.mwo_trans_; 00142 mns_ = Mp.mns_; 00143 mns_trans_ = Mp.mns_trans_; 00144 return *this; 00145 } 00146 00147 std::ostream& MatrixOpNonsingAggr::output(std::ostream& out) const 00148 { 00149 out << "Aggregate nonsingular matrix:\n"; 00150 out << (mwo_trans_ == BLAS_Cpp::no_trans ? "mwo" : "mwo\'") << " =\n" << *mwo_; 00151 out << (mns_trans_ == BLAS_Cpp::no_trans ? "mns" : "mns\'") << " = ???\n"; 00152 return out; 00153 } 00154 00155 bool MatrixOpNonsingAggr::Mp_StM( 00156 MatrixOp* mwo_lhs, value_type alpha 00157 , BLAS_Cpp::Transp trans_rhs) const 00158 { 00159 AbstractLinAlgPack::Mp_StM(mwo_lhs,alpha,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,trans_rhs)); 00160 return true; 00161 } 00162 00163 bool MatrixOpNonsingAggr::Mp_StMtP( 00164 MatrixOp* mwo_lhs, value_type alpha 00165 , BLAS_Cpp::Transp M_trans 00166 , const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans 00167 ) const 00168 { 00169 AbstractLinAlgPack::Mp_StMtP( 00170 mwo_lhs,alpha,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,M_trans) 00171 ,P_rhs,P_rhs_trans); 00172 return true; 00173 } 00174 00175 bool MatrixOpNonsingAggr::Mp_StPtM( 00176 MatrixOp* mwo_lhs, value_type alpha 00177 , const GenPermMatrixSlice& P_rhs, BLAS_Cpp::Transp P_rhs_trans 00178 , BLAS_Cpp::Transp M_trans 00179 ) const 00180 { 00181 AbstractLinAlgPack::Mp_StPtM( 00182 mwo_lhs,alpha,P_rhs,P_rhs_trans 00183 ,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,M_trans)); 00184 return true; 00185 } 00186 00187 bool MatrixOpNonsingAggr::Mp_StPtMtP( 00188 MatrixOp* mwo_lhs, value_type alpha 00189 ,const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00190 ,BLAS_Cpp::Transp M_trans 00191 ,const GenPermMatrixSlice& P_rhs2, BLAS_Cpp::Transp P_rhs2_trans 00192 ) const 00193 { 00194 AbstractLinAlgPack::Mp_StPtMtP( 00195 mwo_lhs,alpha,P_rhs1,P_rhs1_trans 00196 ,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,M_trans) 00197 ,P_rhs2,P_rhs2_trans); 00198 return true; 00199 } 00200 00201 void MatrixOpNonsingAggr::Vp_StMtV( 00202 VectorMutable* y, value_type a, BLAS_Cpp::Transp M_trans 00203 , const Vector& x, value_type b) const 00204 { 00205 AbstractLinAlgPack::Vp_StMtV(y,a,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,M_trans),x,b); 00206 } 00207 00208 void MatrixOpNonsingAggr::Vp_StMtV( 00209 VectorMutable* y, value_type a, BLAS_Cpp::Transp M_trans 00210 , const SpVectorSlice& x, value_type b) const 00211 { 00212 AbstractLinAlgPack::Vp_StMtV(y,a,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,M_trans),x,b); 00213 } 00214 00215 void MatrixOpNonsingAggr::Vp_StPtMtV( 00216 VectorMutable* vs_lhs, value_type alpha 00217 , const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00218 , BLAS_Cpp::Transp M_rhs2_trans 00219 , const Vector& v_rhs3, value_type beta) const 00220 { 00221 AbstractLinAlgPack::Vp_StPtMtV( 00222 vs_lhs,alpha,P_rhs1,P_rhs1_trans 00223 ,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,M_rhs2_trans) 00224 ,v_rhs3,beta); 00225 } 00226 00227 void MatrixOpNonsingAggr::Vp_StPtMtV( 00228 VectorMutable* vs_lhs, value_type alpha 00229 , const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00230 , BLAS_Cpp::Transp M_rhs2_trans 00231 , const SpVectorSlice& sv_rhs3, value_type beta) const 00232 { 00233 AbstractLinAlgPack::Vp_StPtMtV( 00234 vs_lhs,alpha,P_rhs1,P_rhs1_trans 00235 ,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,M_rhs2_trans) 00236 ,sv_rhs3,beta); 00237 } 00238 00239 value_type MatrixOpNonsingAggr::transVtMtV( 00240 const Vector& v_rhs1, BLAS_Cpp::Transp trans_rhs2 00241 , const Vector& v_rhs3) const 00242 { 00243 return AbstractLinAlgPack::transVtMtV(v_rhs1,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,trans_rhs2),v_rhs3); 00244 } 00245 00246 value_type MatrixOpNonsingAggr::transVtMtV( 00247 const SpVectorSlice& sv_rhs1, BLAS_Cpp::Transp trans_rhs2 00248 ,const SpVectorSlice& sv_rhs3 00249 ) const 00250 { 00251 return AbstractLinAlgPack::transVtMtV(sv_rhs1,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,trans_rhs2),sv_rhs3); 00252 } 00253 00254 void MatrixOpNonsingAggr::syr2k( 00255 BLAS_Cpp::Transp M_trans, value_type alpha 00256 ,const GenPermMatrixSlice& P1, BLAS_Cpp::Transp P1_trans 00257 ,const GenPermMatrixSlice& P2, BLAS_Cpp::Transp P2_trans 00258 ,value_type beta, MatrixSymOp* symwo_lhs 00259 ) const 00260 { 00261 AbstractLinAlgPack::syr2k( 00262 *mwo_,BLAS_Cpp::trans_trans(mwo_trans_,M_trans) 00263 ,alpha,P1,P1_trans,P2,P2_trans,beta,symwo_lhs); 00264 } 00265 00266 bool MatrixOpNonsingAggr::Mp_StMtM( 00267 MatrixOp* mwo_lhs, value_type alpha 00268 ,BLAS_Cpp::Transp trans_rhs1, const MatrixOp& mwo_rhs2 00269 ,BLAS_Cpp::Transp trans_rhs2, value_type beta 00270 ) const 00271 { 00272 AbstractLinAlgPack::Mp_StMtM( 00273 mwo_lhs,alpha,*mwo_,trans_rhs1 00274 ,mwo_rhs2,BLAS_Cpp::trans_trans(mwo_trans_,trans_rhs2),beta); 00275 return true; 00276 } 00277 00278 bool MatrixOpNonsingAggr::Mp_StMtM( 00279 MatrixOp* mwo_lhs, value_type alpha 00280 ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1 00281 ,BLAS_Cpp::Transp trans_rhs2, value_type beta 00282 ) const 00283 { 00284 AbstractLinAlgPack::Mp_StMtM( 00285 mwo_lhs,alpha,mwo_rhs1,trans_rhs1 00286 ,*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,trans_rhs2),beta); 00287 return true; 00288 } 00289 00290 bool MatrixOpNonsingAggr::syrk( 00291 BLAS_Cpp::Transp M_trans, value_type alpha 00292 ,value_type beta, MatrixSymOp* sym_lhs 00293 ) const 00294 { 00295 AbstractLinAlgPack::syrk(*mwo_,BLAS_Cpp::trans_trans(mwo_trans_,M_trans),alpha,beta,sym_lhs); 00296 return true; 00297 } 00298 00299 // Overridden from MatrixNonsing */ 00300 00301 void MatrixOpNonsingAggr::V_InvMtV( 00302 VectorMutable* v_lhs, BLAS_Cpp::Transp trans_rhs1 00303 ,const Vector& v_rhs2 00304 ) const 00305 { 00306 AbstractLinAlgPack::V_InvMtV(v_lhs,*mns_,BLAS_Cpp::trans_trans(mns_trans_,trans_rhs1),v_rhs2); 00307 } 00308 00309 void MatrixOpNonsingAggr::V_InvMtV( 00310 VectorMutable* v_lhs, BLAS_Cpp::Transp trans_rhs1 00311 ,const SpVectorSlice& sv_rhs2 00312 ) const 00313 { 00314 AbstractLinAlgPack::V_InvMtV(v_lhs,*mns_,BLAS_Cpp::trans_trans(mns_trans_,trans_rhs1),sv_rhs2); 00315 } 00316 00317 value_type MatrixOpNonsingAggr::transVtInvMtV( 00318 const Vector& v_rhs1 00319 ,BLAS_Cpp::Transp trans_rhs2, const Vector& v_rhs3 00320 ) const 00321 { 00322 return AbstractLinAlgPack::transVtInvMtV(v_rhs1,*mns_,BLAS_Cpp::trans_trans(mns_trans_,trans_rhs2),v_rhs3); 00323 } 00324 00325 value_type MatrixOpNonsingAggr::transVtInvMtV( 00326 const SpVectorSlice& sv_rhs1 00327 ,BLAS_Cpp::Transp trans_rhs2, const SpVectorSlice& sv_rhs3 00328 ) const 00329 { 00330 return AbstractLinAlgPack::transVtInvMtV(sv_rhs1,*mns_,BLAS_Cpp::trans_trans(mns_trans_,trans_rhs2),sv_rhs3); 00331 } 00332 00333 void MatrixOpNonsingAggr::M_StInvMtM( 00334 MatrixOp* m_lhs, value_type alpha 00335 ,BLAS_Cpp::Transp trans_rhs1 00336 ,const MatrixOp& mwo_rhs2, BLAS_Cpp::Transp trans_rhs2 00337 ) const 00338 { 00339 AbstractLinAlgPack::M_StInvMtM(m_lhs,alpha,*mns_,BLAS_Cpp::trans_trans(mns_trans_,trans_rhs1),mwo_rhs2,trans_rhs2); 00340 } 00341 00342 void MatrixOpNonsingAggr::M_StMtInvM( 00343 MatrixOp* m_lhs, value_type alpha 00344 ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1 00345 ,BLAS_Cpp::Transp trans_rhs2 00346 ) const 00347 { 00348 AbstractLinAlgPack::M_StMtInvM(m_lhs,alpha,mwo_rhs1,trans_rhs1,*mns_,BLAS_Cpp::trans_trans(mns_trans_,trans_rhs1)); 00349 } 00350 00351 } // end namespace AbstractLinAlgPack
1.7.4