summaryrefslogtreecommitdiff
path: root/nn/runtime/test/fuzzing
diff options
context:
space:
mode:
authorXusong Wang <xusongw@google.com>2019-12-18 12:40:19 -0800
committerXusong Wang <xusongw@google.com>2019-12-19 19:24:22 +0000
commitbccb79706e0a6933ca8c1181fdf87a5414766bde (patch)
treef26621e61594deded399e720ac387ae6b7b05cec /nn/runtime/test/fuzzing
parent33bb6cb75668e85a87880c8a77f08c975673e979 (diff)
downloadml-bccb79706e0a6933ca8c1181fdf87a5414766bde.tar.gz
Fix NN_IS_FLOAT to comply with aosp/986032.
Bug: 146465110 Test: mma Test: CTS Test: NNT_static_fuzzing Change-Id: Ib5db08ea8a32ac5c974955ea0eb88eadc29cd45c
Diffstat (limited to 'nn/runtime/test/fuzzing')
-rw-r--r--nn/runtime/test/fuzzing/RandomGraphGenerator.cpp2
-rw-r--r--nn/runtime/test/fuzzing/RandomGraphGeneratorUtils.h11
2 files changed, 4 insertions, 9 deletions
diff --git a/nn/runtime/test/fuzzing/RandomGraphGenerator.cpp b/nn/runtime/test/fuzzing/RandomGraphGenerator.cpp
index 0e82dc143..319183854 100644
--- a/nn/runtime/test/fuzzing/RandomGraphGenerator.cpp
+++ b/nn/runtime/test/fuzzing/RandomGraphGenerator.cpp
@@ -303,7 +303,7 @@ void expectNear(const RandomOperand& op, const OperandBuffer& test,
// Accumulate bias and MSE. Use relative bias and MSE for floating point values.
double diff = actual - expected;
- if constexpr (NN_IS_FLOAT(T)) {
+ if constexpr (nnIsFloat<T>) {
diff /= std::max(1.0, std::abs(expected));
}
bias += diff;
diff --git a/nn/runtime/test/fuzzing/RandomGraphGeneratorUtils.h b/nn/runtime/test/fuzzing/RandomGraphGeneratorUtils.h
index 833572774..0df56c9a0 100644
--- a/nn/runtime/test/fuzzing/RandomGraphGeneratorUtils.h
+++ b/nn/runtime/test/fuzzing/RandomGraphGeneratorUtils.h
@@ -417,18 +417,13 @@ inline bool getBernoulli(double p) {
return dis(RandomNumberGenerator::generator);
}
-// std::is_floating_point_v<_Float16> evaluates to true in CTS build target but false in
-// NeuralNetworksTest_static, so we define getUniform<_Float16> explicitly here if not CTS.
-#ifdef NNTEST_CTS
-#define NN_IS_FLOAT(T) std::is_floating_point_v<T>
-#else
-#define NN_IS_FLOAT(T) std::is_floating_point_v<T> || std::is_same_v<T, _Float16>
-#endif
+template <typename T>
+inline constexpr bool nnIsFloat = std::is_floating_point_v<T> || std::is_same_v<T, _Float16>;
// getUniform for floating point values operates on a open interval (lower, upper).
// This is important for generating a scale that is greater than but not equal to a lower bound.
template <typename T>
-inline std::enable_if_t<NN_IS_FLOAT(T), T> getUniform(T lower, T upper) {
+inline std::enable_if_t<nnIsFloat<T>, T> getUniform(T lower, T upper) {
float nextLower = std::nextafter(static_cast<float>(lower), std::numeric_limits<float>::max());
std::uniform_real_distribution<float> dis(nextLower, upper);
return dis(RandomNumberGenerator::generator);