diff options
author | Blake Hechtman <blakehechtman@google.com> | 2018-01-12 08:24:05 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-01-12 08:27:42 -0800 |
commit | 18f860fd8e1fdffd80633cf5ac32f895423dfa8d (patch) | |
tree | c54ab78cf52a281ebf1055bdf7fd18ef9279e6a3 | |
parent | 0bb22b8d777ff8397c93efd10fa62fe9b46081c0 (diff) |
Generate more numerically stable random inputs.
PiperOrigin-RevId: 181746741
-rw-r--r-- | tensorflow/compiler/xla/tests/test_utils.cc | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/tensorflow/compiler/xla/tests/test_utils.cc b/tensorflow/compiler/xla/tests/test_utils.cc index d7346d65c8..8b10aef5b8 100644 --- a/tensorflow/compiler/xla/tests/test_utils.cc +++ b/tensorflow/compiler/xla/tests/test_utils.cc @@ -25,14 +25,21 @@ namespace { template <typename FloatT> void PopulateWithRandomFloatingPointData(Literal* literal) { - // TODO(b/69179121): Generate data that is less self-similar. CHECK_EQ(literal->shape().element_type(), primitive_util::NativeToPrimitiveType<FloatT>()); std::minstd_rand0 engine; - std::uniform_real_distribution<FloatT> generator(-0.9f, 1.0f); + // Create uniform numbers between 1 and 1.125 ot avoid creating denormal + // numbers. + std::uniform_real_distribution<FloatT> generator(1.0f, 1.125f); TF_CHECK_OK(literal->Populate<FloatT>( - [&](tensorflow::gtl::ArraySlice<int64> /*indices*/) { - return generator(engine); + [&](tensorflow::gtl::ArraySlice<int64> indices) { + // Generate a random uniforma number from -0.0625 and 0.0625 and bias it + // with a position dependent nubmer with mean 0.037109375. These number + // should allow for long chains of accumulation without being too close + // to zero or to large to accumulate all numbers accurately. + return (generator(engine) - 1.0625) + + static_cast<FloatT>(Product(indices) % 113 - 47) / + static_cast<FloatT>(256.0f); })); } |