@@ -150,6 +150,7 @@ class SparseSparseBinaryOpShared : public OpKernel {
150
150
151
151
const int64 a_nnz = a_indices_t ->dim_size (0 );
152
152
const int64 b_nnz = b_indices_t ->dim_size (0 );
153
+
153
154
const auto a_values = a_values_t ->vec <T>();
154
155
const auto b_values = b_values_t ->vec <T>();
155
156
@@ -166,6 +167,14 @@ class SparseSparseBinaryOpShared : public OpKernel {
166
167
" Input shapes should be a vector but received shapes " ,
167
168
a_shape_t ->shape ().DebugString (), " and " ,
168
169
b_shape_t ->shape ().DebugString ()));
170
+ const int num_dims = a_indices_t ->dim_size (1 );
171
+ OP_REQUIRES (
172
+ ctx, a_shape_t ->NumElements () == num_dims,
173
+ errors::InvalidArgument (" Second dimension of a_indices and length of "
174
+ " a_shape must match, got " ,
175
+ num_dims, " and " , a_shape_t ->NumElements ()));
176
+ OP_REQUIRES (ctx, num_dims > 0 ,
177
+ errors::InvalidArgument (" Tensors must not be empty" ));
169
178
OP_REQUIRES (ctx, a_shape_t ->IsSameSize (*b_shape_t ),
170
179
errors::InvalidArgument (
171
180
" Operands do not have the same ranks; got shapes: " ,
@@ -180,12 +189,6 @@ class SparseSparseBinaryOpShared : public OpKernel {
180
189
" for dimension " , i));
181
190
}
182
191
183
- OP_REQUIRES (
184
- ctx, a_indices_t ->dim_size (1 ) == b_indices_t ->dim_size (1 ),
185
- errors::InvalidArgument (
186
- " Indices' dimensions do not match: got " , a_indices_t ->dim_size (1 ),
187
- " and " , b_indices_t ->dim_size (1 ), " for the second dimension." ));
188
- const int num_dims = a_indices_t ->dim_size (1 );
189
192
const auto a_indices_mat = a_indices_t ->matrix <int64>();
190
193
const auto b_indices_mat = b_indices_t ->matrix <int64>();
191
194
std::vector<T> a_augmented_values, b_augmented_values;
0 commit comments