mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-10-20 03:51:06 +08:00
Cleanup: Move 2x2 real SVD into the Jacobi module where it naturally belongs.
This commit is contained in:
parent
99f8512985
commit
da55dd1471
@ -32,8 +32,6 @@
|
|||||||
* \endcode
|
* \endcode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "src/misc/RealSvd2x2.h"
|
|
||||||
|
|
||||||
// IWYU pragma: begin_exports
|
// IWYU pragma: begin_exports
|
||||||
#include "src/Eigenvalues/Tridiagonalization.h"
|
#include "src/Eigenvalues/Tridiagonalization.h"
|
||||||
#include "src/Eigenvalues/RealSchur.h"
|
#include "src/Eigenvalues/RealSchur.h"
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// IWYU pragma: begin_exports
|
// IWYU pragma: begin_exports
|
||||||
#include "src/misc/RealSvd2x2.h"
|
|
||||||
#include "src/SVD/UpperBidiagonalization.h"
|
#include "src/SVD/UpperBidiagonalization.h"
|
||||||
#include "src/SVD/SVDBase.h"
|
#include "src/SVD/SVDBase.h"
|
||||||
#include "src/SVD/JacobiSVD.h"
|
#include "src/SVD/JacobiSVD.h"
|
||||||
|
@ -420,6 +420,34 @@ EIGEN_DEVICE_FUNC void inline apply_rotation_in_the_plane(DenseBase<VectorX>& xp
|
|||||||
x, incrx, y, incry, size, c, s);
|
x, incrx, y, incry, size, c, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename MatrixType, typename RealScalar, typename Index>
|
||||||
|
void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q, JacobiRotation<RealScalar>* j_left,
|
||||||
|
JacobiRotation<RealScalar>* j_right) {
|
||||||
|
using std::abs;
|
||||||
|
using std::sqrt;
|
||||||
|
Matrix<RealScalar, 2, 2> m;
|
||||||
|
m << numext::real(matrix.coeff(p, p)), numext::real(matrix.coeff(p, q)), numext::real(matrix.coeff(q, p)),
|
||||||
|
numext::real(matrix.coeff(q, q));
|
||||||
|
JacobiRotation<RealScalar> rot1;
|
||||||
|
RealScalar t = m.coeff(0, 0) + m.coeff(1, 1);
|
||||||
|
RealScalar d = m.coeff(1, 0) - m.coeff(0, 1);
|
||||||
|
|
||||||
|
if (abs(d) < (std::numeric_limits<RealScalar>::min)()) {
|
||||||
|
rot1.s() = RealScalar(0);
|
||||||
|
rot1.c() = RealScalar(1);
|
||||||
|
} else {
|
||||||
|
// If d!=0, then t/d cannot overflow because the magnitude of the
|
||||||
|
// entries forming d are not too small compared to the ones forming t.
|
||||||
|
RealScalar u = t / d;
|
||||||
|
RealScalar tmp = sqrt(RealScalar(1) + numext::abs2(u));
|
||||||
|
rot1.s() = RealScalar(1) / tmp;
|
||||||
|
rot1.c() = u / tmp;
|
||||||
|
}
|
||||||
|
m.applyOnTheLeft(0, 1, rot1);
|
||||||
|
j_right->makeJacobi(m, 0, 1);
|
||||||
|
*j_left = rot1 * j_right->transpose();
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace internal
|
} // end namespace internal
|
||||||
|
|
||||||
} // end namespace Eigen
|
} // end namespace Eigen
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
// This file is part of Eigen, a lightweight C++ template library
|
|
||||||
// for linear algebra.
|
|
||||||
//
|
|
||||||
// Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
|
|
||||||
// Copyright (C) 2013-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
|
|
||||||
//
|
|
||||||
// This Source Code Form is subject to the terms of the Mozilla
|
|
||||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
||||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
||||||
|
|
||||||
#ifndef EIGEN_REALSVD2X2_H
|
|
||||||
#define EIGEN_REALSVD2X2_H
|
|
||||||
|
|
||||||
// IWYU pragma: private
|
|
||||||
#include "./InternalHeaderCheck.h"
|
|
||||||
|
|
||||||
namespace Eigen {
|
|
||||||
|
|
||||||
namespace internal {
|
|
||||||
|
|
||||||
template <typename MatrixType, typename RealScalar, typename Index>
|
|
||||||
void real_2x2_jacobi_svd(const MatrixType &matrix, Index p, Index q, JacobiRotation<RealScalar> *j_left,
|
|
||||||
JacobiRotation<RealScalar> *j_right) {
|
|
||||||
using std::abs;
|
|
||||||
using std::sqrt;
|
|
||||||
Matrix<RealScalar, 2, 2> m;
|
|
||||||
m << numext::real(matrix.coeff(p, p)), numext::real(matrix.coeff(p, q)), numext::real(matrix.coeff(q, p)),
|
|
||||||
numext::real(matrix.coeff(q, q));
|
|
||||||
JacobiRotation<RealScalar> rot1;
|
|
||||||
RealScalar t = m.coeff(0, 0) + m.coeff(1, 1);
|
|
||||||
RealScalar d = m.coeff(1, 0) - m.coeff(0, 1);
|
|
||||||
|
|
||||||
if (abs(d) < (std::numeric_limits<RealScalar>::min)()) {
|
|
||||||
rot1.s() = RealScalar(0);
|
|
||||||
rot1.c() = RealScalar(1);
|
|
||||||
} else {
|
|
||||||
// If d!=0, then t/d cannot overflow because the magnitude of the
|
|
||||||
// entries forming d are not too small compared to the ones forming t.
|
|
||||||
RealScalar u = t / d;
|
|
||||||
RealScalar tmp = sqrt(RealScalar(1) + numext::abs2(u));
|
|
||||||
rot1.s() = RealScalar(1) / tmp;
|
|
||||||
rot1.c() = u / tmp;
|
|
||||||
}
|
|
||||||
m.applyOnTheLeft(0, 1, rot1);
|
|
||||||
j_right->makeJacobi(m, 0, 1);
|
|
||||||
*j_left = rot1 * j_right->transpose();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end namespace internal
|
|
||||||
|
|
||||||
} // end namespace Eigen
|
|
||||||
|
|
||||||
#endif // EIGEN_REALSVD2X2_H
|
|
Loading…
x
Reference in New Issue
Block a user