BlockHouseholder.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2010 Vincent Lejeune
5 // Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // Eigen is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 3 of the License, or (at your option) any later version.
11 //
12 // Alternatively, you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of
15 // the License, or (at your option) any later version.
16 //
17 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License and a copy of the GNU General Public License along with
24 // Eigen. If not, see <http://www.gnu.org/licenses/>.
25 
26 #ifndef EIGEN_BLOCK_HOUSEHOLDER_H
27 #define EIGEN_BLOCK_HOUSEHOLDER_H
28 
29 // This file contains some helper function to deal with block householder reflectors
30 
31 namespace Eigen {
32 
33 namespace internal {
34 
36 template<typename TriangularFactorType,typename VectorsType,typename CoeffsType>
37 void make_block_householder_triangular_factor(TriangularFactorType& triFactor, const VectorsType& vectors, const CoeffsType& hCoeffs)
38 {
39  typedef typename TriangularFactorType::Index Index;
40  typedef typename VectorsType::Scalar Scalar;
41  const Index nbVecs = vectors.cols();
42  eigen_assert(triFactor.rows() == nbVecs && triFactor.cols() == nbVecs && vectors.rows()>=nbVecs);
43 
44  for(Index i = 0; i < nbVecs; i++)
45  {
46  Index rs = vectors.rows() - i;
47  Scalar Vii = vectors(i,i);
48  vectors.const_cast_derived().coeffRef(i,i) = Scalar(1);
49  triFactor.col(i).head(i).noalias() = -hCoeffs(i) * vectors.block(i, 0, rs, i).adjoint()
50  * vectors.col(i).tail(rs);
51  vectors.const_cast_derived().coeffRef(i, i) = Vii;
52  // FIXME add .noalias() once the triangular product can work inplace
53  triFactor.col(i).head(i) = triFactor.block(0,0,i,i).template triangularView<Upper>()
54  * triFactor.col(i).head(i);
55  triFactor(i,i) = hCoeffs(i);
56  }
57 }
58 
60 template<typename MatrixType,typename VectorsType,typename CoeffsType>
61 void apply_block_householder_on_the_left(MatrixType& mat, const VectorsType& vectors, const CoeffsType& hCoeffs)
62 {
63  typedef typename MatrixType::Index Index;
64  enum { TFactorSize = MatrixType::ColsAtCompileTime };
65  Index nbVecs = vectors.cols();
67  make_block_householder_triangular_factor(T, vectors, hCoeffs);
68 
70 
71  // A -= V T V^* A
72  Matrix<typename MatrixType::Scalar,VectorsType::ColsAtCompileTime,MatrixType::ColsAtCompileTime,0,
73  VectorsType::MaxColsAtCompileTime,MatrixType::MaxColsAtCompileTime> tmp = V.adjoint() * mat;
74  // FIXME add .noalias() once the triangular product can work inplace
75  tmp = T.template triangularView<Upper>().adjoint() * tmp;
76  mat.noalias() -= V * tmp;
77 }
78 
79 } // end namespace internal
80 
81 } // end namespace Eigen
82 
83 #endif // EIGEN_BLOCK_HOUSEHOLDER_H