@@ -240,28 +240,29 @@ class SparseTensorSliceDatasetOp : public DatasetOpKernel {
240240 OP_REQUIRES_OK (ctx, ctx->input (" dense_shape" , &dense_shape));
241241
242242 OP_REQUIRES (ctx, TensorShapeUtils::IsMatrix (indices->shape ()),
243- errors::InvalidArgument (
244- " Input indices should be a matrix but received shape " ,
245- indices->shape ().DebugString ()));
246-
247- const auto num_indices = indices->NumElements ();
248- const auto num_values = values->NumElements ();
249- if (num_indices == 0 || num_values == 0 ) {
250- OP_REQUIRES (ctx, num_indices == num_values,
251- errors::InvalidArgument (
252- " If indices or values are empty, the other one must also "
253- " be. Got indices of shape " ,
254- indices->shape ().DebugString (), " and values of shape " ,
255- values->shape ().DebugString ()));
256- }
243+ errors::InvalidArgument (" Input indices must be a matrix. Got: " ,
244+ indices->shape ().DebugString ()));
257245 OP_REQUIRES (ctx, TensorShapeUtils::IsVector (values->shape ()),
258- errors::InvalidArgument (
259- " Input values should be a vector but received shape " ,
260- indices->shape ().DebugString ()));
246+ errors::InvalidArgument (" Input values must be a vector. Got: " ,
247+ values->shape ().DebugString ()));
261248 OP_REQUIRES (ctx, TensorShapeUtils::IsVector (dense_shape->shape ()),
249+ errors::InvalidArgument (" Input shape must be a vector. Got: " ,
250+ dense_shape->shape ().DebugString ()));
251+ OP_REQUIRES (
252+ ctx, values->shape ().dim_size (0 ) == indices->shape ().dim_size (0 ),
253+ errors::InvalidArgument (
254+ " Number of values must match first dimension of indices. " , " Got " ,
255+ values->shape ().dim_size (0 ),
256+ " values, indices shape: " , indices->shape ().DebugString ()));
257+ OP_REQUIRES (
258+ ctx, dense_shape->shape ().dim_size (0 ) == indices->shape ().dim_size (1 ),
259+ errors::InvalidArgument (
260+ " Number of dimensions must match second dimension of indices. " ,
261+ " Got " , dense_shape->shape ().dim_size (0 ),
262+ " dimensions, indices shape: " , indices->shape ().DebugString ()));
263+ OP_REQUIRES (ctx, dense_shape->NumElements () > 0 ,
262264 errors::InvalidArgument (
263- " Input shape should be a vector but received shape " ,
264- dense_shape->shape ().DebugString ()));
265+ " The shape argument requires at least one element." ));
265266
266267 // We currently ensure that `sparse_tensor` is ordered in the
267268 // batch dimension.
0 commit comments