AbstractLinAlgPack_LinAlgOpPackHack.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 
00030 #include "AbstractLinAlgPack_LinAlgOpPackHack.hpp"
00031 #include "AbstractLinAlgPack_VectorMutableDense.hpp"
00032 #include "AbstractLinAlgPack_VectorDenseEncap.hpp"
00033 #include "AbstractLinAlgPack_MatrixOpGetGMS.hpp"
00034 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp"
00035 #include "AbstractLinAlgPack_MultiVectorMutable.hpp"
00036 #include "AbstractLinAlgPack_VectorMutable.hpp"
00037 #include "AbstractLinAlgPack_VectorSpace.hpp"
00038 #include "AbstractLinAlgPack_GenPermMatrixSlice.hpp"
00039 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
00040 #include "DenseLinAlgPack_DMatrixOp.hpp"
00041 
00042 
00043 void LinAlgOpPack::assign(
00044   DMatrixSlice* gms_lhs, const MatrixOp& M_rhs,
00045   BLAS_Cpp::Transp trans_rhs
00046   )
00047 {
00048   Mp_M_assert_sizes(
00049     gms_lhs->rows(), gms_lhs->cols(), BLAS_Cpp::no_trans,
00050     M_rhs.rows(), M_rhs.cols(), trans_rhs );
00051   (*gms_lhs) = 0.0;
00052   Mp_StM(gms_lhs,1.0,M_rhs,trans_rhs);
00053 }
00054 
00055 
00056 void LinAlgOpPack::Mp_StM(
00057   DMatrixSlice* C, value_type a
00058   ,const MatrixOp& B, BLAS_Cpp::Transp B_trans
00059   )
00060 {
00061   using AbstractLinAlgPack::VectorSpace;
00062   using AbstractLinAlgPack::VectorDenseEncap;
00063   using AbstractLinAlgPack::MatrixOpGetGMS;
00064   using AbstractLinAlgPack::MatrixDenseEncap;
00065   const MatrixOpGetGMS
00066     *B_get_gms = dynamic_cast<const MatrixOpGetGMS*>(&B);
00067   if(B_get_gms) {
00068     DenseLinAlgPack::Mp_StM( C, a, MatrixDenseEncap(*B_get_gms)(), B_trans );   
00069   }
00070   else {
00071     const size_type num_cols = C->cols();
00072     VectorSpace::multi_vec_mut_ptr_t
00073       B_mv = ( B_trans == BLAS_Cpp::no_trans 
00074           ? B.space_cols() : B.space_rows()
00075           ).create_members(num_cols);
00076     assign(B_mv.get(),B,B_trans);
00077     for( size_type j = 1; j <= num_cols; ++j ) {
00078       DenseLinAlgPack::Vp_StV(&C->col(j),a,VectorDenseEncap(*B_mv->col(j))());
00079     }
00080   }
00081 }
00082 
00083 void LinAlgOpPack::Vp_StMtV(
00084   DVectorSlice* y, value_type a, const MatrixOp& M
00085   ,BLAS_Cpp::Transp M_trans, const DVectorSlice& x, value_type b
00086   )
00087 {
00088   using BLAS_Cpp::no_trans;
00089   using AbstractLinAlgPack::VectorDenseMutableEncap;
00090   VectorSpace::vec_mut_ptr_t
00091     ay = ( M_trans == no_trans ? M.space_cols() : M.space_rows() ).create_member(),
00092     ax = ( M_trans == no_trans ? M.space_rows() : M.space_cols() ).create_member();
00093   (VectorDenseMutableEncap(*ay))() = *y;
00094   (VectorDenseMutableEncap(*ax))() = x;
00095   AbstractLinAlgPack::Vp_StMtV( ay.get(), a, M, M_trans, *ax, b );
00096   *y = VectorDenseMutableEncap(*ay)();
00097 }
00098 
00099 void LinAlgOpPack::Vp_StMtV(
00100   DVectorSlice* y, value_type a, const MatrixOp& M
00101   ,BLAS_Cpp::Transp M_trans, const SpVectorSlice& x, value_type b
00102   )
00103 {
00104   using BLAS_Cpp::no_trans;
00105   using AbstractLinAlgPack::VectorDenseMutableEncap;
00106   VectorSpace::vec_mut_ptr_t
00107     ay = ( M_trans == no_trans ? M.space_cols() : M.space_rows() ).create_member();
00108   (VectorDenseMutableEncap(*ay))() = *y;
00109   AbstractLinAlgPack::Vp_StMtV( ay.get(), a, M, M_trans, x, b );
00110   *y = VectorDenseMutableEncap(*ay)();
00111 }
00112 
00113 void LinAlgOpPack::V_InvMtV(
00114   DVectorSlice* y, const MatrixOpNonsing& M
00115   ,BLAS_Cpp::Transp M_trans, const DVectorSlice& x
00116   )
00117 {
00118   using BLAS_Cpp::trans;
00119   using AbstractLinAlgPack::VectorDenseMutableEncap;
00120   VectorSpace::vec_mut_ptr_t
00121     ay = ( M_trans == trans ? M.space_cols() : M.space_rows() ).create_member(),
00122     ax = ( M_trans == trans ? M.space_rows() : M.space_cols() ).create_member();
00123   (VectorDenseMutableEncap(*ay))() = *y;
00124   (VectorDenseMutableEncap(*ax))() = x;
00125   AbstractLinAlgPack::V_InvMtV( ay.get(), M, M_trans, *ax );
00126   *y = VectorDenseMutableEncap(*ay)();
00127 }
00128 
00129 void LinAlgOpPack::V_InvMtV(
00130   DVector* y, const MatrixOpNonsing& M
00131   ,BLAS_Cpp::Transp M_trans, const DVectorSlice& x
00132   )
00133 {
00134   using BLAS_Cpp::trans;
00135   using AbstractLinAlgPack::VectorDenseMutableEncap;
00136   VectorSpace::vec_mut_ptr_t
00137     ay = ( M_trans == trans ? M.space_cols() : M.space_rows() ).create_member(),
00138     ax = ( M_trans == trans ? M.space_rows() : M.space_cols() ).create_member();
00139   (VectorDenseMutableEncap(*ax))() = x;
00140   AbstractLinAlgPack::V_InvMtV( ay.get(), M, M_trans, *ax );
00141   *y = VectorDenseMutableEncap(*ay)();
00142 }
00143 
00144 void LinAlgOpPack::V_InvMtV(
00145   DVectorSlice* y, const MatrixOpNonsing& M
00146   ,BLAS_Cpp::Transp M_trans, const SpVectorSlice& x
00147   )
00148 {
00149   using BLAS_Cpp::trans;
00150   using AbstractLinAlgPack::VectorDenseMutableEncap;
00151   VectorSpace::vec_mut_ptr_t
00152     ay = ( M_trans == trans ? M.space_cols() : M.space_rows() ).create_member();
00153   AbstractLinAlgPack::V_InvMtV( ay.get(), M, M_trans, x );
00154   *y = VectorDenseMutableEncap(*ay)();
00155 }
00156 
00157 void LinAlgOpPack::V_InvMtV(
00158   DVector* y, const MatrixOpNonsing& M
00159   ,BLAS_Cpp::Transp M_trans, const SpVectorSlice& x
00160   )
00161 {
00162   y->resize(M.rows());
00163   LinAlgOpPack::V_InvMtV( &(*y)(), M, M_trans, x );
00164 }
00165 
00166 // These methods below are a real problem to implement in general.
00167 //
00168 // If the column space of op(M) could not return the above vector space
00169 // for op(M).space_cols().space(P,P_trans) then we will try, as a last
00170 // resort, to a dense serial vector and see what happens.
00171 
00172 void LinAlgOpPack::Vp_StPtMtV(
00173   DVectorSlice* y, value_type a
00174   ,const GenPermMatrixSlice& P, BLAS_Cpp::Transp P_trans
00175   ,const MatrixOp& M, BLAS_Cpp::Transp M_trans
00176   ,const DVectorSlice& x, value_type b
00177   )
00178 {
00179   namespace mmp = MemMngPack;
00180   using BLAS_Cpp::no_trans;
00181   using AbstractLinAlgPack::VectorMutableDense;
00182   using AbstractLinAlgPack::VectorDenseMutableEncap;
00183   using AbstractLinAlgPack::Vp_StPtMtV;
00184   VectorSpace::space_ptr_t
00185     ay_space = ( M_trans == no_trans ? M.space_cols() : M.space_rows() ).space(P,P_trans);
00186   VectorSpace::vec_mut_ptr_t
00187     ay =  ( ay_space.get()
00188         ? ay_space->create_member()
00189         : Teuchos::rcp_implicit_cast<VectorMutable>(
00190           Teuchos::rcp(new VectorMutableDense(BLAS_Cpp::rows(P.rows(),P.cols(),P_trans)))
00191           ) ),
00192     ax = ( M_trans == no_trans ? M.space_rows() : M.space_cols() ).create_member();
00193   (VectorDenseMutableEncap(*ay))() = *y;
00194   (VectorDenseMutableEncap(*ax))() = x;
00195   Vp_StPtMtV( ay.get(), a, P, P_trans, M, M_trans, *ax, b );
00196   *y = VectorDenseMutableEncap(*ay)();
00197 }
00198 
00199 void LinAlgOpPack::Vp_StPtMtV(
00200   DVectorSlice* y, value_type a
00201   ,const GenPermMatrixSlice& P, BLAS_Cpp::Transp P_trans
00202   ,const MatrixOp& M, BLAS_Cpp::Transp M_trans
00203   ,const SpVectorSlice& x, value_type b
00204   )
00205 {
00206   using BLAS_Cpp::no_trans;
00207   using AbstractLinAlgPack::VectorMutableDense;
00208   using AbstractLinAlgPack::VectorDenseMutableEncap;
00209   using AbstractLinAlgPack::Vp_StPtMtV;
00210   VectorSpace::vec_mut_ptr_t
00211     ay = ( M_trans == no_trans ? M.space_cols() : M.space_rows() ).space(P,P_trans)->create_member();
00212   (VectorDenseMutableEncap(*ay))() = *y;
00213   Vp_StPtMtV( ay.get(), a, P, P_trans, M, M_trans, x, b );
00214   *y = VectorDenseMutableEncap(*ay)();
00215 }

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