From 9e305d6766fb8517cf2a0d46c5784565ed3a9b92 Mon Sep 17 00:00:00 2001 From: liuqi Date: Tue, 17 Apr 2018 19:45:16 +0800 Subject: [PATCH] Use positive random float for op test. --- mace/ops/ops_test_util.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mace/ops/ops_test_util.h b/mace/ops/ops_test_util.h index aca7853d..8c5a3829 100644 --- a/mace/ops/ops_test_util.h +++ b/mace/ops/ops_test_util.h @@ -133,7 +133,7 @@ class OpsTestNet { template void AddRandomInput(const std::string &name, const std::vector &shape, - bool positive = false) { + bool positive = true) { Tensor *input = ws_.CreateTensor(name, GetDeviceAllocator(D), DataTypeToEnum::v()); input->Resize(shape); @@ -308,7 +308,8 @@ class OpsTestBase : public ::testing::Test { template void GenerateRandomRealTypeData(const std::vector &shape, - std::vector *res) { + std::vector *res, + bool positive = true) { MACE_CHECK_NOTNULL(res); std::random_device rd; @@ -321,9 +322,14 @@ void GenerateRandomRealTypeData(const std::vector &shape, if (DataTypeToEnum::value == DT_HALF) { std::generate(res->begin(), res->end(), - [&gen, &nd] { return half_float::half_cast(nd(gen)); }); + [&gen, &nd, positive] { + return half_float::half_cast( + positive ? std::abs(nd(gen)) : nd(gen)); + }); } else { - std::generate(res->begin(), res->end(), [&gen, &nd] { return nd(gen); }); + std::generate(res->begin(), res->end(), [&gen, &nd, positive] { + return positive ? std::abs(nd(gen)) : nd(gen); + }); } } -- GitLab