mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-03 06:50:57 +08:00
work around stupid msvc error when constructing at compile time an expression
that involves a division by zero, even if the numeric type has floating point
This commit is contained in:
parent
e5073746f3
commit
9044c98cff
@ -239,6 +239,9 @@ struct ei_qr_preconditioner_impl<MatrixType, HouseholderQRPreconditioner, Precon
|
||||
* \a p is the greater dimension, meaning that it is still of the same order of complexity as the faster bidiagonalizing R-SVD algorithms.
|
||||
* In particular, like any R-SVD, it takes advantage of non-squareness in that its complexity is only linear in the greater dimension.
|
||||
*
|
||||
* If the input matrix has inf or nan coefficients, the result of the computation is undefined, but the computation is guaranteed to
|
||||
* terminate in finite (and reasonable) time.
|
||||
*
|
||||
* The possible values for QRPreconditioner are:
|
||||
* \li ColPivHouseholderQRPreconditioner is the default. In practice it's very safe. It uses column-pivoting QR.
|
||||
* \li FullPivHouseholderQRPreconditioner, is the safest and slowest. It uses full-pivoting QR.
|
||||
|
@ -209,18 +209,30 @@ void jacobisvd_method()
|
||||
VERIFY_IS_APPROX(m.jacobiSvd(ComputeFullU|ComputeFullV).solve(m), m);
|
||||
}
|
||||
|
||||
// work around stupid msvc error when constructing at compile time an expression that involves
|
||||
// a division by zero, even if the numeric type has floating point
|
||||
template<typename Scalar>
|
||||
EIGEN_DONT_INLINE Scalar zero() { return Scalar(0); }
|
||||
|
||||
template<typename MatrixType>
|
||||
void jacobisvd_inf_nan()
|
||||
{
|
||||
// all this function does is verify we don't iterate infinitely on nan/inf values
|
||||
|
||||
JacobiSVD<MatrixType> svd;
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
Scalar some_inf = Scalar(1) / Scalar(0);
|
||||
Scalar some_inf = Scalar(1) / zero<Scalar>();
|
||||
VERIFY((some_inf - some_inf) != (some_inf - some_inf));
|
||||
svd.compute(MatrixType::Constant(10,10,some_inf), ComputeFullU | ComputeFullV);
|
||||
Scalar some_nan = Scalar(0) / Scalar(0);
|
||||
|
||||
Scalar some_nan = zero<Scalar>() / zero<Scalar>();
|
||||
VERIFY(some_nan != some_nan);
|
||||
svd.compute(MatrixType::Constant(10,10,some_nan), ComputeFullU | ComputeFullV);
|
||||
|
||||
MatrixType m = MatrixType::Zero(10,10);
|
||||
m(ei_random<int>(0,9), ei_random<int>(0,9)) = some_inf;
|
||||
svd.compute(m, ComputeFullU | ComputeFullV);
|
||||
|
||||
m = MatrixType::Zero(10,10);
|
||||
m(ei_random<int>(0,9), ei_random<int>(0,9)) = some_nan;
|
||||
svd.compute(m, ComputeFullU | ComputeFullV);
|
||||
|
Loading…
Reference in New Issue
Block a user