Skip to content
Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mihaimaruseac authored and tensorflower-gardener committed Aug 2, 2021
1 parent 062534a commit 4923de5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tensorflow/core/kernels/reshape_util.cc
Expand Up @@ -174,6 +174,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<Device>()(
context, input_shape, output_shape,
input_indices_in.matrix<int64>(),
Expand Down

0 comments on commit 4923de5

Please sign in to comment.