1 | /* Copyright 2021 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/eager/immediate_execution_tensor_handle.h" |
17 | |
18 | namespace tensorflow { |
19 | |
20 | std::string ImmediateExecutionTensorHandle::DebugString() const { |
21 | PartialTensorShape shape; |
22 | std::string shape_string; |
23 | if (Shape(&shape).ok()) { |
24 | shape_string = shape.DebugString(); |
25 | } else { |
26 | shape_string = "<error computing shape>" ; |
27 | } |
28 | std::string value_string; |
29 | if (!SummarizeValue(value_string).ok()) { |
30 | value_string = "<error computing value>" ; |
31 | } |
32 | if (value_string.length() > 100) { |
33 | // The default NumPy-style output can be distractingly long in error |
34 | // messages. |
35 | value_string = absl::StrCat(value_string.substr(0, 100), " [...]" ); |
36 | } |
37 | Status s; |
38 | const char* device_name = DeviceName(&s); |
39 | if (!s.ok()) { |
40 | device_name = "<error fetching device name>" ; |
41 | } |
42 | return absl::StrCat("TensorHandle(" , value_string, ", shape=" , shape_string, |
43 | ", dtype=" , DataType_Name(DataType()), ", device=\"" , |
44 | device_name, "\")" ); |
45 | } |
46 | |
47 | Status ImmediateExecutionTensorHandle::SummarizeValue( |
48 | std::string& summary) const { |
49 | Status status; |
50 | AbstractTensorPtr resolved( |
51 | // TODO(allenl): Resolve should be const, and the caches that get updated |
52 | // marked mutable. |
53 | const_cast<ImmediateExecutionTensorHandle*>(this)->Resolve(&status)); |
54 | if (!status.ok()) { |
55 | return status; |
56 | } |
57 | summary = resolved->SummarizeValue(); |
58 | return OkStatus(); |
59 | } |
60 | |
61 | } // namespace tensorflow |
62 | |