|
ConstrainedOptPack: C++ Tools for Constrained (and Unconstrained) Optimization Version of the Day
|
00001 #if 0 00002 00003 // @HEADER 00004 // *********************************************************************** 00005 // 00006 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00007 // Copyright (2003) Sandia Corporation 00008 // 00009 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00010 // license for use of this work by or on behalf of the U.S. Government. 00011 // 00012 // This library is free software; you can redistribute it and/or modify 00013 // it under the terms of the GNU Lesser General Public License as 00014 // published by the Free Software Foundation; either version 2.1 of the 00015 // License, or (at your option) any later version. 00016 // 00017 // This library is distributed in the hope that it will be useful, but 00018 // WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 // Lesser General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU Lesser General Public 00023 // License along with this library; if not, write to the Free Software 00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00025 // USA 00026 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00027 // 00028 // *********************************************************************** 00029 // @HEADER 00030 00031 #include <assert.h> 00032 #include <sstream> 00033 00034 #include "ConstrainedOptPack_MatrixGenBanded.hpp" 00035 #include "DenseLinAlgPack_AssertOp.hpp" 00036 #include "DenseLinAlgPack_LinAlgOpPack.hpp" 00037 #include "DenseLinAlgPack_BLAS_Cpp.hpp" 00038 #include "MiWorkspacePack.h" 00039 00040 namespace ConstrainedOptPack { 00041 00042 MatrixGenBanded::MatrixGenBanded( 00043 size_type m 00044 ,size_type n 00045 ,size_type kl 00046 ,size_type ku 00047 ,DMatrixSlice *MB 00048 ,const release_resource_ptr_t& MB_release_resource_ptr 00049 ) 00050 { 00051 initialize(m,n,kl,ku,MB,MB_release_resource_ptr); 00052 } 00053 00054 void MatrixGenBanded::initialize( 00055 size_type m 00056 ,size_type n 00057 ,size_type kl 00058 ,size_type ku 00059 ,DMatrixSlice *MB 00060 ,const release_resource_ptr_t& MB_release_resource_ptr 00061 ) 00062 { 00063 // Validate input 00064 00065 if( m == 0 ) { 00066 if( n != 0 ) 00067 throw std::invalid_argument( 00068 "MatrixGenBanded::initialize(...): Error, " 00069 "n must be 0 if m == 0" ); 00070 if( kl != 0 ) 00071 throw std::invalid_argument( 00072 "MatrixGenBanded::initialize(...): Error, " 00073 "kl must be 0 if m == 0" ); 00074 if( ku != 0 ) 00075 throw std::invalid_argument( 00076 "MatrixGenBanded::initialize(...): Error, " 00077 "ku must be 0 if m == 0" ); 00078 if( MB != NULL ) 00079 throw std::invalid_argument( 00080 "MatrixGenBanded::initialize(...): Error, " 00081 "MB must be NULL if m == 0" ); 00082 if( MB_release_resource_ptr.get() != NULL ) 00083 throw std::invalid_argument( 00084 "MatrixGenBanded::initialize(...): Error, " 00085 "MB_release_resource_ptr.get() must be NULL if m == 0" ); 00086 } 00087 else { 00088 if( kl + 1 > m ) 00089 throw std::invalid_argument( 00090 "MatrixGenBanded::initialize(...): Error, " 00091 "kl + 1 can not be larger than m" ); 00092 if( ku + 1 > n ) 00093 throw std::invalid_argument( 00094 "MatrixGenBanded::initialize(...): Error, " 00095 "ku + 1 can not be larger than n" ); 00096 if( MB == NULL ) 00097 throw std::invalid_argument( 00098 "MatrixGenBanded::initialize(...): Error, " 00099 "MB must not be NULL if n > 0" ); 00100 } 00101 00102 // Set the members 00103 00104 if( m == 0 ) { 00105 m_ = 0; 00106 n_ = 0; 00107 kl_ = 0; 00108 ku_ = 0; 00109 MB_.bind(DMatrixSlice()); 00110 MB_release_resource_ptr_ = NULL; 00111 } 00112 else { 00113 // Set the members 00114 m_ = m; 00115 n_ = n; 00116 kl_ = kl; 00117 ku_ = ku; 00118 MB_.bind(*MB); 00119 } 00120 } 00121 00122 // Overridden from MatrixOp 00123 00124 size_type MatrixGenBanded::rows() const 00125 { 00126 return m_; 00127 } 00128 00129 size_type MatrixGenBanded::cols() const 00130 { 00131 return n_; 00132 } 00133 00134 size_type MatrixGenBanded::nz() const 00135 { 00136 return (ku_ + kl_ + 1) * n_ - ( (ku_+1) * (ku_+1) - (ku_+1) )/2 - ( (kl_+1) * (kl_+1) - (kl_+1) )/2; // Is correct? 00137 } 00138 00139 std::ostream& MatrixGenBanded::output(std::ostream& out) const 00140 { 00141 return MatrixOp::output(out); // ToDo: Implement specialized version later! 00142 } 00143 00144 void MatrixGenBanded::Vp_StMtV( 00145 DVectorSlice* y, value_type a, BLAS_Cpp::Transp M_trans 00146 , const DVectorSlice& x, value_type b) const 00147 { 00148 assert_initialized(); 00149 DenseLinAlgPack::Vp_MtV_assert_sizes( y->size(), n_, n_, BLAS_Cpp::no_trans, x.size() ); 00150 BLAS_Cpp::gbmv(M_trans,m_,n_,kl_,ku_,a,MB_.col_ptr(1),MB_.max_rows(),x.raw_ptr(),x.stride() 00151 ,b,y->raw_ptr(),y->stride()); 00152 } 00153 00154 void MatrixGenBanded::Vp_StMtV( 00155 DVectorSlice* y, value_type a, BLAS_Cpp::Transp M_trans 00156 , const SpVectorSlice& x, value_type b) const 00157 { 00158 assert_initialized(); 00159 MatrixOp::Vp_StMtV(y,a,M_trans,x,b); // ToDo: Implement spacialized operation when needed! 00160 } 00161 00162 void MatrixGenBanded::Vp_StPtMtV( 00163 DVectorSlice* y, value_type a 00164 , const GenPermMatrixSlice& P, BLAS_Cpp::Transp P_trans 00165 , BLAS_Cpp::Transp M_trans 00166 , const DVectorSlice& x, value_type b) const 00167 { 00168 assert_initialized(); 00169 MatrixOp::Vp_StPtMtV(y,a,P,P_trans,M_trans,x,b); // ToDo: Implement spacialized operation when needed! 00170 } 00171 00172 void MatrixGenBanded::Vp_StPtMtV( 00173 DVectorSlice* y, value_type a 00174 , const GenPermMatrixSlice& P, BLAS_Cpp::Transp P_trans 00175 , BLAS_Cpp::Transp M_trans 00176 , const SpVectorSlice& x, value_type b) const 00177 { 00178 assert_initialized(); 00179 MatrixOp::Vp_StPtMtV(y,a,P,P_trans,M_trans,x,b); // ToDo: Implement spacialized operation when needed! 00180 } 00181 00182 // Private member functions 00183 00184 void MatrixGenBanded::assert_initialized() const 00185 { 00186 if( m_ == 0 ) 00187 throw std::logic_error("MatrixGenBanded::assert_initialized(): Error, " 00188 "not initialized!" ); 00189 } 00190 00191 } // end namespace ConstrainedOptPack 00192 00193 #endif // 0
1.7.4