AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
AbstractLinAlgPack_MatrixSymNonsingSerial.cpp
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_MatrixSymNonsingSerial.hpp"
00032 #include "AbstractLinAlgPack_MatrixSymOpGetGMSSymMutable.hpp"
00033 #include "AbstractLinAlgPack_MatrixOpSerial.hpp"
00034 #include "AbstractLinAlgPack_EtaVector.hpp"
00035 #include "DenseLinAlgPack_DMatrixClass.hpp"
00036 #include "DenseLinAlgPack_DMatrixOp.hpp"
00037 #include "DenseLinAlgPack_DMatrixAsTriSym.hpp"
00038 #include "AbstractLinAlgPack_LinAlgOpPackHack.hpp"
00039 #include "DenseLinAlgPack_AssertOp.hpp"
00040 #include "Teuchos_dyn_cast.hpp"
00041 
00042 namespace LinAlgOpPack {
00043   using AbstractLinAlgPack::Vp_StMtV;
00044   using AbstractLinAlgPack::Mp_StMtM;
00045 }
00046 
00047 namespace AbstractLinAlgPack {
00048 
00049 void MatrixSymNonsingSerial::M_StMtInvMtM(
00050     DMatrixSliceSym* S, value_type a, const MatrixOpSerial& B
00051   , BLAS_Cpp::Transp B_trans, EMatrixDummyArg ) const
00052 {
00053   using BLAS_Cpp::trans;
00054   using BLAS_Cpp::no_trans;
00055   using BLAS_Cpp::trans_not;
00056   using AbstractLinAlgPack::M_StInvMtM;
00057   using DenseLinAlgPack::nonconst_tri_ele;
00058   using DenseLinAlgPack::tri_ele;
00059   using DenseLinAlgPack::assign;
00060   using LinAlgOpPack::M_StMtM;
00061   //
00062   // S = a * op(B) * inv(M) * op(B')
00063   //
00064   // We will form S won column at a time:
00065   //
00066   // S(:,j) = a * op(B) * inv(M) * op(B') * e(j)
00067   //
00068   // for j = 1 ... op(B').cols()
00069   //   t1 = op(B')*e(j)
00070   //   t2 = inv(M)*t1
00071   //   t3 = a*op(B)*t2
00072   //   S(:,j) = t3
00073   //
00074   // Above we only need to set the lower (lower triangle stored)
00075   // or upper (upper triangle stored) part of S(:,k)
00076   //
00077   DenseLinAlgPack::MtM_assert_sizes( rows(), cols(), no_trans
00078     , B.rows(), B.cols(), trans_not(B_trans) );
00079   DenseLinAlgPack::Mp_MtM_assert_sizes( S->rows(), S->cols(), no_trans
00080     , B.rows(), B.cols(), B_trans
00081     , B.rows(), B.cols(), trans_not(B_trans) );
00082 
00083   DVector t1, t2, t3; // ToDo: Use temp workspace!
00084   const size_type
00085     opBT_cols = BLAS_Cpp::cols( B.cols(), B.rows(), B_trans ),
00086     m         = S->rows();
00087   for( size_type j = 1; j <= m; ++j ) {
00088     EtaVector e_j(j,opBT_cols);                               // e(j)
00089     LinAlgOpPack::V_MtV( &t1, B, trans_not(B_trans), e_j() ); // t1 = op(B')*e(j)
00090     AbstractLinAlgPack::V_InvMtV( &t2, *this, no_trans, t1() ); // t2 = inv(M)*t1
00091     LinAlgOpPack::V_StMtV( &t3, a, B, B_trans, t2() );        // t3 = a*op(B)*t2
00092     Range1D
00093       rng = ( S->uplo() == BLAS_Cpp::upper ? Range1D(1,j) : Range1D(j,m) );
00094     S->gms().col(j)(rng) = t3(rng);
00095   }
00096 }
00097 
00098 // Overridden from MatrixSymNonsing
00099 
00100 void MatrixSymNonsingSerial::M_StMtInvMtM(
00101   MatrixSymOp* symwo_lhs, value_type alpha
00102   ,const MatrixOp& mwo, BLAS_Cpp::Transp mwo_trans
00103   ,EMatrixDummyArg dummy
00104   ) const
00105 {
00106   using Teuchos::dyn_cast;
00107   this->M_StMtInvMtM(
00108     &MatrixDenseSymMutableEncap(symwo_lhs)(), alpha
00109     ,dyn_cast<const MatrixOpSerial>(mwo), mwo_trans
00110     ,dummy );
00111 }
00112 
00113 } // end namespace AbstractLinAlgPack
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends