@@ -17,11 +17,13 @@ limitations under the License.
1717
1818#include < stdint.h>
1919
20+ #include < cstddef>
2021#include < limits>
2122#ifndef TF_LITE_STATIC_MEMORY
2223#include < string>
2324#endif // TF_LITE_STATIC_MEMORY
2425
26+ #include " absl/types/span.h"
2527#include " tensorflow/lite/core/c/builtin_op_data.h"
2628#include " tensorflow/lite/core/c/common.h"
2729#ifndef NDEBUG
@@ -341,6 +343,30 @@ bool IsMobilePlatform();
341343// Returns whether there is unspecified dimension in the tensor's dim signature.
342344bool HasUnspecifiedDimension (const TfLiteTensor* tensor);
343345
346+ /* *
347+ * Calculates the product of the given dimensions. Returns an error if any of
348+ * the dimensions is negative or if the product overflows.
349+ * @param context The context to use for error reporting.
350+ * @param dims The dimensions to multiply.
351+ * @param error_message The error message to use if an error is encountered.
352+ * @param product The output parameter to store the product.
353+ */
354+ TfLiteStatus CheckedShapeProduct (TfLiteContext* context,
355+ absl::Span<const int > dims,
356+ const char * error_message, size_t & product);
357+
358+ /* *
359+ * Calculates the product of the given dimensions. Returns an error if any of
360+ * the dimensions is negative or if the product overflows.
361+ * @param context The context to use for error reporting.
362+ * @param dims The dimensions to multiply.
363+ * @param error_message The error message to use if an error is encountered.
364+ * @param product The output parameter to store the product.
365+ */
366+ TfLiteStatus CheckedShapeProductToInt (TfLiteContext* context,
367+ absl::Span<const int > dims,
368+ const char * error_message, int & product);
369+
344370} // namespace tflite
345371
346372#endif // TENSORFLOW_LITE_KERNELS_KERNEL_UTIL_H_
0 commit comments