ConstrainedOptPack: C++ Tools for Constrained (and Unconstrained) Optimization Version of the Day
ConstrainedOptPack_MatrixGenBanded.cpp
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 // Redistribution and use in source and binary forms, with or without
00013 // modification, are permitted provided that the following conditions are
00014 // met:
00015 //
00016 // 1. Redistributions of source code must retain the above copyright
00017 // notice, this list of conditions and the following disclaimer.
00018 //
00019 // 2. Redistributions in binary form must reproduce the above copyright
00020 // notice, this list of conditions and the following disclaimer in the
00021 // documentation and/or other materials provided with the distribution.
00022 //
00023 // 3. Neither the name of the Corporation nor the names of the
00024 // contributors may be used to endorse or promote products derived from
00025 // this software without specific prior written permission.
00026 //
00027 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00028 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00031 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00036 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 //
00039 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00040 // 
00041 // ***********************************************************************
00042 // @HEADER
00043 
00044 #include <assert.h>
00045 #include <sstream>
00046 
00047 #include "ConstrainedOptPack_MatrixGenBanded.hpp"
00048 #include "DenseLinAlgPack_AssertOp.hpp"
00049 #include "DenseLinAlgPack_LinAlgOpPack.hpp"
00050 #include "DenseLinAlgPack_BLAS_Cpp.hpp"
00051 #include "MiWorkspacePack.h"
00052 
00053 namespace ConstrainedOptPack {
00054 
00055 MatrixGenBanded::MatrixGenBanded(
00056   size_type                         m
00057   ,size_type                        n
00058   ,size_type                        kl
00059   ,size_type                        ku
00060   ,DMatrixSlice                   *MB
00061   ,const release_resource_ptr_t&    MB_release_resource_ptr
00062   )
00063 {
00064   initialize(m,n,kl,ku,MB,MB_release_resource_ptr);
00065 }
00066 
00067 void MatrixGenBanded::initialize(
00068   size_type                         m
00069   ,size_type                        n
00070   ,size_type                        kl
00071   ,size_type                        ku
00072   ,DMatrixSlice                   *MB
00073   ,const release_resource_ptr_t&    MB_release_resource_ptr
00074   )
00075 {
00076   // Validate input
00077 
00078   if( m == 0 ) {
00079     if( n != 0 )
00080       throw std::invalid_argument(
00081         "MatrixGenBanded::initialize(...): Error, "
00082         "n must be 0 if m == 0" );
00083     if( kl != 0 )
00084       throw std::invalid_argument(
00085         "MatrixGenBanded::initialize(...): Error, "
00086         "kl must be 0 if m == 0" );
00087     if( ku != 0 )
00088       throw std::invalid_argument(
00089         "MatrixGenBanded::initialize(...): Error, "
00090         "ku must be 0 if m == 0" );
00091     if( MB != NULL )
00092       throw std::invalid_argument(
00093         "MatrixGenBanded::initialize(...): Error, "
00094         "MB must be NULL if m == 0" );
00095     if( MB_release_resource_ptr.get() != NULL )
00096       throw std::invalid_argument(
00097         "MatrixGenBanded::initialize(...): Error, "
00098         "MB_release_resource_ptr.get() must be NULL if m == 0" );
00099   }
00100   else {
00101     if( kl + 1 > m )
00102       throw std::invalid_argument(
00103         "MatrixGenBanded::initialize(...): Error, "
00104         "kl + 1 can not be larger than m" );
00105     if( ku + 1 > n )
00106       throw std::invalid_argument(
00107         "MatrixGenBanded::initialize(...): Error, "
00108         "ku + 1 can not be larger than n" );
00109     if( MB == NULL )
00110       throw std::invalid_argument(
00111         "MatrixGenBanded::initialize(...): Error, "
00112         "MB must not be NULL if n > 0" );
00113   }
00114 
00115   // Set the members
00116 
00117   if( m == 0 ) {
00118     m_                        = 0;
00119     n_                        = 0;
00120     kl_                       = 0;
00121     ku_                       = 0;
00122     MB_.bind(DMatrixSlice());
00123     MB_release_resource_ptr_  = NULL;
00124   }
00125   else {
00126     // Set the members
00127     m_                        = m;
00128     n_                        = n;
00129     kl_                       = kl;
00130     ku_                       = ku;
00131     MB_.bind(*MB);
00132   }
00133 }
00134 
00135 // Overridden from MatrixOp
00136 
00137 size_type MatrixGenBanded::rows() const
00138 {
00139   return m_;
00140 }
00141 
00142 size_type MatrixGenBanded::cols() const
00143 {
00144   return n_;
00145 }
00146 
00147 size_type MatrixGenBanded::nz() const
00148 {
00149   return (ku_ + kl_ + 1) * n_ - ( (ku_+1) * (ku_+1) - (ku_+1) )/2  - ( (kl_+1) * (kl_+1) - (kl_+1) )/2; // Is correct?
00150 }
00151 
00152 std::ostream& MatrixGenBanded::output(std::ostream& out) const
00153 {
00154   return MatrixOp::output(out); // ToDo: Implement specialized version later!
00155 }
00156 
00157 void MatrixGenBanded::Vp_StMtV(
00158   DVectorSlice* y, value_type a, BLAS_Cpp::Transp M_trans
00159   , const DVectorSlice& x, value_type b) const
00160 {
00161   assert_initialized();
00162   DenseLinAlgPack::Vp_MtV_assert_sizes( y->size(), n_, n_, BLAS_Cpp::no_trans, x.size() );
00163   BLAS_Cpp::gbmv(M_trans,m_,n_,kl_,ku_,a,MB_.col_ptr(1),MB_.max_rows(),x.raw_ptr(),x.stride()
00164            ,b,y->raw_ptr(),y->stride());
00165 }
00166 
00167 void MatrixGenBanded::Vp_StMtV(
00168   DVectorSlice* y, value_type a, BLAS_Cpp::Transp M_trans
00169   , const SpVectorSlice& x, value_type b) const
00170 {
00171   assert_initialized();
00172   MatrixOp::Vp_StMtV(y,a,M_trans,x,b); // ToDo: Implement spacialized operation when needed!
00173 }
00174 
00175 void MatrixGenBanded::Vp_StPtMtV(
00176   DVectorSlice* y, value_type a
00177   , const GenPermMatrixSlice& P, BLAS_Cpp::Transp P_trans
00178   , BLAS_Cpp::Transp M_trans
00179   , const DVectorSlice& x, value_type b) const
00180 {
00181   assert_initialized();
00182   MatrixOp::Vp_StPtMtV(y,a,P,P_trans,M_trans,x,b); // ToDo: Implement spacialized operation when needed!
00183 }
00184 
00185 void MatrixGenBanded::Vp_StPtMtV(
00186   DVectorSlice* y, value_type a
00187   , const GenPermMatrixSlice& P, BLAS_Cpp::Transp P_trans
00188   , BLAS_Cpp::Transp M_trans
00189   , const SpVectorSlice& x, value_type b) const
00190 {
00191   assert_initialized();
00192   MatrixOp::Vp_StPtMtV(y,a,P,P_trans,M_trans,x,b); // ToDo: Implement spacialized operation when needed!
00193 }
00194 
00195 // Private member functions
00196 
00197 void MatrixGenBanded::assert_initialized() const
00198 {
00199   if( m_ == 0 )
00200     throw std::logic_error("MatrixGenBanded::assert_initialized(): Error, "
00201                  "not initialized!" );
00202 }
00203 
00204 } // end namespace ConstrainedOptPack
00205 
00206 #endif // 0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends