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