Eigen  3.3.7
Householder.h
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_HOUSEHOLDER_H
12 #define EIGEN_HOUSEHOLDER_H
13 
14 namespace Eigen {
15 
16 namespace internal {
17 template<int n> struct decrement_size
18 {
19  enum {
20  ret = n==Dynamic ? n : n-1
21  };
22 };
23 }
24 
41 template<typename Derived>
43 {
45  makeHouseholder(essentialPart, tau, beta);
46 }
47 
63 template<typename Derived>
64 template<typename EssentialPart>
66  EssentialPart& essential,
67  Scalar& tau,
68  RealScalar& beta) const
69 {
70  using std::sqrt;
71  using numext::conj;
72 
73  EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
75 
76  RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm();
77  Scalar c0 = coeff(0);
78  const RealScalar tol = (std::numeric_limits<RealScalar>::min)();
79 
80  if(tailSqNorm <= tol && numext::abs2(numext::imag(c0))<=tol)
81  {
82  tau = RealScalar(0);
83  beta = numext::real(c0);
84  essential.setZero();
85  }
86  else
87  {
88  beta = sqrt(numext::abs2(c0) + tailSqNorm);
89  if (numext::real(c0)>=RealScalar(0))
90  beta = -beta;
91  essential = tail / (c0 - beta);
92  tau = conj((beta - c0) / beta);
93  }
94 }
95 
111 template<typename Derived>
112 template<typename EssentialPart>
114  const EssentialPart& essential,
115  const Scalar& tau,
116  Scalar* workspace)
117 {
118  if(rows() == 1)
119  {
120  *this *= Scalar(1)-tau;
121  }
122  else if(tau!=Scalar(0))
123  {
126  tmp.noalias() = essential.adjoint() * bottom;
127  tmp += this->row(0);
128  this->row(0) -= tau * tmp;
129  bottom.noalias() -= tau * essential * tmp;
130  }
131 }
132 
148 template<typename Derived>
149 template<typename EssentialPart>
151  const EssentialPart& essential,
152  const Scalar& tau,
153  Scalar* workspace)
154 {
155  if(cols() == 1)
156  {
157  *this *= Scalar(1)-tau;
158  }
159  else if(tau!=Scalar(0))
160  {
163  tmp.noalias() = right * essential.conjugate();
164  tmp += this->col(0);
165  this->col(0) -= tau * tmp;
166  right.noalias() -= tau * tmp * essential.transpose();
167  }
168 }
169 
170 } // end namespace Eigen
171 
172 #endif // EIGEN_HOUSEHOLDER_H
void makeHouseholder(EssentialPart &essential, Scalar &tau, RealScalar &beta) const
Definition: Householder.h:65
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:66
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)
Namespace containing all symbols from the Eigen library.
Definition: Core:306
void applyHouseholderOnTheLeft(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition: Householder.h:113
Expression of a fixed-size or dynamic-size sub-vector.
Definition: ForwardDeclarations.h:83
Definition: Eigen_Colamd.h:50
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
void applyHouseholderOnTheRight(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition: Householder.h:150
void makeHouseholderInPlace(Scalar &tau, RealScalar &beta)
Definition: Householder.h:42
const int Dynamic
Definition: Constants.h:21