|
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 <assert.h> 00030 00031 #include "AbstractLinAlgPack_VectorSpaceSerial.hpp" 00032 #include "AbstractLinAlgPack_VectorSpaceFactorySerial.hpp" 00033 #include "AbstractLinAlgPack_VectorMutableDense.hpp" 00034 #include "AbstractLinAlgPack_MultiVectorMutableDense.hpp" 00035 #include "AbstractLinAlgPack_VectorMutable.hpp" 00036 #include "AbstractLinAlgPack_GenPermMatrixSlice.hpp" 00037 #include "DenseLinAlgPack_DVectorClass.hpp" 00038 #include "Teuchos_TestForException.hpp" 00039 00040 #ifdef TEUCHOS_DEBUG 00041 #define CLASS_MEMBER_PTRS \ 00042 const VectorSpaceSerial *_this = this; \ 00043 const size_type *_dim = &dim_; 00044 #else 00045 #define CLASS_MEMBER_PTRS 00046 #endif 00047 00048 namespace AbstractLinAlgPack { 00049 00050 VectorSpaceSerial::VectorSpaceSerial( size_type dim ) 00051 { 00052 CLASS_MEMBER_PTRS 00053 initialize(dim); 00054 } 00055 00056 void VectorSpaceSerial::initialize( size_type dim ) 00057 { 00058 CLASS_MEMBER_PTRS 00059 dim_ = dim; 00060 } 00061 00062 // Overridden from VectorSpace 00063 00064 bool VectorSpaceSerial::is_compatible(const VectorSpace& a_vec_space ) const 00065 { 00066 CLASS_MEMBER_PTRS 00067 return this->dim() == a_vec_space.dim() && a_vec_space.is_in_core(); 00068 } 00069 00070 bool VectorSpaceSerial::is_in_core() const 00071 { 00072 return true; 00073 } 00074 00075 index_type VectorSpaceSerial::dim() const 00076 { 00077 CLASS_MEMBER_PTRS 00078 return dim_; 00079 } 00080 00081 VectorSpace::space_fcty_ptr_t 00082 VectorSpaceSerial::small_vec_spc_fcty() const 00083 { 00084 CLASS_MEMBER_PTRS 00085 return Teuchos::rcp(new VectorSpaceFactorySerial()); 00086 } 00087 00088 VectorSpace::space_ptr_t 00089 VectorSpaceSerial::clone() const 00090 { 00091 CLASS_MEMBER_PTRS 00092 namespace mmp = MemMngPack; 00093 return Teuchos::rcp( new VectorSpaceSerial( dim_ ) ); 00094 } 00095 00096 VectorSpace::vec_mut_ptr_t 00097 VectorSpaceSerial::create_member() const 00098 { 00099 CLASS_MEMBER_PTRS 00100 namespace mmp = MemMngPack; 00101 return Teuchos::rcp(new VectorMutableDense(dim_)); 00102 } 00103 00104 VectorSpace::multi_vec_mut_ptr_t 00105 VectorSpaceSerial::create_members(size_type num_vecs) const 00106 { 00107 CLASS_MEMBER_PTRS 00108 namespace mmp = MemMngPack; 00109 return Teuchos::rcp(new MultiVectorMutableDense(dim_,num_vecs)); 00110 } 00111 00112 VectorSpace::space_ptr_t 00113 VectorSpaceSerial::sub_space(const Range1D& rng_in) const 00114 { 00115 CLASS_MEMBER_PTRS 00116 namespace mmp = MemMngPack; 00117 const size_type this_dim = this->dim(); 00118 const Range1D rng = RangePack::full_range( rng_in, 1, this_dim ); 00119 #ifdef TEUCHOS_DEBUG 00120 TEST_FOR_EXCEPTION( 00121 rng.ubound() > this_dim, std::out_of_range 00122 ,"VectorSpaceSerial::sub_view(...) : Error, " 00123 "rng = ["<<rng.lbound()<<","<<rng.ubound()<<"] " 00124 "is not in the range [1,this->dim()] = [1," << this_dim ); 00125 #endif 00126 if( rng == Range1D(1,this_dim) ) 00127 return Teuchos::rcp( this, false ); 00128 return Teuchos::rcp( new VectorSpaceSerial( rng.size() ) ); 00129 } 00130 00131 VectorSpace::space_ptr_t 00132 VectorSpaceSerial::space( 00133 const GenPermMatrixSlice &P 00134 ,BLAS_Cpp::Transp P_trans 00135 ) const 00136 { 00137 CLASS_MEMBER_PTRS 00138 return Teuchos::rcp( new VectorSpaceSerial( BLAS_Cpp::rows( P.rows(), P.cols(), P_trans ) ) ); 00139 } 00140 00141 } // end namespace AbstractLinAlgPack
1.7.4