Eigen  5.0.1-dev+60122df6
 
Loading...
Searching...
No Matches
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
17namespace Eigen {
18
19namespace internal {
20template <int n>
21struct decrement_size {
22 enum { ret = n == Dynamic ? n : n - 1 };
23};
24} // namespace internal
25
42template <typename Derived>
43EIGEN_DEVICE_FUNC void MatrixBase<Derived>::makeHouseholderInPlace(Scalar& tau, RealScalar& beta) {
45 makeHouseholder(essentialPart, tau, beta);
46}
47
63template <typename Derived>
64template <typename EssentialPart>
65EIGEN_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
103template <typename Derived>
104template <typename EssentialPart>
105EIGEN_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
135template <typename Derived>
136template <typename EssentialPart>
137EIGEN_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
Expression of a fixed-size or dynamic-size block.
Definition Block.h:110
RowXpr row(Index i)
Definition DenseBase.h:1085
ColXpr col(Index i)
Definition DenseBase.h:1072
internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:62
FixedSegmentReturnType<... >::Type tail(NType n)
Definition DenseBase.h:1212
A matrix or vector expression mapping an existing array of data.
Definition Map.h:96
void makeHouseholder(EssentialPart &essential, Scalar &tau, RealScalar &beta) const
Definition Householder.h:65
void applyHouseholderOnTheLeft(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition Householder.h:105
void applyHouseholderOnTheRight(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition Householder.h:137
void makeHouseholderInPlace(Scalar &tau, RealScalar &beta)
Definition Householder.h:43
Expression of a fixed-size or dynamic-size sub-vector.
Definition VectorBlock.h:58
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
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:25