aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Zongheng Yang <zongheng@google.com>2016-09-01 07:32:38 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-09-01 08:46:38 -0700
commite146dc63437d23acf4e221350d9a52a2599f2975 (patch)
tree3fdd744d23b3b20f9a26dc3f8dc2c4b330612acf
parentb36576e48db9c9c5448a1f15ded364f4f1f5a9d9 (diff)
TensorSlice: fix a subtle, long-standing bug with IsFullAt().
Discovered during the development of V2 format. This has not been triggered since the TensorSlice class has seen little use outside of the V1 codepath. That code path has made careful use of it to not violate the implicit contract (that lengths_[d] == -1 iff starts_[d] == 0). Change: 131950924
-rw-r--r--tensorflow/core/framework/tensor_slice.h4
-rw-r--r--tensorflow/core/framework/tensor_slice_test.cc4
2 files changed, 5 insertions, 3 deletions
diff --git a/tensorflow/core/framework/tensor_slice.h b/tensorflow/core/framework/tensor_slice.h
index 8c4a2adeb3..fca40e0894 100644
--- a/tensorflow/core/framework/tensor_slice.h
+++ b/tensorflow/core/framework/tensor_slice.h
@@ -94,7 +94,9 @@ class TensorSlice {
}
// If we have a full slice along dimension "d".
- bool IsFullAt(int d) const { return lengths_[d] < 0; }
+ bool IsFullAt(int d) const {
+ return lengths_[d] == kFullExtent && starts_[d] == 0;
+ }
// If this is a full slice, i.e. IsFullAt(d) for every d.
bool IsFull() const;
diff --git a/tensorflow/core/framework/tensor_slice_test.cc b/tensorflow/core/framework/tensor_slice_test.cc
index e26c840998..bb32fa0724 100644
--- a/tensorflow/core/framework/tensor_slice_test.cc
+++ b/tensorflow/core/framework/tensor_slice_test.cc
@@ -273,8 +273,8 @@ TEST(TensorSliceTest, Deserialization) {
TensorSlice ts3(proto3);
// Both serializations should be interpreted the same.
- EXPECT_EQ("0,5:0,10:14,1:-:-", ts2.DebugString());
- EXPECT_EQ("0,5:0,10:14,1:-:-", ts3.DebugString());
+ EXPECT_EQ("0,5:0,10:14,1:1,-1:-", ts2.DebugString());
+ EXPECT_EQ("0,5:0,10:14,1:1,-1:-", ts3.DebugString());
}
TEST(TensorSliceTest, UpdateToCover) {