ConstrainedOptPack_MatrixGenBanded.cpp

Go to the documentation of this file.
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 #include <sstream>
00031 
00032 #include "ConstrainedOptPack_MatrixGenBanded.hpp"
00033 #include "DenseLinAlgPack_AssertOp.hpp"
00034 #include "DenseLinAlgPack_LinAlgOpPack.hpp"
00035 #include "DenseLinAlgPack_BLAS_Cpp.hpp"
00036 #include "MiWorkspacePack.h"
00037 
00038 namespace ConstrainedOptPack {
00039 
00040 MatrixGenBanded::MatrixGenBanded(
00041   size_type                         m
00042   ,size_type                        n
00043   ,size_type                        kl
00044   ,size_type                        ku
00045   ,DMatrixSlice                   *MB
00046   ,const release_resource_ptr_t&    MB_release_resource_ptr
00047   )
00048 {
00049   initialize(m,n,kl,ku,MB,MB_release_resource_ptr);
00050 }
00051 
00052 void MatrixGenBanded::initialize(
00053   size_type                         m
00054   ,size_type                        n
00055   ,size_type                        kl
00056   ,size_type                        ku
00057   ,DMatrixSlice                   *MB
00058   ,const release_resource_ptr_t&    MB_release_resource_ptr
00059   )
00060 {
00061   // Validate input
00062 
00063   if( m == 0 ) {
00064     if( n != 0 )
00065       throw std::invalid_argument(
00066         "MatrixGenBanded::initialize(...): Error, "
00067         "n must be 0 if m == 0" );
00068     if( kl != 0 )
00069       throw std::invalid_argument(
00070         "MatrixGenBanded::initialize(...): Error, "
00071         "kl must be 0 if m == 0" );
00072     if( ku != 0 )
00073       throw std::invalid_argument(
00074         "MatrixGenBanded::initialize(...): Error, "
00075         "ku must be 0 if m == 0" );
00076     if( MB != NULL )
00077       throw std::invalid_argument(
00078         "MatrixGenBanded::initialize(...): Error, "
00079         "MB must be NULL if m == 0" );
00080     if( MB_release_resource_ptr.get() != NULL )
00081       throw std::invalid_argument(
00082         "MatrixGenBanded::initialize(...): Error, "
00083         "MB_release_resource_ptr.get() must be NULL if m == 0" );
00084   }
00085   else {
00086     if( kl + 1 > m )
00087       throw std::invalid_argument(
00088         "MatrixGenBanded::initialize(...): Error, "
00089         "kl + 1 can not be larger than m" );
00090     if( ku + 1 > n )
00091       throw std::invalid_argument(
00092         "MatrixGenBanded::initialize(...): Error, "
00093         "ku + 1 can not be larger than n" );
00094     if( MB == NULL )
00095       throw std::invalid_argument(
00096         "MatrixGenBanded::initialize(...): Error, "
00097         "MB must not be NULL if n > 0" );
00098   }
00099 
00100   // Set the members
00101 
00102   if( m == 0 ) {
00103     m_                        = 0;
00104     n_                        = 0;
00105     kl_                       = 0;
00106     ku_                       = 0;
00107     MB_.bind(DMatrixSlice());
00108     MB_release_resource_ptr_  = NULL;
00109   }
00110   else {
00111     // Set the members
00112     m_                        = m;
00113     n_                        = n;
00114     kl_                       = kl;
00115     ku_                       = ku;
00116     MB_.bind(*MB);
00117   }
00118 }
00119 
00120 // Overridden from MatrixOp
00121 
00122 size_type MatrixGenBanded::rows() const
00123 {
00124   return m_;
00125 }
00126 
00127 size_type MatrixGenBanded::cols() const
00128 {
00129   return n_;
00130 }
00131 
00132 size_type MatrixGenBanded::nz() const
00133 {
00134   return (ku_ + kl_ + 1) * n_ - ( (ku_+1) * (ku_+1) - (ku_+1) )/2  - ( (kl_+1) * (kl_+1) - (kl_+1) )/2; // Is correct?
00135 }
00136 
00137 std::ostream& MatrixGenBanded::output(std::ostream& out) const
00138 {
00139   return MatrixOp::output(out); // ToDo: Implement specialized version later!
00140 }
00141 
00142 void MatrixGenBanded::Vp_StMtV(
00143   DVectorSlice* y, value_type a, BLAS_Cpp::Transp M_trans
00144   , const DVectorSlice& x, value_type b) const
00145 {
00146   assert_initialized();
00147   DenseLinAlgPack::Vp_MtV_assert_sizes( y->size(), n_, n_, BLAS_Cpp::no_trans, x.size() );
00148   BLAS_Cpp::gbmv(M_trans,m_,n_,kl_,ku_,a,MB_.col_ptr(1),MB_.max_rows(),x.raw_ptr(),x.stride()
00149            ,b,y->raw_ptr(),y->stride());
00150 }
00151 
00152 void MatrixGenBanded::Vp_StMtV(
00153   DVectorSlice* y, value_type a, BLAS_Cpp::Transp M_trans
00154   , const SpVectorSlice& x, value_type b) const
00155 {
00156   assert_initialized();
00157   MatrixOp::Vp_StMtV(y,a,M_trans,x,b); // ToDo: Implement spacialized operation when needed!
00158 }
00159 
00160 void MatrixGenBanded::Vp_StPtMtV(
00161   DVectorSlice* y, value_type a
00162   , const GenPermMatrixSlice& P, BLAS_Cpp::Transp P_trans
00163   , BLAS_Cpp::Transp M_trans
00164   , const DVectorSlice& x, value_type b) const
00165 {
00166   assert_initialized();
00167   MatrixOp::Vp_StPtMtV(y,a,P,P_trans,M_trans,x,b); // ToDo: Implement spacialized operation when needed!
00168 }
00169 
00170 void MatrixGenBanded::Vp_StPtMtV(
00171   DVectorSlice* y, value_type a
00172   , const GenPermMatrixSlice& P, BLAS_Cpp::Transp P_trans
00173   , BLAS_Cpp::Transp M_trans
00174   , const SpVectorSlice& x, value_type b) const
00175 {
00176   assert_initialized();
00177   MatrixOp::Vp_StPtMtV(y,a,P,P_trans,M_trans,x,b); // ToDo: Implement spacialized operation when needed!
00178 }
00179 
00180 // Private member functions
00181 
00182 void MatrixGenBanded::assert_initialized() const
00183 {
00184   if( m_ == 0 )
00185     throw std::logic_error("MatrixGenBanded::assert_initialized(): Error, "
00186                  "not initialized!" );
00187 }
00188 
00189 } // end namespace ConstrainedOptPack

Generated on Tue Oct 20 12:51:44 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7