diff options
author | Antonio Sanchez <cantonios@google.com> | 2021-01-21 09:44:42 -0800 |
---|---|---|
committer | Antonio Sanchez <cantonios@google.com> | 2021-01-21 09:44:42 -0800 |
commit | 25d8498f8ba29c8dc055dd56113facbdbe154345 (patch) | |
tree | 5095712269388fdbbdeb0ba400f08d7e37fa2c55 /test | |
parent | 660c6b857c2a5fbcffe99721b0f327267309a736 (diff) |
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.
Diffstat (limited to 'test')
-rw-r--r-- | test/stable_norm.cpp | 17 |
1 files 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<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] |