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 // IWYU pragma: private
15 #include "./InternalHeaderCheck.h"
16 
17 namespace Eigen {
18 
19 namespace internal {
20 template <int n>
22  enum { ret = n == Dynamic ? n : n - 1 };
23 };
24 } // namespace internal
25 
42 template <typename Derived>
45  makeHouseholder(essentialPart, tau, beta);
46 }
47 
63 template <typename Derived>
64 template <typename EssentialPart>
66  RealScalar& beta) const {
67  using numext::conj;
68  using numext::sqrt;
69 
70  EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
72 
73  RealScalar tailSqNorm = size() == 1 ? RealScalar(0) : tail.squaredNorm();
74  Scalar c0 = coeff(0);
76 
77  if (tailSqNorm <= tol && numext::abs2(numext::imag(c0)) <= tol) {
78  tau = RealScalar(0);
79  beta = numext::real(c0);
80  essential.setZero();
81  } else {
82  beta = sqrt(numext::abs2(c0) + tailSqNorm);
83  if (numext::real(c0) >= RealScalar(0)) beta = -beta;
84  essential = tail / (c0 - beta);
85  tau = conj((beta - c0) / beta);
86  }
87 }
88 
104 template <typename Derived>
105 template <typename EssentialPart>
106 EIGEN_DEVICE_FUNC void MatrixBase<Derived>::applyHouseholderOnTheLeft(const EssentialPart& essential, const Scalar& tau,
107  Scalar* workspace) {
108  if (rows() == 1) {
109  *this *= Scalar(1) - tau;
110  } else if (!numext::is_exactly_zero(tau)) {
113  cols());
114  tmp.noalias() = essential.adjoint() * bottom;
115  tmp += this->row(0);
116  this->row(0) -= tau * tmp;
117  bottom.noalias() -= tau * essential * tmp;
118  }
119 }
120 
136 template <typename Derived>
137 template <typename EssentialPart>
139  const Scalar& tau, Scalar* workspace) {
140  if (cols() == 1) {
141  *this *= Scalar(1) - tau;
142  } else if (!numext::is_exactly_zero(tau)) {
145  cols() - 1);
146  tmp.noalias() = right * essential;
147  tmp += this->col(0);
148  this->col(0) -= tau * tmp;
149  right.noalias() -= tau * tmp * essential.adjoint();
150  }
151 }
152 
153 } // end namespace Eigen
154 
155 #endif // EIGEN_HOUSEHOLDER_H
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:133
AnnoyingScalar imag(const AnnoyingScalar &)
Definition: AnnoyingScalar.h:132
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
m col(1)
m row(1)
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:36
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:110
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:69
internal::traits< Derived >::Scalar Scalar
Definition: DenseBase.h:62
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
EIGEN_DEVICE_FUNC void makeHouseholderInPlace(Scalar &tau, RealScalar &beta)
Definition: Householder.h:43
EIGEN_DEVICE_FUNC void applyHouseholderOnTheLeft(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition: Householder.h:106
EIGEN_DEVICE_FUNC void makeHouseholder(EssentialPart &essential, Scalar &tau, RealScalar &beta) const
Definition: Householder.h:65
EIGEN_DEVICE_FUNC void applyHouseholderOnTheRight(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition: Householder.h:138
Expression of a fixed-size or dynamic-size sub-vector.
Definition: VectorBlock.h:58
float real
Definition: datatypes.h:10
#define min(a, b)
Definition: datatypes.h:22
Scalar beta
Definition: level2_cplx_impl.h:36
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool is_exactly_zero(const X &x)
Definition: Meta.h:592
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE float sqrt(const float &x)
Definition: arch/SSE/MathFunctions.h:69
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: MathFunctions.h:1102
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
Definition: AutoDiffScalar.h:482
const int Dynamic
Definition: Constants.h:25
Definition: Eigen_Colamd.h:49
Definition: Householder.h:21
@ ret
Definition: Householder.h:22