Eigen  3.4.90 (git rev 5a9f66fb35d03a4da9ef8976e67a61b30aa16dcf)
 
Loading...
Searching...
No Matches
RealSvd2x2.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2009-2010 Benoit Jacob <[email protected]>
5// Copyright (C) 2013-2016 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_REALSVD2X2_H
12#define EIGEN_REALSVD2X2_H
13
14// IWYU pragma: private
15#include "./InternalHeaderCheck.h"
16
17namespace Eigen {
18
19namespace internal {
20
21template <typename MatrixType, typename RealScalar, typename Index>
22void real_2x2_jacobi_svd(const MatrixType &matrix, Index p, Index q, JacobiRotation<RealScalar> *j_left,
23 JacobiRotation<RealScalar> *j_right) {
24 using std::abs;
25 using std::sqrt;
26 Matrix<RealScalar, 2, 2> m;
27 m << numext::real(matrix.coeff(p, p)), numext::real(matrix.coeff(p, q)), numext::real(matrix.coeff(q, p)),
28 numext::real(matrix.coeff(q, q));
29 JacobiRotation<RealScalar> rot1;
30 RealScalar t = m.coeff(0, 0) + m.coeff(1, 1);
31 RealScalar d = m.coeff(1, 0) - m.coeff(0, 1);
32
33 if (abs(d) < (std::numeric_limits<RealScalar>::min)()) {
34 rot1.s() = RealScalar(0);
35 rot1.c() = RealScalar(1);
36 } else {
37 // If d!=0, then t/d cannot overflow because the magnitude of the
38 // entries forming d are not too small compared to the ones forming t.
39 RealScalar u = t / d;
40 RealScalar tmp = sqrt(RealScalar(1) + numext::abs2(u));
41 rot1.s() = RealScalar(1) / tmp;
42 rot1.c() = u / tmp;
43 }
44 m.applyOnTheLeft(0, 1, rot1);
45 j_right->makeJacobi(m, 0, 1);
46 *j_left = rot1 * j_right->transpose();
47}
48
49} // end namespace internal
50
51} // end namespace Eigen
52
53#endif // EIGEN_REALSVD2X2_H
Namespace containing all symbols from the Eigen library.
Definition Core:137
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)