$darkmode
Eigen  5.0.1-dev
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 // IWYU pragma: private
15 #include "./InternalHeaderCheck.h"
16 
17 namespace Eigen {
18 
19 namespace internal {
20 template <int n>
21 struct decrement_size {
22  enum { ret = n == Dynamic ? n : n - 1 };
23 };
24 } // namespace internal
25 
42 template <typename Derived>
43 EIGEN_DEVICE_FUNC void MatrixBase<Derived>::makeHouseholderInPlace(Scalar& tau, RealScalar& beta) {
45  makeHouseholder(essentialPart, tau, beta);
46 }
47 
63 template <typename Derived>
64 template <typename EssentialPart>
65 EIGEN_DEVICE_FUNC void MatrixBase<Derived>::makeHouseholder(EssentialPart& essential, Scalar& tau,
66  RealScalar& beta) const {
67  using numext::conj;
68 
69  EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
71 
72  RealScalar tailSqNorm = size() == 1 ? RealScalar(0) : tail.squaredNorm();
73  Scalar c0 = coeff(0);
74  const RealScalar tol = (std::numeric_limits<RealScalar>::min)();
75 
76  if (tailSqNorm <= tol && numext::abs2(numext::imag(c0)) <= tol) {
77  tau = RealScalar(0);
78  beta = numext::real(c0);
79  essential.setZero();
80  } else {
81  beta = numext::sqrt(numext::abs2(c0) + tailSqNorm);
82  if (numext::real(c0) >= RealScalar(0)) beta = -beta;
83  essential = tail / (c0 - beta);
84  tau = conj((beta - c0) / beta);
85  }
86 }
87 
103 template <typename Derived>
104 template <typename EssentialPart>
105 EIGEN_DEVICE_FUNC void MatrixBase<Derived>::applyHouseholderOnTheLeft(const EssentialPart& essential, const Scalar& tau,
106  Scalar* workspace) {
107  if (rows() == 1) {
108  *this *= Scalar(1) - tau;
109  } else if (!numext::is_exactly_zero(tau)) {
112  cols());
113  tmp.noalias() = essential.adjoint() * bottom;
114  tmp += this->row(0);
115  this->row(0) -= tau * tmp;
116  bottom.noalias() -= tau * essential * tmp;
117  }
118 }
119 
135 template <typename Derived>
136 template <typename EssentialPart>
137 EIGEN_DEVICE_FUNC void MatrixBase<Derived>::applyHouseholderOnTheRight(const EssentialPart& essential,
138  const Scalar& tau, Scalar* workspace) {
139  if (cols() == 1) {
140  *this *= Scalar(1) - tau;
141  } else if (!numext::is_exactly_zero(tau)) {
144  cols() - 1);
145  tmp.noalias() = right * essential;
146  tmp += this->col(0);
147  this->col(0) -= tau * tmp;
148  right.noalias() -= tau * tmp * essential.adjoint();
149  }
150 }
151 
152 } // end namespace Eigen
153 
154 #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:62
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
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: B01_Experimental.dox:1
void applyHouseholderOnTheLeft(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition: Householder.h:105
Expression of a fixed-size or dynamic-size sub-vector.
Definition: ForwardDeclarations.h:98
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:109
void applyHouseholderOnTheRight(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition: Householder.h:137
void makeHouseholderInPlace(Scalar &tau, RealScalar &beta)
Definition: Householder.h:43
const int Dynamic
Definition: Constants.h:25