File indexing completed on 2025-01-19 09:52:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EIGEN_REALSVD2X2_H
0012 #define EIGEN_REALSVD2X2_H
0013
0014 namespace Eigen {
0015
0016 namespace internal {
0017
0018 template<typename MatrixType, typename RealScalar, typename Index>
0019 void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q,
0020 JacobiRotation<RealScalar> *j_left,
0021 JacobiRotation<RealScalar> *j_right)
0022 {
0023 using std::sqrt;
0024 using std::abs;
0025 Matrix<RealScalar,2,2> m;
0026 m << numext::real(matrix.coeff(p,p)), numext::real(matrix.coeff(p,q)),
0027 numext::real(matrix.coeff(q,p)), numext::real(matrix.coeff(q,q));
0028 JacobiRotation<RealScalar> rot1;
0029 RealScalar t = m.coeff(0,0) + m.coeff(1,1);
0030 RealScalar d = m.coeff(1,0) - m.coeff(0,1);
0031
0032 if(abs(d) < (std::numeric_limits<RealScalar>::min)())
0033 {
0034 rot1.s() = RealScalar(0);
0035 rot1.c() = RealScalar(1);
0036 }
0037 else
0038 {
0039
0040
0041 RealScalar u = t / d;
0042 RealScalar tmp = sqrt(RealScalar(1) + numext::abs2(u));
0043 rot1.s() = RealScalar(1) / tmp;
0044 rot1.c() = u / tmp;
0045 }
0046 m.applyOnTheLeft(0,1,rot1);
0047 j_right->makeJacobi(m,0,1);
0048 *j_left = rot1 * j_right->transpose();
0049 }
0050
0051 }
0052
0053 }
0054
0055 #endif