From a680ed0bf03d5ca3b2c4a70c0d95eeebc20da6d6 Mon Sep 17 00:00:00 2001 From: Prakalp Srivastava <prakalps@google.com> Date: Thu, 17 Oct 2019 17:06:29 -0700 Subject: [PATCH] For Substr check pos and len rank equality only when their rank is known. This fixes a bug where len has unknown rank, while pos has known shape. The WithRank(...) check returned error in such a case. Here we compare their ranks only when both pos and len have known rank. PiperOrigin-RevId: 275370109 Change-Id: I8df36f3d4dcf3104e246e8605689b9ded3d9c783 --- tensorflow/core/ops/string_ops.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tensorflow/core/ops/string_ops.cc b/tensorflow/core/ops/string_ops.cc index 4d9ad0a56c5..d0247e0cb94 100644 --- a/tensorflow/core/ops/string_ops.cc +++ b/tensorflow/core/ops/string_ops.cc @@ -261,8 +261,10 @@ REGISTER_OP("Substr") ShapeHandle pos_shape = c->input(1); ShapeHandle len_shape = c->input(2); ShapeHandle unused; - // Check that pos/len have same rank - TF_RETURN_IF_ERROR(c->WithRank(pos_shape, c->Rank(len_shape), &unused)); + // If len rank is known, check that pos and len have the same rank + if (c->RankKnown(len_shape)) { + TF_RETURN_IF_ERROR(c->WithRank(pos_shape, c->Rank(len_shape), &unused)); + } // Check that dimensions are equal for (int32 i = 0; i < c->Rank(pos_shape); ++i) { DimensionHandle pos_dim = c->Dim(pos_shape, i);