Householder.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 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>
46 {
48  makeHouseholder(essentialPart, tau, beta);
49 }
50 
66 template<typename Derived>
67 template<typename EssentialPart>
70  EssentialPart& essential,
71  Scalar& tau,
72  RealScalar& beta) const
73 {
74  using numext::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);
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>
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>
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
int n
RowXpr row(Index i)
This is the const version of row(). *‍/.
ColXpr col(Index i)
This is the const version of col().
FixedSegmentReturnType<... >::Type tail(NType n)
const ImagReturnType imag() const
RealReturnType real() const
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:883
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:36
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:107
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:68
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
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:684
bool abs2(bool x)
EIGEN_ALWAYS_INLINE float sqrt(const float &x)
bool is_exactly_zero(const X &x)
Definition: Meta.h:475
: InteropHeaders
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)