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 namespace Eigen {
15 
16 namespace internal {
17 template<int n> struct decrement_size
18 {
19  enum {
20  ret = n==Dynamic ? n : n-1
21  };
22 };
23 }
24 
41 template<typename Derived>
44 {
46  makeHouseholder(essentialPart, tau, beta);
47 }
48 
64 template<typename Derived>
65 template<typename EssentialPart>
68  EssentialPart& essential,
69  Scalar& tau,
70  RealScalar& beta) const
71 {
72  using std::sqrt;
73  using numext::conj;
74 
75  EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
77 
78  RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm();
79  Scalar c0 = coeff(0);
81 
82  if(tailSqNorm <= tol && numext::abs2(numext::imag(c0))<=tol)
83  {
84  tau = RealScalar(0);
85  beta = numext::real(c0);
86  essential.setZero();
87  }
88  else
89  {
90  beta = sqrt(numext::abs2(c0) + tailSqNorm);
91  if (numext::real(c0)>=RealScalar(0))
92  beta = -beta;
93  essential = tail / (c0 - beta);
94  tau = conj((beta - c0) / beta);
95  }
96 }
97 
113 template<typename Derived>
114 template<typename EssentialPart>
117  const EssentialPart& essential,
118  const Scalar& tau,
119  Scalar* workspace)
120 {
121  if(rows() == 1)
122  {
123  *this *= Scalar(1)-tau;
124  }
125  else if(tau!=Scalar(0))
126  {
129  tmp.noalias() = essential.adjoint() * bottom;
130  tmp += this->row(0);
131  this->row(0) -= tau * tmp;
132  bottom.noalias() -= tau * essential * tmp;
133  }
134 }
135 
151 template<typename Derived>
152 template<typename EssentialPart>
155  const EssentialPart& essential,
156  const Scalar& tau,
157  Scalar* workspace)
158 {
159  if(cols() == 1)
160  {
161  *this *= Scalar(1)-tau;
162  }
163  else if(tau!=Scalar(0))
164  {
167  tmp.noalias() = right * essential;
168  tmp += this->col(0);
169  this->col(0) -= tau * tmp;
170  right.noalias() -= tau * tmp * essential.adjoint();
171  }
172 }
173 
174 } // end namespace Eigen
175 
176 #endif // EIGEN_HOUSEHOLDER_H
Eigen::conj
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
Definition: AutoDiffScalar.h:574
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
tail
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE FixedSegmentReturnType< internal::get_fixed_value< NType >::value >::Type tail(NType n)
Definition: BlockMethods.h:1257
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::MatrixBase::applyHouseholderOnTheLeft
EIGEN_DEVICE_FUNC void applyHouseholderOnTheLeft(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition: Householder.h:116
col
m col(1)
Eigen::Block
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
Eigen::DenseBase< Solve< Decomposition, RhsType > >::Scalar
internal::traits< Solve< Decomposition, RhsType > >::Scalar Scalar
Definition: DenseBase.h:66
Eigen::internal::decrement_size
Definition: Householder.h:17
real
float real
Definition: datatypes.h:10
Eigen::MatrixBase::applyHouseholderOnTheRight
EIGEN_DEVICE_FUNC void applyHouseholderOnTheRight(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Definition: Householder.h:154
EIGEN_STATIC_ASSERT_VECTOR_ONLY
#define EIGEN_STATIC_ASSERT_VECTOR_ONLY(TYPE)
Definition: StaticAssert.h:142
beta
double beta(double a, double b)
Definition: beta.c:61
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::MatrixBase::makeHouseholder
EIGEN_DEVICE_FUNC void makeHouseholder(EssentialPart &essential, Scalar &tau, RealScalar &beta) const
Definition: Householder.h:67
size
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
n
int n
Definition: BiCGSTAB_simple.cpp:1
Eigen::DenseBase< Solve< Decomposition, RhsType > >::RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: DenseBase.h:73
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:22
Eigen::internal::decrement_size::ret
@ ret
Definition: Householder.h:20
imag
const EIGEN_DEVICE_FUNC ImagReturnType imag() const
Definition: CommonCwiseUnaryOps.h:109
conj
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:104
Eigen::Map
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:94
RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:47
right
static char right
Definition: blas_interface.hh:61
Eigen::numext::abs2
EIGEN_DEVICE_FUNC bool abs2(bool x)
Definition: Eigen/src/Core/MathFunctions.h:1294
row
m row(1)
Eigen::VectorBlock
Expression of a fixed-size or dynamic-size sub-vector.
Definition: ForwardDeclarations.h:85
min
#define min(a, b)
Definition: datatypes.h:19
gtsam::tol
const G double tol
Definition: Group.h:79
internal
Definition: BandTriangularSolver.h:13
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
ceres::sqrt
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:418
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::MatrixBase::makeHouseholderInPlace
EIGEN_DEVICE_FUNC void makeHouseholderInPlace(Scalar &tau, RealScalar &beta)
Definition: Householder.h:43


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:01:14