BlockHouseholder.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2010 Vincent Lejeune
00005 // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 #ifndef EIGEN_BLOCK_HOUSEHOLDER_H
00027 #define EIGEN_BLOCK_HOUSEHOLDER_H
00028 
00029 // This file contains some helper function to deal with block householder reflectors
00030 
00031 namespace internal {
00032 
00034 template<typename TriangularFactorType,typename VectorsType,typename CoeffsType>
00035 void make_block_householder_triangular_factor(TriangularFactorType& triFactor, const VectorsType& vectors, const CoeffsType& hCoeffs)
00036 {
00037   typedef typename TriangularFactorType::Index Index;
00038   typedef typename VectorsType::Scalar Scalar;
00039   const Index nbVecs = vectors.cols();
00040   eigen_assert(triFactor.rows() == nbVecs && triFactor.cols() == nbVecs && vectors.rows()>=nbVecs);
00041 
00042   for(Index i = 0; i < nbVecs; i++)
00043   {
00044     Index rs = vectors.rows() - i;
00045     Scalar Vii = vectors(i,i);
00046     vectors.const_cast_derived().coeffRef(i,i) = Scalar(1);
00047     triFactor.col(i).head(i).noalias() = -hCoeffs(i) * vectors.block(i, 0, rs, i).adjoint()
00048                                        * vectors.col(i).tail(rs);
00049     vectors.const_cast_derived().coeffRef(i, i) = Vii;
00050     // FIXME add .noalias() once the triangular product can work inplace
00051     triFactor.col(i).head(i) = triFactor.block(0,0,i,i).template triangularView<Upper>()
00052                              * triFactor.col(i).head(i);
00053     triFactor(i,i) = hCoeffs(i);
00054   }
00055 }
00056 
00058 template<typename MatrixType,typename VectorsType,typename CoeffsType>
00059 void apply_block_householder_on_the_left(MatrixType& mat, const VectorsType& vectors, const CoeffsType& hCoeffs)
00060 {
00061   typedef typename MatrixType::Index Index;
00062   enum { TFactorSize = MatrixType::ColsAtCompileTime };
00063   Index nbVecs = vectors.cols();
00064   Matrix<typename MatrixType::Scalar, TFactorSize, TFactorSize> T(nbVecs,nbVecs);
00065   make_block_householder_triangular_factor(T, vectors, hCoeffs);
00066 
00067   const TriangularView<VectorsType, UnitLower>& V(vectors);
00068 
00069   // A -= V T V^* A
00070   Matrix<typename MatrixType::Scalar,VectorsType::ColsAtCompileTime,MatrixType::ColsAtCompileTime,0,
00071          VectorsType::MaxColsAtCompileTime,MatrixType::MaxColsAtCompileTime> tmp = V.adjoint() * mat;
00072   // FIXME add .noalias() once the triangular product can work inplace
00073   tmp = T.template triangularView<Upper>().adjoint() * tmp;
00074   mat.noalias() -= V * tmp;
00075 }
00076 
00077 } // end namespace internal
00078 
00079 #endif // EIGEN_BLOCK_HOUSEHOLDER_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:31