From 25d8498f8ba29c8dc055dd56113facbdbe154345 Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Thu, 21 Jan 2021 09:44:42 -0800 Subject: [PATCH] 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. --- test/stable_norm.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/stable_norm.cpp b/test/stable_norm.cpp index 008e35d87..cb8a80c18 100644 --- a/test/stable_norm.cpp +++ b/test/stable_norm.cpp @@ -161,12 +161,8 @@ template void stable_norm(const MatrixType& m) // mix { - // Ensure unique indices otherwise inf may be overwritten by NaN. - Index i2, j2; - do { - i2 = internal::random(0,rows-1); - j2 = internal::random(0,cols-1); - } while (i2 == i && j2 == j); + Index i2 = internal::random(0,rows-1); + Index j2 = internal::random(0,cols-1); v = vrand; v(i,j) = -std::numeric_limits::infinity(); v(i2,j2) = std::numeric_limits::quiet_NaN(); @@ -174,8 +170,13 @@ template 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]