Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
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 <[email protected]>
5// Copyright (C) 2009 Gael Guennebaud <[email protected]>
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 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);
75 const RealScalar tol = (std::numeric_limits<RealScalar>::min)();
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
104template <typename Derived>
105template <typename EssentialPart>
106EIGEN_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
136template <typename Derived>
137template <typename EssentialPart>
138EIGEN_DEVICE_FUNC void MatrixBase<Derived>::applyHouseholderOnTheRight(const EssentialPart& essential,
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
Expression of a fixed-size or dynamic-size block.
Definition Block.h:110
internal::traits< Derived >::Scalar Scalar
Definition DenseBase.h:62
A matrix or vector expression mapping an existing array of data.
Definition Map.h:96
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:52
Expression of a fixed-size or dynamic-size sub-vector.
Definition VectorBlock.h:58
Namespace containing all symbols from the Eigen library.
Definition Core:137
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