Eigen  3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)
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 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 template<int n> struct decrement_size
20 {
21  enum {
22  ret = n==Dynamic ? n : n-1
23  };
24 };
25 }
26 
43 template<typename Derived>
44 EIGEN_DEVICE_FUNC
46 {
48  makeHouseholder(essentialPart, tau, beta);
49 }
50 
66 template<typename Derived>
67 template<typename EssentialPart>
68 EIGEN_DEVICE_FUNC
70  EssentialPart& essential,
71  Scalar& tau,
72  RealScalar& beta) const
73 {
74  using std::sqrt;
75  using numext::conj;
76 
77  EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
79 
80  RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm();
81  Scalar c0 = coeff(0);
82  const RealScalar tol = (std::numeric_limits<RealScalar>::min)();
83 
84  if(tailSqNorm <= tol && numext::abs2(numext::imag(c0))<=tol)
85  {
86  tau = RealScalar(0);
87  beta = numext::real(c0);
88  essential.setZero();
89  }
90  else
91  {
92  beta = sqrt(numext::abs2(c0) + tailSqNorm);
93  if (numext::real(c0)>=RealScalar(0))
94  beta = -beta;
95  essential = tail / (c0 - beta);
96  tau = conj((beta - c0) / beta);
97  }
98 }
99 
115 template<typename Derived>
116 template<typename EssentialPart>
117 EIGEN_DEVICE_FUNC
119  const EssentialPart& essential,
120  const Scalar& tau,
121  Scalar* workspace)
122 {
123  if(rows() == 1)
124  {
125  *this *= Scalar(1)-tau;
126  }
127  else if(!numext::is_exactly_zero(tau))
128  {
131  tmp.noalias() = essential.adjoint() * bottom;
132  tmp += this->row(0);
133  this->row(0) -= tau * tmp;
134  bottom.noalias() -= tau * essential * tmp;
135  }
136 }
137 
153 template<typename Derived>
154 template<typename EssentialPart>
155 EIGEN_DEVICE_FUNC
157  const EssentialPart& essential,
158  const Scalar& tau,
159  Scalar* workspace)
160 {
161  if(cols() == 1)
162  {
163  *this *= Scalar(1)-tau;
164  }
165  else if(!numext::is_exactly_zero(tau))
166  {
169  tmp.noalias() = right * essential;
170  tmp += this->col(0);
171  this->col(0) -= tau * tmp;
172  right.noalias() -= tau * tmp * essential.adjoint();
173  }
174 }
175 
176 } // end namespace Eigen
177 
178 #endif // EIGEN_HOUSEHOLDER_H
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:107
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:61
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:98
void makeHouseholder(EssentialPart &essential, Scalar &tau, RealScalar &beta) const
Definition: Householder.h:69
void applyHouseholderOnTheLeft(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition: Householder.h:118
void applyHouseholderOnTheRight(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition: Householder.h:156
void makeHouseholderInPlace(Scalar &tau, RealScalar &beta)
Definition: Householder.h:45
Expression of a fixed-size or dynamic-size sub-vector.
Definition: VectorBlock.h:62
Namespace containing all symbols from the Eigen library.
Definition: Core:139
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)
const int Dynamic
Definition: Constants.h:24
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)