Householder.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 Benoit Jacob <jacob.benoit.1@gmail.com>
00005 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
00006 //
00007 // This Source Code Form is subject to the terms of the Mozilla
00008 // Public License v. 2.0. If a copy of the MPL was not distributed
00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00010 
00011 #ifndef EIGEN_HOUSEHOLDER_H
00012 #define EIGEN_HOUSEHOLDER_H
00013 
00014 namespace Eigen { 
00015 
00016 namespace internal {
00017 template<int n> struct decrement_size
00018 {
00019   enum {
00020     ret = n==Dynamic ? n : n-1
00021   };
00022 };
00023 }
00024 
00041 template<typename Derived>
00042 void MatrixBase<Derived>::makeHouseholderInPlace(Scalar& tau, RealScalar& beta)
00043 {
00044   VectorBlock<Derived, internal::decrement_size<Base::SizeAtCompileTime>::ret> essentialPart(derived(), 1, size()-1);
00045   makeHouseholder(essentialPart, tau, beta);
00046 }
00047 
00063 template<typename Derived>
00064 template<typename EssentialPart>
00065 void MatrixBase<Derived>::makeHouseholder(
00066   EssentialPart& essential,
00067   Scalar& tau,
00068   RealScalar& beta) const
00069 {
00070   EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
00071   VectorBlock<const Derived, EssentialPart::SizeAtCompileTime> tail(derived(), 1, size()-1);
00072   
00073   RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm();
00074   Scalar c0 = coeff(0);
00075 
00076   if(tailSqNorm == RealScalar(0) && internal::imag(c0)==RealScalar(0))
00077   {
00078     tau = RealScalar(0);
00079     beta = internal::real(c0);
00080     essential.setZero();
00081   }
00082   else
00083   {
00084     beta = internal::sqrt(internal::abs2(c0) + tailSqNorm);
00085     if (internal::real(c0)>=RealScalar(0))
00086       beta = -beta;
00087     essential = tail / (c0 - beta);
00088     tau = internal::conj((beta - c0) / beta);
00089   }
00090 }
00091 
00107 template<typename Derived>
00108 template<typename EssentialPart>
00109 void MatrixBase<Derived>::applyHouseholderOnTheLeft(
00110   const EssentialPart& essential,
00111   const Scalar& tau,
00112   Scalar* workspace)
00113 {
00114   if(rows() == 1)
00115   {
00116     *this *= Scalar(1)-tau;
00117   }
00118   else
00119   {
00120     Map<typename internal::plain_row_type<PlainObject>::type> tmp(workspace,cols());
00121     Block<Derived, EssentialPart::SizeAtCompileTime, Derived::ColsAtCompileTime> bottom(derived(), 1, 0, rows()-1, cols());
00122     tmp.noalias() = essential.adjoint() * bottom;
00123     tmp += this->row(0);
00124     this->row(0) -= tau * tmp;
00125     bottom.noalias() -= tau * essential * tmp;
00126   }
00127 }
00128 
00144 template<typename Derived>
00145 template<typename EssentialPart>
00146 void MatrixBase<Derived>::applyHouseholderOnTheRight(
00147   const EssentialPart& essential,
00148   const Scalar& tau,
00149   Scalar* workspace)
00150 {
00151   if(cols() == 1)
00152   {
00153     *this *= Scalar(1)-tau;
00154   }
00155   else
00156   {
00157     Map<typename internal::plain_col_type<PlainObject>::type> tmp(workspace,rows());
00158     Block<Derived, Derived::RowsAtCompileTime, EssentialPart::SizeAtCompileTime> right(derived(), 0, 1, rows(), cols()-1);
00159     tmp.noalias() = right * essential.conjugate();
00160     tmp += this->col(0);
00161     this->col(0) -= tau * tmp;
00162     right.noalias() -= tau * tmp * essential.transpose();
00163   }
00164 }
00165 
00166 } // end namespace Eigen
00167 
00168 #endif // EIGEN_HOUSEHOLDER_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:24:38