~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/Eigen3/Eigen/src/Householder/Householder.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
// Eigen is free software; you can redistribute it and/or
 
8
// modify it under the terms of the GNU Lesser General Public
 
9
// License as published by the Free Software Foundation; either
 
10
// version 3 of the License, or (at your option) any later version.
 
11
//
 
12
// Alternatively, you can redistribute it and/or
 
13
// modify it under the terms of the GNU General Public License as
 
14
// published by the Free Software Foundation; either version 2 of
 
15
// the License, or (at your option) any later version.
 
16
//
 
17
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
 
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
19
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
 
20
// GNU General Public License for more details.
 
21
//
 
22
// You should have received a copy of the GNU Lesser General Public
 
23
// License and a copy of the GNU General Public License along with
 
24
// Eigen. If not, see <http://www.gnu.org/licenses/>.
 
25
 
 
26
#ifndef EIGEN_HOUSEHOLDER_H
 
27
#define EIGEN_HOUSEHOLDER_H
 
28
 
 
29
namespace internal {
 
30
template<int n> struct decrement_size
 
31
{
 
32
  enum {
 
33
    ret = n==Dynamic ? n : n-1
 
34
  };
 
35
};
 
36
}
 
37
 
 
38
template<typename Derived>
 
39
void MatrixBase<Derived>::makeHouseholderInPlace(Scalar& tau, RealScalar& beta)
 
40
{
 
41
  VectorBlock<Derived, internal::decrement_size<Base::SizeAtCompileTime>::ret> essentialPart(derived(), 1, size()-1);
 
42
  makeHouseholder(essentialPart, tau, beta);
 
43
}
 
44
 
 
45
/** Computes the elementary reflector H such that:
 
46
  * \f$ H *this = [ beta 0 ... 0]^T \f$
 
47
  * where the transformation H is:
 
48
  * \f$ H = I - tau v v^*\f$
 
49
  * and the vector v is:
 
50
  * \f$ v^T = [1 essential^T] \f$
 
51
  *
 
52
  * On output:
 
53
  * \param essential the essential part of the vector \c v
 
54
  * \param tau the scaling factor of the householder transformation
 
55
  * \param beta the result of H * \c *this
 
56
  *
 
57
  * \sa MatrixBase::makeHouseholderInPlace(), MatrixBase::applyHouseholderOnTheLeft(),
 
58
  *     MatrixBase::applyHouseholderOnTheRight()
 
59
  */
 
60
template<typename Derived>
 
61
template<typename EssentialPart>
 
62
void MatrixBase<Derived>::makeHouseholder(
 
63
  EssentialPart& essential,
 
64
  Scalar& tau,
 
65
  RealScalar& beta) const
 
66
{
 
67
  EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart)
 
68
  VectorBlock<const Derived, EssentialPart::SizeAtCompileTime> tail(derived(), 1, size()-1);
 
69
  
 
70
  RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm();
 
71
  Scalar c0 = coeff(0);
 
72
 
 
73
  if(tailSqNorm == RealScalar(0) && internal::imag(c0)==RealScalar(0))
 
74
  {
 
75
    tau = RealScalar(0);
 
76
    beta = internal::real(c0);
 
77
    essential.setZero();
 
78
  }
 
79
  else
 
80
  {
 
81
    beta = internal::sqrt(internal::abs2(c0) + tailSqNorm);
 
82
    if (internal::real(c0)>=RealScalar(0))
 
83
      beta = -beta;
 
84
    essential = tail / (c0 - beta);
 
85
    tau = internal::conj((beta - c0) / beta);
 
86
  }
 
87
}
 
88
 
 
89
template<typename Derived>
 
90
template<typename EssentialPart>
 
91
void MatrixBase<Derived>::applyHouseholderOnTheLeft(
 
92
  const EssentialPart& essential,
 
93
  const Scalar& tau,
 
94
  Scalar* workspace)
 
95
{
 
96
  if(rows() == 1)
 
97
  {
 
98
    *this *= Scalar(1)-tau;
 
99
  }
 
100
  else
 
101
  {
 
102
    Map<typename internal::plain_row_type<PlainObject>::type> tmp(workspace,cols());
 
103
    Block<Derived, EssentialPart::SizeAtCompileTime, Derived::ColsAtCompileTime> bottom(derived(), 1, 0, rows()-1, cols());
 
104
    tmp.noalias() = essential.adjoint() * bottom;
 
105
    tmp += this->row(0);
 
106
    this->row(0) -= tau * tmp;
 
107
    bottom.noalias() -= tau * essential * tmp;
 
108
  }
 
109
}
 
110
 
 
111
template<typename Derived>
 
112
template<typename EssentialPart>
 
113
void MatrixBase<Derived>::applyHouseholderOnTheRight(
 
114
  const EssentialPart& essential,
 
115
  const Scalar& tau,
 
116
  Scalar* workspace)
 
117
{
 
118
  if(cols() == 1)
 
119
  {
 
120
    *this *= Scalar(1)-tau;
 
121
  }
 
122
  else
 
123
  {
 
124
    Map<typename internal::plain_col_type<PlainObject>::type> tmp(workspace,rows());
 
125
    Block<Derived, Derived::RowsAtCompileTime, EssentialPart::SizeAtCompileTime> right(derived(), 0, 1, rows(), cols()-1);
 
126
    tmp.noalias() = right * essential.conjugate();
 
127
    tmp += this->col(0);
 
128
    this->col(0) -= tau * tmp;
 
129
    right.noalias() -= tau * tmp * essential.transpose();
 
130
  }
 
131
}
 
132
 
 
133
#endif // EIGEN_HOUSEHOLDER_H