From 4923de56ec94fff7770df259ab7f2288a74feb41 Mon Sep 17 00:00:00 2001 From: Mihai Maruseac Date: Mon, 2 Aug 2021 13:52:28 -0700 Subject: [PATCH] Don't do any work when reshaping 0 elements sparse tensor. If reshaping to 0 elements tensor, check that input has no elements. If reshaping no elements input, check that output has no elements. PiperOrigin-RevId: 388296986 Change-Id: Iadc9fe7252e14313ca987e69bf0d7042fd10232a --- tensorflow/core/kernels/reshape_util.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tensorflow/core/kernels/reshape_util.cc b/tensorflow/core/kernels/reshape_util.cc index d0d54738..9b520334 100644 --- a/tensorflow/core/kernels/reshape_util.cc +++ b/tensorflow/core/kernels/reshape_util.cc @@ -173,6 +173,12 @@ void ReshapeSparseTensor(OpKernelContext *context, TensorShape({nnz, output_rank}), &result_indices)); if (nnz > 0) { + OP_REQUIRES( + context, dense_size > 0 && product > 0, + errors::InvalidArgument( + "Input tensor has ", nnz, " non zero elements but input shape (", + input_shape.DebugString(), ") or output shape (", + output_shape.DebugString(), ") is empty")); OP_REQUIRES_OK(context, functor::ReshapeSparseTensorFunctor()( input_shape, output_shape, input_indices_in.matrix(), -- 2.27.0