Medial Code Documentation
Loading...
Searching...
No Matches
External
Eigen
src
Householder
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
{
44
VectorBlock<Derived, internal::decrement_size<Base::SizeAtCompileTime>::ret
>
essentialPart
(derived(), 1, size()-1);
45
makeHouseholder(
essentialPart
,
tau
, beta);
46
}
47
63
template
<
typename
Derived>
64
template
<
typename
EssentialPart>
65
void
MatrixBase<Derived>::makeHouseholder
(
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
)
74
VectorBlock<const Derived, EssentialPart::SizeAtCompileTime>
tail(derived(), 1, size()-1);
75
76
RealScalar
tailSqNorm
= size()==1 ? RealScalar(0) : tail.squaredNorm();
77
Scalar
c0
= coeff(0);
78
const
RealScalar
tol
= (std::numeric_limits<RealScalar>::min)();
79
80
if
(
tailSqNorm
<=
tol
&& numext::abs2(numext::imag(
c0
))<=
tol
)
81
{
82
tau
= RealScalar(0);
83
beta = numext::real(
c0
);
84
essential
.setZero();
85
}
86
else
87
{
88
beta = sqrt(numext::abs2(
c0
) +
tailSqNorm
);
89
if
(numext::real(
c0
)>=RealScalar(0))
90
beta = -beta;
91
essential
= tail / (
c0
- beta);
92
tau
=
conj
((beta -
c0
) / beta);
93
}
94
}
95
111
template
<
typename
Derived>
112
template
<
typename
EssentialPart>
113
void
MatrixBase<Derived>::applyHouseholderOnTheLeft
(
114
const
EssentialPart
&
essential
,
115
const
Scalar&
tau
,
116
Scalar*
workspace
)
117
{
118
if
(rows() == 1)
119
{
120
*
this
*= Scalar(1)-
tau
;
121
}
122
else
123
{
124
Map<typename internal::plain_row_type<PlainObject>::type
> tmp(
workspace
,cols());
125
Block<Derived, EssentialPart::SizeAtCompileTime, Derived::ColsAtCompileTime>
bottom
(derived(), 1, 0, rows()-1, cols());
126
tmp.noalias() =
essential
.adjoint() *
bottom
;
127
tmp += this->row(0);
128
this->row(0) -=
tau
* tmp;
129
bottom
.noalias() -=
tau
*
essential
* tmp;
130
}
131
}
132
148
template
<
typename
Derived>
149
template
<
typename
EssentialPart>
150
void
MatrixBase<Derived>::applyHouseholderOnTheRight
(
151
const
EssentialPart
&
essential
,
152
const
Scalar&
tau
,
153
Scalar*
workspace
)
154
{
155
if
(cols() == 1)
156
{
157
*
this
*= Scalar(1)-
tau
;
158
}
159
else
160
{
161
Map<typename internal::plain_col_type<PlainObject>::type
> tmp(
workspace
,rows());
162
Block<Derived, Derived::RowsAtCompileTime, EssentialPart::SizeAtCompileTime>
right(derived(), 0, 1, rows(), cols()-1);
163
tmp.noalias() = right *
essential
.conjugate();
164
tmp += this->col(0);
165
this->col(0) -=
tau
* tmp;
166
right.noalias() -=
tau
* tmp *
essential
.transpose();
167
}
168
}
169
170
}
// end namespace Eigen
171
172
#endif
// EIGEN_HOUSEHOLDER_H
Eigen::MatrixBase
Base class for all dense matrices, vectors, and expressions.
Definition
MatrixBase.h:50
Eigen::Solve
Pseudo expression representing a solving operation.
Definition
Solve.h:63
Eigen::internal::decrement_size
Definition
Householder.h:18
Generated on Mon Sep 15 2025 12:12:02 for Medial Code Documentation by
1.9.8