From addd1a52db369841d9a8eceb38caa4944bf68ccc Mon Sep 17 00:00:00 2001 From: TFLM-bot Date: Thu, 9 Jul 2026 15:00:27 +0000 Subject: [PATCH] Sync from upstream TF. --- tensorflow/lite/kernels/internal/common.h | 19 ++++++++++--------- .../lite/tools/flatbuffer_utils_test.py | 6 +++--- tensorflow/lite/tools/test_utils.py | 2 +- tensorflow/lite/tools/visualize_test.py | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tensorflow/lite/kernels/internal/common.h b/tensorflow/lite/kernels/internal/common.h index 929168b7098..aa5248470fe 100644 --- a/tensorflow/lite/kernels/internal/common.h +++ b/tensorflow/lite/kernels/internal/common.h @@ -1007,19 +1007,19 @@ template struct NdArrayDesc { // The "extent" of each dimension. Indices along dimension d must be in the // half-open interval [0, extents[d]). - int extents[N]; + int64_t extents[N]; // The number of *elements* (not bytes) between consecutive indices of each // dimension. - int strides[N]; + int64_t strides[N]; }; // DO NOT USE THIS FUNCTION FOR NEW FUNCTIONALITY BEYOND IMPLEMENTING // BROADCASTING. // // Same as Offset(), except takes as NdArrayDesc instead of Dims. -inline int SubscriptToIndex(const NdArrayDesc<4>& desc, int i0, int i1, int i2, - int i3) { +inline int64_t SubscriptToIndex(const NdArrayDesc<4>& desc, int i0, int i1, + int i2, int i3) { TFLITE_DCHECK(i0 >= 0 && i0 < desc.extents[0]); TFLITE_DCHECK(i1 >= 0 && i1 < desc.extents[1]); TFLITE_DCHECK(i2 >= 0 && i2 < desc.extents[2]); @@ -1028,13 +1028,13 @@ inline int SubscriptToIndex(const NdArrayDesc<4>& desc, int i0, int i1, int i2, i3 * desc.strides[3]; } -inline int SubscriptToIndex(const NdArrayDesc<5>& desc, int indexes[5]) { +inline int64_t SubscriptToIndex(const NdArrayDesc<5>& desc, int indexes[5]) { return indexes[0] * desc.strides[0] + indexes[1] * desc.strides[1] + indexes[2] * desc.strides[2] + indexes[3] * desc.strides[3] + indexes[4] * desc.strides[4]; } -inline int SubscriptToIndex(const NdArrayDesc<8>& desc, int indexes[8]) { +inline int64_t SubscriptToIndex(const NdArrayDesc<8>& desc, int indexes[8]) { return indexes[0] * desc.strides[0] + indexes[1] * desc.strides[1] + indexes[2] * desc.strides[2] + indexes[3] * desc.strides[3] + indexes[4] * desc.strides[4] + indexes[5] * desc.strides[5] + @@ -1102,7 +1102,7 @@ inline void NdArrayDescsForElementwiseBroadcast(const Dims& input0_dims, template TFLITE_NOINLINE void CopyDimsToDesc(const RuntimeShape& input_shape, NdArrayDesc* desc_out) { - int desc_stride = 1; + int64_t desc_stride = 1; for (int i = N - 1; i >= 0; --i) { desc_out->extents[i] = input_shape.Dims(i); desc_out->strides[i] = desc_stride; @@ -1283,8 +1283,9 @@ inline int LegacyHowManyThreads(int max_num_threads, int rows, int cols, static constexpr std::uint64_t min_cubic_size_per_thread = 64 * 1024; // We can only multiply two out of three sizes without risking overflow - const std::uint64_t cubic_size = - std::uint64_t(rows) * std::uint64_t(cols) * std::uint64_t(depth); + const std::uint64_t cubic_size = static_cast(rows) * + static_cast(cols) * + static_cast(depth); thread_count = std::min( thread_count, static_cast(cubic_size / min_cubic_size_per_thread)); diff --git a/tensorflow/lite/tools/flatbuffer_utils_test.py b/tensorflow/lite/tools/flatbuffer_utils_test.py index aca36815c1b..b604d178f3a 100644 --- a/tensorflow/lite/tools/flatbuffer_utils_test.py +++ b/tensorflow/lite/tools/flatbuffer_utils_test.py @@ -18,9 +18,9 @@ import subprocess import sys -from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.python import schema_py_generated as schema # pylint:disable=g-direct-tensorflow-import -from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.tools import flatbuffer_utils -from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.tools import test_utils +from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.python import schema_py_generated as schema # pylint:disable=g-direct-tensorflow-import +from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.tools import flatbuffer_utils +from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.tools import test_utils from tensorflow.python.framework import test_util from tensorflow.python.platform import test diff --git a/tensorflow/lite/tools/test_utils.py b/tensorflow/lite/tools/test_utils.py index d446f21c3df..d71267bb401 100644 --- a/tensorflow/lite/tools/test_utils.py +++ b/tensorflow/lite/tools/test_utils.py @@ -18,7 +18,7 @@ """ import flatbuffers -from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.python import schema_py_generated as schema_fb +from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.python import schema_py_generated as schema_fb TFLITE_SCHEMA_VERSION = 3 diff --git a/tensorflow/lite/tools/visualize_test.py b/tensorflow/lite/tools/visualize_test.py index 1fe431960b9..5f00a189272 100644 --- a/tensorflow/lite/tools/visualize_test.py +++ b/tensorflow/lite/tools/visualize_test.py @@ -16,8 +16,8 @@ import os import re -from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.tools import test_utils -from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.tools import visualize +from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.tools import test_utils +from tflite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite_micro.tensorflow.lite.tools import visualize from tensorflow.python.framework import test_util from tensorflow.python.platform import test