mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-11-27 06:30:28 +08:00
Fix stable_norm_1 test.
Test enters an infinite loop if size is 1x1 when choosing to select unique indices for adding `inf` and `NaN` to the input. Here we revert to non-unique indices, and split the `hypotNorm` check into two cases: one where both `inf` and `NaN` are added, and one where only `NaN` is added.
This commit is contained in:
parent
660c6b857c
commit
25d8498f8b
@ -161,12 +161,8 @@ template<typename MatrixType> void stable_norm(const MatrixType& m)
|
||||
|
||||
// mix
|
||||
{
|
||||
// Ensure unique indices otherwise inf may be overwritten by NaN.
|
||||
Index i2, j2;
|
||||
do {
|
||||
i2 = internal::random<Index>(0,rows-1);
|
||||
j2 = internal::random<Index>(0,cols-1);
|
||||
} while (i2 == i && j2 == j);
|
||||
Index i2 = internal::random<Index>(0,rows-1);
|
||||
Index j2 = internal::random<Index>(0,cols-1);
|
||||
v = vrand;
|
||||
v(i,j) = -std::numeric_limits<RealScalar>::infinity();
|
||||
v(i2,j2) = std::numeric_limits<RealScalar>::quiet_NaN();
|
||||
@ -174,8 +170,13 @@ template<typename MatrixType> void stable_norm(const MatrixType& m)
|
||||
VERIFY(!(numext::isfinite)(v.norm())); VERIFY((numext::isnan)(v.norm()));
|
||||
VERIFY(!(numext::isfinite)(v.stableNorm())); VERIFY((numext::isnan)(v.stableNorm()));
|
||||
VERIFY(!(numext::isfinite)(v.blueNorm())); VERIFY((numext::isnan)(v.blueNorm()));
|
||||
// hypot propagates inf over NaN.
|
||||
VERIFY(!(numext::isfinite)(v.hypotNorm())); VERIFY((numext::isinf)(v.hypotNorm()));
|
||||
if (i2 != i || j2 != j) {
|
||||
// hypot propagates inf over NaN.
|
||||
VERIFY(!(numext::isfinite)(v.hypotNorm())); VERIFY((numext::isinf)(v.hypotNorm()));
|
||||
} else {
|
||||
// inf is overwritten by NaN, expect norm to be NaN.
|
||||
VERIFY(!(numext::isfinite)(v.hypotNorm())); VERIFY((numext::isnan)(v.hypotNorm()));
|
||||
}
|
||||
}
|
||||
|
||||
// stableNormalize[d]
|
||||
|
Loading…
Reference in New Issue
Block a user