|
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 MATRIX_COMPOSITE_STD_H 00043 #define MATRIX_COMPOSITE_STD_H 00044 00045 #include <deque> 00046 00047 #include "AbstractLinAlgPack_MatrixOp.hpp" 00048 #include "AbstractLinAlgPack_GenPermMatrixSlice.hpp" 00049 #include "AbstractLinAlgPack_VectorSpace.hpp" 00050 #include "Teuchos_RCP.hpp" 00051 #include "ReleaseResource.hpp" 00052 00053 namespace AbstractLinAlgPack { 00054 00126 class MatrixComposite : public MatrixOp { 00127 public: 00128 00129 // /////////////////////////////////// 00130 // Public types 00131 00133 typedef Teuchos::RCP< 00134 MemMngPack::ReleaseResource> release_resource_ptr_t; 00135 00140 struct SubVectorEntry { 00142 typedef Teuchos::RCP<const GenPermMatrixSlice> GPMS_ptr_t; 00144 SubVectorEntry( 00145 size_type r_l, size_type c_l, value_type beta 00146 ,const Range1D& rng_G 00147 ,const GPMS_ptr_t& G, const release_resource_ptr_t& G_release, BLAS_Cpp::Transp G_trans 00148 ,const Vector* v 00149 ,const release_resource_ptr_t& v_release, BLAS_Cpp::Transp v_trans 00150 ) 00151 :r_l_(r_l),c_l_(c_l),beta_(beta),rng_G_(rng_G),G_(G),G_release_(G_release),G_trans_(G_trans) 00152 ,v_(v),v_release_(v_release),v_trans_(v_trans) 00153 {} 00155 bool operator==(const SubVectorEntry v) 00156 { 00157 return 00158 r_l_==v.r_l_ && c_l_==v.c_l_ && beta_==v.beta_ 00159 && rng_G_==v.rng_G_ && G_.get()==v.G_.get() && G_release_.get()==v.G_release_.get() && G_trans_==v.G_trans_ 00160 && v_==v.v_ && v_release_.get()==v.v_release_.get() && v_trans_==v.v_trans_; 00161 } 00163 size_type r_l_, 00164 c_l_; 00165 00166 value_type beta_; 00167 00168 Range1D rng_G_; 00169 00170 GPMS_ptr_t G_; 00171 00172 release_resource_ptr_t G_release_; 00174 BLAS_Cpp::Transp G_trans_; 00175 00176 const Vector *v_; 00177 00178 release_resource_ptr_t v_release_; 00180 BLAS_Cpp::Transp v_trans_; 00181 }; // end struct SubVectorEntry 00182 00184 typedef std::deque<SubVectorEntry> vector_list_t; 00185 00190 struct SubMatrixEntry { 00192 typedef Teuchos::RCP<const GenPermMatrixSlice> GPMS_ptr_t; 00194 SubMatrixEntry( 00195 size_type r_l, size_type r_u, size_type c_l, size_type c_u, value_type alpha 00196 ,const Range1D& rng_P 00197 ,const GPMS_ptr_t& P, const release_resource_ptr_t& P_release, BLAS_Cpp::Transp P_trans 00198 ,const MatrixOp* A, const release_resource_ptr_t& A_release, BLAS_Cpp::Transp A_trans 00199 ,const Range1D& rng_Q 00200 ,const GPMS_ptr_t& Q, const release_resource_ptr_t& Q_release, BLAS_Cpp::Transp Q_trans 00201 ) 00202 :r_l_(r_l),r_u_(r_u),c_l_(c_l),c_u_(c_u),alpha_(alpha),rng_P_(rng_P),P_(P),P_release_(P_release),P_trans_(P_trans) 00203 ,A_(A),A_release_(A_release),A_trans_(A_trans),rng_Q_(rng_Q),Q_(Q),Q_release_(Q_release),Q_trans_(Q_trans) 00204 {} 00206 bool operator==(const SubMatrixEntry m) 00207 { 00208 return 00209 r_l_==m.r_l_ && r_u_==m.r_u_ && c_l_==m.c_l_ && c_u_==m.c_u_ && alpha_==m.alpha_ 00210 && rng_P_==m.rng_P_ && P_.get()==m.P_.get() && P_release_.get()==m.P_release_.get() && P_trans_==m.P_trans_ 00211 && A_==m.A_ && A_release_.get()==m.A_release_.get() && A_trans_==m.A_trans_ 00212 && rng_Q_==m.rng_Q_ && Q_.get()==m.Q_.get() && Q_release_.get()==m.Q_release_.get() && Q_trans_==m.Q_trans_; 00213 } 00215 size_type r_l_, r_u_, c_l_, c_u_; 00217 value_type alpha_; 00219 Range1D rng_P_; // rng_P_.size() > 0 => P_ is ignored, rng_P_.full_range() => all rows op(A) 00221 GPMS_ptr_t P_; 00223 release_resource_ptr_t P_release_; 00225 BLAS_Cpp::Transp P_trans_; 00227 const MatrixOp *A_; 00229 release_resource_ptr_t A_release_; 00231 BLAS_Cpp::Transp A_trans_; 00233 Range1D rng_Q_; // rng_Q_.size() > 0 => Q_ is ignored, rng_Q_.full_range() => all columns op(A) 00235 GPMS_ptr_t Q_; 00237 release_resource_ptr_t Q_release_; 00239 BLAS_Cpp::Transp Q_trans_; 00240 }; // end struct SubMatrixEntry 00241 00243 typedef std::deque<SubMatrixEntry> matrix_list_t; 00244 00247 00252 MatrixComposite( size_type rows = 0, size_type cols = 0 ); 00253 00265 void reinitialize( size_type rows = 0, size_type cols = 0 ); 00266 00271 void add_vector( 00272 size_type row_offset 00273 ,size_type col_offset 00274 ,value_type beta 00275 ,const GenPermMatrixSlice *G 00276 ,const release_resource_ptr_t &G_release 00277 ,BLAS_Cpp::Transp G_trans 00278 ,const Vector *v 00279 ,const release_resource_ptr_t &v_release 00280 ,BLAS_Cpp::Transp v_trans 00281 ); 00282 00287 void add_vector( 00288 size_type row_offset 00289 ,size_type col_offset 00290 ,value_type beta 00291 ,const Range1D &rng_G 00292 ,const Vector *v 00293 ,const release_resource_ptr_t &v_release 00294 ,BLAS_Cpp::Transp v_trans 00295 ); 00296 00301 void add_vector( 00302 size_type row_offset 00303 ,size_type col_offset 00304 ,value_type beta 00305 ,const Vector *v 00306 ,const release_resource_ptr_t &v_release 00307 ,BLAS_Cpp::Transp v_trans 00308 ); 00309 00317 void remove_vector( vector_list_t::iterator itr ); 00318 00323 void add_matrix( 00324 size_type row_offset 00325 ,size_type col_offset 00326 ,value_type alpha 00327 ,const GenPermMatrixSlice *P 00328 ,const release_resource_ptr_t &P_release 00329 ,BLAS_Cpp::Transp P_trans 00330 ,const MatrixOp *A 00331 ,const release_resource_ptr_t &A_release 00332 ,BLAS_Cpp::Transp A_trans 00333 ,const GenPermMatrixSlice *Q 00334 ,const release_resource_ptr_t &Q_release 00335 ,BLAS_Cpp::Transp Q_trans 00336 ); 00337 00342 void add_matrix( 00343 size_type row_offset 00344 ,size_type col_offset 00345 ,value_type alpha 00346 ,const Range1D &rng_P 00347 ,const MatrixOp *A 00348 ,const release_resource_ptr_t &A_release 00349 ,BLAS_Cpp::Transp A_trans 00350 ,const Range1D &rng_Q 00351 ); 00352 00357 void add_matrix( 00358 size_type row_offset 00359 ,size_type col_offset 00360 ,value_type alpha 00361 ,const Range1D &rng_P 00362 ,const MatrixOp *A 00363 ,const release_resource_ptr_t &A_release 00364 ,BLAS_Cpp::Transp A_trans 00365 ,const GenPermMatrixSlice *Q 00366 ,const release_resource_ptr_t &Q_release 00367 ,BLAS_Cpp::Transp Q_trans 00368 ); 00369 00374 void add_matrix( 00375 size_type row_offset 00376 ,size_type col_offset 00377 ,value_type alpha 00378 ,const GenPermMatrixSlice *P 00379 ,const release_resource_ptr_t &P_release 00380 ,BLAS_Cpp::Transp P_trans 00381 ,const MatrixOp *A 00382 ,const release_resource_ptr_t &A_release 00383 ,BLAS_Cpp::Transp A_trans 00384 ,const Range1D &rng_Q 00385 ); 00386 00391 void add_matrix( 00392 size_type row_offset 00393 ,size_type col_offset 00394 ,value_type alpha 00395 ,const MatrixOp *A 00396 ,const release_resource_ptr_t &A_release 00397 ,BLAS_Cpp::Transp A_trans 00398 ); 00399 00404 void add_matrix( 00405 size_type row_offset 00406 ,size_type col_offset 00407 ,value_type alpha 00408 ,const GenPermMatrixSlice *P 00409 ,const release_resource_ptr_t &P_release 00410 ,BLAS_Cpp::Transp P_trans 00411 ); 00412 00420 void remove_matrix( matrix_list_t::iterator itr ); 00421 00452 virtual void finish_construction( 00453 const VectorSpace::space_ptr_t& space_cols 00454 ,const VectorSpace::space_ptr_t& space_rows 00455 ); 00456 00458 00461 00463 int num_vectors() const; 00465 vector_list_t::iterator vectors_begin(); 00467 vector_list_t::iterator vectors_end(); 00469 vector_list_t::const_iterator vectors_begin() const; 00471 vector_list_t::const_iterator vectors_end() const; 00473 int num_matrices() const; 00475 matrix_list_t::iterator matrices_begin(); 00477 matrix_list_t::iterator matrices_end(); 00479 matrix_list_t::const_iterator matrices_begin() const; 00481 matrix_list_t::const_iterator matrices_end() const; 00482 00484 00487 00489 size_type rows() const; 00491 size_type cols() const; 00493 size_type nz() const; 00494 00496 00499 00501 const VectorSpace& space_rows() const; 00503 const VectorSpace& space_cols() const; 00505 mat_ptr_t sub_view(const Range1D& row_rng, const Range1D& col_rng) const; 00507 void Vp_StMtV(VectorMutable* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1 00508 , const Vector& v_rhs2, value_type beta) const; 00510 void Vp_StMtV(VectorMutable* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1 00511 , const SpVectorSlice& sv_rhs2, value_type beta) const; 00513 void Vp_StPtMtV(VectorMutable* vs_lhs, value_type alpha 00514 , const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00515 , BLAS_Cpp::Transp M_rhs2_trans 00516 , const Vector& v_rhs3, value_type beta) const; 00518 void Vp_StPtMtV(VectorMutable* vs_lhs, value_type alpha 00519 , const GenPermMatrixSlice& P_rhs1, BLAS_Cpp::Transp P_rhs1_trans 00520 , BLAS_Cpp::Transp M_rhs2_trans 00521 , const SpVectorSlice& sv_rhs3, value_type beta) const; 00522 00524 00525 private: 00526 00527 // /////////////////////////////// 00528 // private data members 00529 00530 bool fully_constructed_; 00531 size_type rows_, cols_; 00532 #ifdef DOXYGEN_COMPILE 00533 MatrixOp *matrices; 00534 Vector *vectors; 00535 VectorSpace *space_cols; 00536 VectorSpace *space_rows; 00537 #else 00538 matrix_list_t matrix_list_; 00539 vector_list_t vector_list_; 00540 VectorSpace::space_ptr_t space_cols_; 00541 VectorSpace::space_ptr_t space_rows_; 00542 #endif 00543 00544 // /////////////////////////////// 00545 // private member functions 00546 00547 void assert_fully_constructed() const; 00548 00549 }; // end class MatrixComposite 00550 00551 } // end namespace AbstractLinAlgPack 00552 00553 #endif // MATRIX_COMPOSITE_STD_H
1.7.6.1