Skip to content

Commit c878ce6

Browse files
girvingkeveman
authored andcommitted
Change DebugString behavior to ShortDebugString
The old behavior of DebugString is needlessly verbose and is quite confusing for scalar shapes (it produced the empty string). Now DebugString is the same as ShortDebugString. A future commit will remove ShortDebugString. Change: 112590646
1 parent c8eaac9 commit c878ce6

5 files changed

Lines changed: 13 additions & 35 deletions

File tree

tensorflow/core/framework/tensor_shape.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,6 @@ TensorShapeIter TensorShape::end() const {
149149
}
150150

151151
string TensorShape::DebugString() const {
152-
TensorShapeProto proto;
153-
AsProto(&proto);
154-
return proto.ShortDebugString();
155-
}
156-
157-
string TensorShape::ShortDebugString() const {
158152
return strings::StrCat(
159153
"[", str_util::Join(gtl::ArraySlice<int64>(dim_sizes_), ","), "]");
160154
}

tensorflow/core/framework/tensor_slice_test.cc

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,29 +157,20 @@ TEST(TensorSliceTest, SliceTensorShape) {
157157
TensorShape x({2, 4, 5, 8});
158158
TensorShape y;
159159
EXPECT_OK(a.SliceTensorShape(x, &y));
160-
EXPECT_EQ(
161-
"dim { size: 1 } "
162-
"dim { size: 4 } "
163-
"dim { size: 1 } "
164-
"dim { size: 6 }",
165-
y.DebugString());
160+
EXPECT_EQ("[1,4,1,6]", y.DebugString());
166161
}
167162

168-
// An invalid application -- dimension 2 is out of bound
163+
// An invalid application -- dimension 2 is out of bounds
169164
{
170165
TensorSlice a = TensorSlice::ParseOrDie("1,1:1,4:-:-");
171166
TensorShape x({2, 4, 5, 8});
172167
TensorShape y;
173168
EXPECT_EQ(
174169
"Internal: "
175170
"Extent in dimension 1 out of bounds: "
176-
"shape = dim { size: 2 } "
177-
"dim { size: 4 } "
178-
"dim { size: 5 } "
179-
"dim { size: 8 }, "
180-
"slice = 1,1:1,4:-:-",
171+
"shape = [2,4,5,8], slice = 1,1:1,4:-:-",
181172
a.SliceTensorShape(x, &y).ToString());
182-
EXPECT_EQ("", y.DebugString());
173+
EXPECT_EQ("[]", y.DebugString());
183174
}
184175
}
185176

tensorflow/core/public/tensor_shape.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,15 @@ class TensorShape {
124124

125125
/// For error messages.
126126
string DebugString() const;
127-
string ShortDebugString() const;
128-
// TODO(vrv): Consolidate DebugString() and ShortDebugString() into one
129-
// function that is not verbose and works for scalars.
127+
128+
/// Same as DebugString()
129+
string ShortDebugString() const { return DebugString(); }
130+
// TODO(irving): Remove, used to be different but isn't now.
130131

131132
/// Same as `TensorShape(proto).ShortDebugString()` but doesn't crash for
132133
/// invalid protos.
133134
static string ShortDebugString(const TensorShapeProto& proto);
135+
// TODO(irving): Rename to DebugString.
134136

135137
private:
136138
// Recalculates the dimensions of this tensor after they are modified.

tensorflow/core/util/tensor_slice_reader_test.cc

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,7 @@ void SimpleFloatHelper(TensorSliceWriter::CreateBuilderFunction create_function,
115115
TensorShape shape;
116116
DataType type;
117117
EXPECT_TRUE(reader.HasTensor("test", &shape, &type));
118-
EXPECT_EQ(
119-
"dim { size: 4 } "
120-
"dim { size: 5 }",
121-
shape.DebugString());
118+
EXPECT_EQ("[4,5]", shape.DebugString());
122119
EXPECT_EQ(DT_FLOAT, type);
123120
EXPECT_FALSE(reader.HasTensor("don't exist", nullptr, nullptr));
124121
}
@@ -242,10 +239,7 @@ void SimpleIntXHelper(TensorSliceWriter::CreateBuilderFunction create_function,
242239
TensorShape shape;
243240
DataType type;
244241
EXPECT_TRUE(reader.HasTensor("test", &shape, &type));
245-
EXPECT_EQ(
246-
"dim { size: 4 } "
247-
"dim { size: 5 }",
248-
shape.DebugString());
242+
EXPECT_EQ("[4,5]", shape.DebugString());
249243
EXPECT_EQ(DataTypeToEnum<T>::v(), type);
250244
EXPECT_FALSE(reader.HasTensor("don't exist", nullptr, nullptr));
251245
}
@@ -379,10 +373,7 @@ void CachedTensorSliceReaderTesterHelper(
379373
TensorShape shape;
380374
DataType type;
381375
EXPECT_TRUE(reader->HasTensor("test", &shape, &type));
382-
EXPECT_EQ(
383-
"dim { size: 4 } "
384-
"dim { size: 5 }",
385-
shape.DebugString());
376+
EXPECT_EQ("[4,5]", shape.DebugString());
386377
EXPECT_EQ(DT_FLOAT, type);
387378
EXPECT_FALSE(reader->HasTensor("don't exist", nullptr, nullptr));
388379
}

tensorflow/python/kernel_tests/constant_op_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def testShape(self):
536536

537537
with self.assertRaisesOpError(
538538
"must feed a value for placeholder tensor 'p' with dtype float and "
539-
"shape dim { size: 10 } dim { size: 10 }"):
539+
r"shape \[10,10\]"):
540540
p_identity.eval()
541541

542542
with self.assertRaisesWithPredicateMatch(

0 commit comments

Comments
 (0)