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

Function CreateTensorProto

tensorflow/core/framework/tensor_util.h:277–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275// are determined based on type of the 'values' parameter.
276template <typename Type>
277typename std::enable_if<internal::TensorProtoHelper<Type>::value,
278 TensorProto>::type
279CreateTensorProto(const std::vector<Type>& values,
280 const std::vector<size_t>& shape) {
281 TensorProto tensor;
282 TensorShapeProto tensor_shape_proto;
283 internal::SetTensorProtoShape(shape, &tensor_shape_proto);
284 if (TensorShape(tensor_shape_proto).num_elements() != values.size()) {
285 LOG(ERROR) << "Shape and number of values (" << values.size()
286 << ") are incompatible.";
287 return tensor;
288 }
289 using TypeHelper = internal::TensorProtoHelper<Type>;
290 tensor.set_dtype(TypeHelper::GetDataType());
291 tensor.mutable_tensor_shape()->Swap(&tensor_shape_proto);
292 TypeHelper::AddValues(values.begin(), values.end(), &tensor);
293 return tensor;
294}
295
296// Converts values in tensor to run-length encoded compressed form.
297//

Callers 1

TESTFunction · 0.85

Calls 9

SetTensorProtoShapeFunction · 0.85
TensorShapeClass · 0.70
GetDataTypeFunction · 0.50
num_elementsMethod · 0.45
sizeMethod · 0.45
set_dtypeMethod · 0.45
SwapMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

TESTFunction · 0.68