MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / PrintTensor

Function PrintTensor

tensorflow/cc/framework/cc_op_gen.cc:165–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165string PrintTensor(const TensorProto& tensor_proto) {
166 Tensor t(tensor_proto.dtype());
167 CHECK(t.FromProto(tensor_proto));
168 const int64 num_elts = t.NumElements();
169 switch (t.dtype()) {
170 case DT_FLOAT:
171 return PrintArray(num_elts, t.flat<float>().data());
172 case DT_DOUBLE:
173 return PrintArray(num_elts, t.flat<double>().data());
174 case DT_INT32:
175 return PrintArray(num_elts, t.flat<int32>().data());
176 case DT_UINT8:
177 case DT_QUINT8:
178 return PrintArray(num_elts, t.flat<uint8>().data());
179 case DT_UINT16:
180 case DT_QUINT16:
181 return PrintArray(num_elts, t.flat<uint16>().data());
182 case DT_INT16:
183 case DT_QINT16:
184 return PrintArray(num_elts, t.flat<int16>().data());
185 case DT_INT8:
186 case DT_QINT8:
187 return PrintArray(num_elts, t.flat<int8>().data());
188 case DT_INT64:
189 return PrintArray(num_elts, t.flat<int64>().data());
190 case DT_BOOL:
191 return PrintArray(num_elts, t.flat<bool>().data());
192 case DT_STRING: {
193 string ret;
194 for (int64 i = 0; i < num_elts; ++i) {
195 if (i > 0) strings::StrAppend(&ret, " ");
196 strings::StrAppend(&ret, absl::CEscape(t.flat<tstring>()(i)));
197 }
198 return ret;
199 }
200 default: {
201 LOG(FATAL) << "Not handling type " << EnumName_DataType(t.dtype());
202 return string();
203 }
204 }
205}
206
207string PrintTensorProto(const TensorProto& proto) {
208 return strings::StrCat("Input::Initializer(", "{", PrintTensor(proto), "}, ",

Callers 1

PrintTensorProtoFunction · 0.70

Calls 7

CEscapeFunction · 0.85
PrintArrayFunction · 0.70
StrAppendFunction · 0.50
dtypeMethod · 0.45
FromProtoMethod · 0.45
NumElementsMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected