RealSvd2x2.h
Go to the documentation of this file.
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 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
18 namespace internal {
19 
20 template<typename MatrixType, typename RealScalar, typename Index>
21 void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q,
24 {
25  using std::sqrt;
26  using std::abs;
28  m << numext::real(matrix.coeff(p,p)), numext::real(matrix.coeff(p,q)),
29  numext::real(matrix.coeff(q,p)), numext::real(matrix.coeff(q,q));
31  RealScalar t = m.coeff(0,0) + m.coeff(1,1);
32  RealScalar d = m.coeff(1,0) - m.coeff(0,1);
33 
35  {
36  rot1.s() = RealScalar(0);
37  rot1.c() = RealScalar(1);
38  }
39  else
40  {
41  // If d!=0, then t/d cannot overflow because the magnitude of the
42  // entries forming d are not too small compared to the ones forming t.
43  RealScalar u = t / d;
44  RealScalar tmp = sqrt(RealScalar(1) + numext::abs2(u));
45  rot1.s() = RealScalar(1) / tmp;
46  rot1.c() = u / tmp;
47  }
48  m.applyOnTheLeft(0,1,rot1);
49  j_right->makeJacobi(m,0,1);
50  *j_left = rot1 * j_right->transpose();
51 }
52 
53 } // end namespace internal
54 
55 } // end namespace Eigen
56 
57 #endif // EIGEN_REALSVD2X2_H
Matrix3f m
const AbsReturnType abs() const
const SqrtReturnType sqrt() const
RealReturnType real() const
float * p
Matrix< float, 1, Dynamic > MatrixType
Rotation given by a cosine-sine pair.
Definition: Jacobi.h:37
Scalar & s()
Definition: Jacobi.h:51
bool makeJacobi(const MatrixBase< Derived > &, Index p, Index q)
Definition: Jacobi.h:141
JacobiRotation transpose() const
Definition: Jacobi.h:65
Scalar & c()
Definition: Jacobi.h:49
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:684
void real_2x2_jacobi_svd(const MatrixType &matrix, Index p, Index q, JacobiRotation< RealScalar > *j_left, JacobiRotation< RealScalar > *j_right)
Definition: RealSvd2x2.h:21
bool abs2(bool x)
: InteropHeaders
Definition: Core:139
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)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)