AbstractLinAlgPack_MatrixBasisNonbasis.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 
00031 #include "AbstractLinAlgPack_MatrixBasisNonbasis.hpp"
00032 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_SpVectorClass.hpp"
00033 #include "DenseLinAlgPack_DVectorOp.hpp"
00034 #include "DenseLinAlgPack_DMatrixOp.hpp"
00035 #include "DenseLinAlgPack_AssertOp.hpp"
00036 
00037 namespace AbstractLinAlgPack {
00038 
00039 // Overridden from MatrixOp
00040 
00041 void MatrixBasisNonbasis::Vp_StMtV(DVectorSlice* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
00042     , const DVectorSlice& vs_rhs2, value_type beta) const
00043 {
00044   using AbstractLinAlgPack::Vp_StMtV;
00045 
00046   size_type n = rows(), m = cols();
00047 
00048   DenseLinAlgPack::Vp_MtV_assert_sizes( vs_lhs->size()
00049     , n, m, trans_rhs1, vs_rhs2.size() );
00050 
00051   switch(trans_rhs1) {
00052     case BLAS_Cpp::no_trans:
00053       //
00054       // M = [ C' ; N' ]
00055       //
00056       // y = b*y + a * M * x
00057       //
00058       // y = b*y + a * [ C' ] * x
00059       //               [ N' ]
00060       //
00061       // y(1:m)   = b*y(1:m)   + a * C' * x
00062       // y(m+1:n) = b*y(m+1:n) + a * N' * x
00063       
00064       // y(1:m)   = b*y(1:m)   + a * C' * x
00065       Vp_StMtV( &(*vs_lhs)(1,m), alpha, C(), BLAS_Cpp::trans, vs_rhs2, beta );
00066 
00067       // y(m+1:n) = b*y(m+1:n) + a * N' * x
00068       if( rows() > cols() )
00069         Vp_StMtV( &(*vs_lhs)(m+1,n), alpha, N(), BLAS_Cpp::trans, vs_rhs2, beta );
00070 
00071       break;
00072 
00073     case BLAS_Cpp::trans:
00074       //
00075       // M' = [ C , N ]
00076       //
00077       // y = b*y + a * M' * x
00078       //
00079       // y = b*y + a * [ C , N ] * [ x(1:m)   ]
00080       //                           [ x(m+1:n) ]
00081       //
00082       // y = b*y + a * C * x(1:m) + a * N * x(m+1:n)
00083 
00084       // y = b*y + a * C * x(1:m)
00085       Vp_StMtV( vs_lhs, alpha, C(), BLAS_Cpp::no_trans, vs_rhs2(1,m), beta );
00086       
00087       // y = y + a * N * x(m+1:n)
00088       if( rows() > cols() )
00089         Vp_StMtV( vs_lhs, alpha, N(), BLAS_Cpp::no_trans, vs_rhs2(m+1,n) );
00090 
00091       break;
00092 
00093     default:
00094       TEST_FOR_EXCEPT(true);
00095   }
00096 }
00097 
00098 void MatrixBasisNonbasis::Vp_StMtV(DVectorSlice* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
00099     , const SpVectorSlice& sv_rhs2, value_type beta) const
00100 {
00101   using AbstractLinAlgPack::Vp_StMtV;
00102 
00103   size_type n = rows(), m = cols();
00104   // Assert that the dimensions of the aruments match up and if not
00105   // then throw an excption.
00106   DenseLinAlgPack::Vp_MtV_assert_sizes( vs_lhs->size()
00107     , n, m, trans_rhs1, sv_rhs2.size() );
00108 
00109   switch(trans_rhs1) {
00110     case BLAS_Cpp::no_trans:
00111       //
00112       // M = [ C' ; N' ]
00113       //
00114       // y = b*y + a * M * x
00115       //
00116       // y = b*y + a * [ C' ] * x
00117       //               [ N' ]
00118       //
00119       // y(1:m)   = b*y(1:m)   + a * C' * x
00120       // y(m+1:n) = b*y(m+1:n) + a * N' * x
00121       
00122       // y(1:m)   = b*y(1:m)   + a * C' * x
00123       Vp_StMtV( &(*vs_lhs)(1,m), alpha, C(), BLAS_Cpp::trans, sv_rhs2, beta );
00124 
00125       // y(m+1:n) = b*y(m+1:n) + a * N' * x
00126       if( rows() > cols() )
00127         Vp_StMtV( &(*vs_lhs)(m+1,n), alpha, N(), BLAS_Cpp::trans, sv_rhs2, beta );
00128 
00129       break;
00130 
00131     case BLAS_Cpp::trans:
00132       //
00133       // M' = [ C , N ]
00134       //
00135       // y = b*y + a * M' * x
00136       //
00137       // y = b*y + a * [ C , N ] * [ x(1:m)   ]
00138       //                           [ x(m+1:n) ]
00139       //
00140       // y = b*y + a * C * x(1:m) + a * N * x(m+1:n)
00141 
00142       // y = b*y + a * C * x(1:m)
00143       Vp_StMtV( vs_lhs, alpha, C(), BLAS_Cpp::no_trans, sv_rhs2(1,m), beta );
00144       
00145       // y = y + a * N * x(m+1:n)
00146       if( rows() > cols() )
00147         Vp_StMtV( vs_lhs, alpha, N(), BLAS_Cpp::no_trans, sv_rhs2(m+1,n) );
00148 
00149       break;
00150 
00151     default:
00152       TEST_FOR_EXCEPT(true);
00153   }
00154 }
00155 
00156 } // end namespace AbstractLinAlgPack 

Generated on Thu Sep 18 12:35:11 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1