Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:52:22

0001 // This file is part of Eigen, a lightweight C++ template library
0002 // for linear algebra.
0003 //
0004 // Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
0005 // Copyright (C) 2013-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
0006 //
0007 // This Source Code Form is subject to the terms of the Mozilla
0008 // Public License v. 2.0. If a copy of the MPL was not distributed
0009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
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     // If d!=0, then t/d cannot overflow because the magnitude of the
0040     // entries forming d are not too small compared to the ones forming t.
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 } // end namespace internal
0052 
0053 } // end namespace Eigen
0054 
0055 #endif // EIGEN_REALSVD2X2_H