$darkmode
Eigen  5.0.1-dev
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 <jacob.benoit.1@gmail.com>
5 // Copyright (C) 2013-2016 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_REALSVD2X2_H
12 #define EIGEN_REALSVD2X2_H
13 
14 // IWYU pragma: private
15 #include "./InternalHeaderCheck.h"
16 
17 namespace Eigen {
18 
19 namespace internal {
20 
21 template <typename MatrixType, typename RealScalar, typename Index>
22 void 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
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:82
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)