OSVR-Core
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 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>
42 void MatrixBase<Derived>::makeHouseholderInPlace(Scalar& tau, RealScalar& beta)
43 {
45  makeHouseholder(essentialPart, tau, beta);
46 }
47 
63 template<typename Derived>
64 template<typename EssentialPart>
66  EssentialPart& essential,
67  Scalar& tau,
68  RealScalar& beta) const
69 {
70  using std::sqrt;
71  using numext::conj;
72 
73  EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
75 
76  RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm();
77  Scalar c0 = coeff(0);
78 
79  if(tailSqNorm == RealScalar(0) && numext::imag(c0)==RealScalar(0))
80  {
81  tau = RealScalar(0);
82  beta = numext::real(c0);
83  essential.setZero();
84  }
85  else
86  {
87  beta = sqrt(numext::abs2(c0) + tailSqNorm);
88  if (numext::real(c0)>=RealScalar(0))
89  beta = -beta;
90  essential = tail / (c0 - beta);
91  tau = conj((beta - c0) / beta);
92  }
93 }
94 
110 template<typename Derived>
111 template<typename EssentialPart>
113  const EssentialPart& essential,
114  const Scalar& tau,
115  Scalar* workspace)
116 {
117  if(rows() == 1)
118  {
119  *this *= Scalar(1)-tau;
120  }
121  else
122  {
125  tmp.noalias() = essential.adjoint() * bottom;
126  tmp += this->row(0);
127  this->row(0) -= tau * tmp;
128  bottom.noalias() -= tau * essential * tmp;
129  }
130 }
131 
147 template<typename Derived>
148 template<typename EssentialPart>
150  const EssentialPart& essential,
151  const Scalar& tau,
152  Scalar* workspace)
153 {
154  if(cols() == 1)
155  {
156  *this *= Scalar(1)-tau;
157  }
158  else
159  {
162  tmp.noalias() = right * essential.conjugate();
163  tmp += this->col(0);
164  this->col(0) -= tau * tmp;
165  right.noalias() -= tau * tmp * essential.transpose();
166  }
167 }
168 
169 } // end namespace Eigen
170 
171 #endif // EIGEN_HOUSEHOLDER_H
void makeHouseholder(EssentialPart &essential, Scalar &tau, RealScalar &beta) const
Computes the elementary reflector H such that: where the transformation H is: and the vector v is: ...
Definition: Householder.h:65
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:104
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
typename detail::split_list_< List... >::tail tail
Get the list without its first element.
Definition: SplitList.h:58
void applyHouseholderOnTheLeft(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Apply the elementary reflector H given by with from the left to a vector or matrix.
Definition: Householder.h:112
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
Expression of a fixed-size or dynamic-size sub-vector.
Definition: ForwardDeclarations.h:83
Definition: Householder.h:17
Definition: BandTriangularSolver.h:13
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:103
void applyHouseholderOnTheRight(const EssentialPart &essential, const Scalar &tau, Scalar *workspace)
Apply the elementary reflector H given by with from the right to a vector or matrix.
Definition: Householder.h:149
void makeHouseholderInPlace(Scalar &tau, RealScalar &beta)
Computes the elementary reflector H such that: where the transformation H is: and the vector v is: ...
Definition: Householder.h:42
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48