mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
Fix overflow when checking SVD accuracy
This commit is contained in:
parent
b0d08869a9
commit
c3e398d138
@ -33,6 +33,7 @@ void svd_check_full(const MatrixType& m, const SvdType& svd)
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef typename MatrixType::Scalar Scalar;
|
typedef typename MatrixType::Scalar Scalar;
|
||||||
|
typedef typename MatrixType::RealScalar RealScalar;
|
||||||
typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime> MatrixUType;
|
typedef Matrix<Scalar, RowsAtCompileTime, RowsAtCompileTime> MatrixUType;
|
||||||
typedef Matrix<Scalar, ColsAtCompileTime, ColsAtCompileTime> MatrixVType;
|
typedef Matrix<Scalar, ColsAtCompileTime, ColsAtCompileTime> MatrixVType;
|
||||||
|
|
||||||
@ -40,7 +41,10 @@ void svd_check_full(const MatrixType& m, const SvdType& svd)
|
|||||||
sigma.diagonal() = svd.singularValues().template cast<Scalar>();
|
sigma.diagonal() = svd.singularValues().template cast<Scalar>();
|
||||||
MatrixUType u = svd.matrixU();
|
MatrixUType u = svd.matrixU();
|
||||||
MatrixVType v = svd.matrixV();
|
MatrixVType v = svd.matrixV();
|
||||||
VERIFY_IS_APPROX(m, u * sigma * v.adjoint());
|
RealScalar scaling = m.cwiseAbs().maxCoeff();
|
||||||
|
if(scaling<=(std::numeric_limits<RealScalar>::min)())
|
||||||
|
scaling = RealScalar(1);
|
||||||
|
VERIFY_IS_APPROX(m/scaling, u * (sigma/scaling) * v.adjoint());
|
||||||
VERIFY_IS_UNITARY(u);
|
VERIFY_IS_UNITARY(u);
|
||||||
VERIFY_IS_UNITARY(v);
|
VERIFY_IS_UNITARY(v);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user