aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/util/util.cc
diff options
context:
space:
mode:
authorGravatar Vijay Vasudevan <vrv@google.com>2015-12-10 16:42:22 -0800
committerGravatar Vijay Vasudevan <vrv@google.com>2015-12-10 16:42:22 -0800
commitd9cfc64a2ddf05c0b093c8fb6704c67452ee3ea0 (patch)
tree0310b5935c816541c4cee940bf990dc627a97141 /tensorflow/core/util/util.cc
parent475edf8e949e9913e74d2f4b183f271198ecda86 (diff)
TensorFlow: merge changes from internal
Change 109945903 Make unsorted_segment_sum detect negative indices Previously it crashed. This fixes #466. Also improve the error message to say which index is problematic. Change 109942557 Fix the conv_grad_input with stride 2. + We always call the Cudnn implementation even if we have an incompatible padding. Base CL: 109948577
Diffstat (limited to 'tensorflow/core/util/util.cc')
-rw-r--r--tensorflow/core/util/util.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/tensorflow/core/util/util.cc b/tensorflow/core/util/util.cc
index 77cf853773..eaa211e170 100644
--- a/tensorflow/core/util/util.cc
+++ b/tensorflow/core/util/util.cc
@@ -15,7 +15,10 @@ limitations under the License.
#include "tensorflow/core/util/util.h"
+#include "tensorflow/core/lib/gtl/inlined_vector.h"
+#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/platform/logging.h"
+
namespace tensorflow {
StringPiece NodeNamePrefix(const StringPiece& op_name) {
@@ -93,4 +96,28 @@ string PrintMemory(const char* ptr, int n) {
return ret;
}
+string SliceDebugString(const TensorShape& shape, const int64 flat) {
+ // Special case rank 0 and 1
+ const int dims = shape.dims();
+ if (dims == 0) return "";
+ if (dims == 1) return strings::StrCat("[", flat, "]");
+
+ // Compute strides
+ gtl::InlinedVector<int64, 32> strides(dims);
+ strides.back() = 1;
+ for (int i = dims - 2; i >= 0; i--) {
+ strides[i] = strides[i + 1] * shape.dim_size(i + 1);
+ }
+
+ // Unflatten index
+ int64 left = flat;
+ string result;
+ for (int i = 0; i < dims; i++) {
+ strings::StrAppend(&result, i ? "," : "[", left / strides[i]);
+ left %= strides[i];
+ }
+ strings::StrAppend(&result, "]");
+ return result;
+}
+
} // namespace tensorflow