Skip to content
Permalink
Browse files Browse the repository at this point in the history
Add missing validation to sparse dense cwise ops.
PiperOrigin-RevId: 415543133
Change-Id: I5baf3284e919338afb96178c468ad3d3cb0d956c
  • Loading branch information
mihaimaruseac authored and tensorflower-gardener committed Dec 10, 2021
1 parent 68d1298 commit 1b54cad
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tensorflow/core/kernels/sparse_dense_binary_op_shared.cc
Expand Up @@ -78,11 +78,24 @@ class SparseDenseBinaryOpShared : public OpKernel {
"but received shapes: ",
values_t->shape().DebugString(), " and ",
shape_t->shape().DebugString()));
OP_REQUIRES(
ctx, TensorShapeUtils::IsVector(shape_t->shape()),
errors::InvalidArgument("Input sp_shape must be a vector. Got: ",
shape_t->shape().DebugString()));
OP_REQUIRES(
ctx, values_t->dim_size(0) == indices_t->dim_size(0),
errors::InvalidArgument(
"The first dimension of values and indices should match. (",
values_t->dim_size(0), " vs. ", indices_t->dim_size(0), ")"));
OP_REQUIRES(
ctx, shape_t->shape().dim_size(0) == indices_t->shape().dim_size(1),
errors::InvalidArgument(
"Number of dimensions must match second dimension of indices. ",
"Got ", shape_t->shape().dim_size(0),
" dimensions, indices shape: ", indices_t->shape().DebugString()));
OP_REQUIRES(ctx, shape_t->NumElements() > 0,
errors::InvalidArgument(
"The shape argument requires at least one element."));

const auto indices_mat = indices_t->matrix<int64_t>();
const auto shape_vec = shape_t->vec<int64_t>();
Expand Down

0 comments on commit 1b54cad

Please sign in to comment.