|
ConstrainedOptPack: C++ Tools for Constrained (and Unconstrained) Optimization 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 <limits> 00032 00033 #include "ConstrainedOptPack_MatrixSymIdentitySerial.hpp" 00034 #include "DenseLinAlgPack_DMatrixAsTriSym.hpp" 00035 #include "DenseLinAlgPack_DMatrixOp.hpp" 00036 #include "DenseLinAlgPack_DMatrixOut.hpp" 00037 #include "DenseLinAlgPack_LinAlgOpPack.hpp" 00038 #include "DenseLinAlgPack_AssertOp.hpp" 00039 00040 namespace ConstrainedOptPack { 00041 00042 // Constructors 00043 00044 MatrixSymIdentitySerial::MatrixSymIdentitySerial(size_type size, value_type scale) 00045 { 00046 this->initialize(size,scale); 00047 } 00048 00049 void MatrixSymIdentitySerial::initialize(size_type size, value_type scale) 00050 { 00051 size_ = size; 00052 scale_ = scale; 00053 } 00054 00055 // Overridden from MatrixBase 00056 00057 size_type MatrixSymIdentitySerial::rows() const 00058 { 00059 return size_; 00060 } 00061 00062 size_type MatrixSymIdentitySerial::nz() const 00063 { 00064 return size_; 00065 } 00066 00067 // Overridden from MatrixOp 00068 00069 std::ostream& MatrixSymIdentitySerial::output(std::ostream& out) const 00070 { 00071 out << "Identity matrix of size " << size_ << " x " << size_ << std::endl; 00072 return out; 00073 } 00074 00075 // Overridden from MatrixOpSerial 00076 00077 void MatrixSymIdentitySerial::Vp_StMtV( 00078 DVectorSlice* y, value_type a, BLAS_Cpp::Transp M_trans 00079 ,const DVectorSlice& x, value_type b 00080 ) const 00081 { 00082 DenseLinAlgPack::Vp_MtV_assert_sizes( y->dim(), rows(), cols(), BLAS_Cpp::no_trans, x.dim() ); 00083 DenseLinAlgPack::Vt_S(y,b); 00084 DenseLinAlgPack::Vp_StV(y,a*scale_,x); 00085 } 00086 00087 // Overridden from MatrixNonsinguarSerial 00088 00089 void MatrixSymIdentitySerial::V_InvMtV( 00090 DVectorSlice* y, BLAS_Cpp::Transp M_trans, const DVectorSlice& x 00091 ) const 00092 { 00093 DenseLinAlgPack::Vp_MtV_assert_sizes( y->dim(), rows(), cols(), BLAS_Cpp::no_trans, x.dim() ); 00094 LinAlgOpPack::V_StV(y,scale_,x); 00095 } 00096 00097 // Overridden from MatrixSymNonsing 00098 00099 void MatrixSymIdentitySerial::M_StMtInvMtM( 00100 DMatrixSliceSym* S, value_type a 00101 ,const MatrixOpSerial& B, BLAS_Cpp::Transp B_trans 00102 ,EMatrixDummyArg dummy_arg 00103 ) const 00104 { 00105 this->MatrixSymNonsingSerial::M_StMtInvMtM(S,a,B,B_trans,dummy_arg); 00106 // ToDo: Implement by calling S = b*S + scale*a*op(B')*op(B) 00107 } 00108 00109 // Overridden from MatrixExtractInvCholFactor 00110 00111 void MatrixSymIdentitySerial::extract_inv_chol( DMatrixSliceTriEle* InvChol ) const 00112 { 00113 if( scale_ < 0.0 ) 00114 throw std::logic_error( 00115 "MatrixSymIdentitySerial::extract_inv_chol(...) : " 00116 "Error, we can not compute the inverse cholesky factor " 00117 "of a negative definite matrix." ); 00118 DenseLinAlgPack::assign( &InvChol->gms(), 0.0 ); 00119 InvChol->gms().diag() = 1.0 / std::sqrt(scale_); 00120 } 00121 00122 } // end namespace ConstrainedOptPack
1.7.4