From f64b6dc38783c503ae4449979ad360ef78129599 Mon Sep 17 00:00:00 2001 From: ddavis-2015 Date: Wed, 22 Nov 2023 13:31:45 -0800 Subject: [PATCH] Fix zero-point calculation rounding error @tensorflow/micro Use roundf to correctly round negative values. bug=fixes #2327 --- tensorflow/lite/micro/test_helpers.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tensorflow/lite/micro/test_helpers.h b/tensorflow/lite/micro/test_helpers.h index 2a6204feb12..6315b9fecdc 100644 --- a/tensorflow/lite/micro/test_helpers.h +++ b/tensorflow/lite/micro/test_helpers.h @@ -1,4 +1,4 @@ -/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. +/* Copyright 2023 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ limitations under the License. #define TENSORFLOW_LITE_MICRO_TEST_HELPERS_H_ #include +#include #include #include #include @@ -325,7 +326,7 @@ inline float SymmetricScaleFromMinMax(const float min, const float max) { template inline int ZeroPointFromMinMax(const float min, const float max) { return static_cast(std::numeric_limits::min()) + - static_cast(-min / ScaleFromMinMax(min, max) + 0.5f); + static_cast(roundf(-min / ScaleFromMinMax(min, max))); } } // namespace testing