1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. |
2 | |
3 | Licensed under the Apache License, Version 2.0 (the "License"); |
4 | you may not use this file except in compliance with the License. |
5 | You may obtain a copy of the License at |
6 | |
7 | http://www.apache.org/licenses/LICENSE-2.0 |
8 | |
9 | Unless required by applicable law or agreed to in writing, software |
10 | distributed under the License is distributed on an "AS IS" BASIS, |
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | See the License for the specific language governing permissions and |
13 | limitations under the License. |
14 | ==============================================================================*/ |
15 | |
16 | #include "tensorflow/c/kernels/tensor_shape_utils.h" |
17 | |
18 | #include <string> |
19 | |
20 | #include "tensorflow/c/tf_tensor.h" |
21 | #include "tensorflow/core/platform/logging.h" |
22 | #include "tensorflow/core/platform/strcat.h" |
23 | |
24 | namespace tensorflow { |
25 | |
26 | std::string ShapeDebugString(TF_Tensor* tensor) { |
27 | // A TF_Tensor cannot have an unknown rank. |
28 | CHECK_GE(TF_NumDims(tensor), 0); |
29 | tensorflow::string s = "[" ; |
30 | for (int i = 0; i < TF_NumDims(tensor); ++i) { |
31 | if (i > 0) tensorflow::strings::StrAppend(&s, "," ); |
32 | int64_t dim = TF_Dim(tensor, i); |
33 | // A TF_Tensor cannot have an unknown dimension. |
34 | CHECK_GE(dim, 0); |
35 | tensorflow::strings::StrAppend(&s, dim); |
36 | } |
37 | tensorflow::strings::StrAppend(&s, "]" ); |
38 | return s; |
39 | } |
40 | } // namespace tensorflow |
41 | |