From 8584f21392772170b007ee3b3fbfed17fe19e32f Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Sat, 1 Dec 2018 20:58:09 +0000 Subject: [PATCH] Fix SparseDenseCwise's broadcasting issue This fix tries to address the issue raised in 24072. In `sparse_dense_cwise_mul/add` operations the broadcasting only support dense to sparse, though the validation was not captured. This fix fixes the validation in SparseDenseBinaryOpShared so that error could be thrown correctly. This fix fixes 24072. Signed-off-by: Yong Tang --- tensorflow/core/kernels/sparse_dense_binary_op_shared.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tensorflow/core/kernels/sparse_dense_binary_op_shared.cc b/tensorflow/core/kernels/sparse_dense_binary_op_shared.cc index ac48202ada2..3a6b66302f7 100644 --- a/tensorflow/core/kernels/sparse_dense_binary_op_shared.cc +++ b/tensorflow/core/kernels/sparse_dense_binary_op_shared.cc @@ -88,12 +88,11 @@ class SparseDenseBinaryOpShared : public OpKernel { const auto rhs_dims = BCast::FromShape(dense_t->shape()); BCast b(lhs_dims, rhs_dims, false); // false for keeping the same num dims. - // True iff (size(lhs) > size(rhs)), or (sizes equal, lhs cwise rhs). + // True iff (size(lhs) >= size(rhs)) and all dims in lhs is smaller or equal to dims in rhs (from right to left). auto VecGreaterEq = [](ArraySlice lhs, ArraySlice rhs) { - if (lhs.size() > rhs.size()) return true; if (lhs.size() < rhs.size()) return false; - for (size_t i = 0; i < lhs.size(); ++i) { - if (lhs[i] < rhs[i]) return false; + for (size_t i = 0; i < rhs.size(); ++i) { + if (lhs[lhs.size() - 1 - i] < rhs[rhs.size() - 1 - i]) return false; } return true; };