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

Function FeatureDenseCopy

tensorflow/core/util/example_proto_helper.cc:61–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61Status FeatureDenseCopy(const std::size_t out_index, const string& name,
62 const string& key, const DataType& dtype,
63 const TensorShape& shape, const Feature& feature,
64 Tensor* out) {
65 const std::size_t num_elements = shape.num_elements();
66 const std::size_t offset = out_index * num_elements;
67
68 switch (dtype) {
69 case DT_INT64: {
70 const Int64List& values = feature.int64_list();
71 if (static_cast<size_t>(values.value_size()) != num_elements) {
72 return errors::InvalidArgument(
73 "Name: ", name, ", Key: ", key, ", Index: ", out_index,
74 ". Number of int64 values != expected. "
75 "values size: ",
76 values.value_size(), " but output shape: ", shape.DebugString());
77 }
78 auto out_p = out->flat<int64>().data() + offset;
79 std::copy_n(values.value().data(), num_elements, out_p);
80 return Status::OK();
81 }
82 case DT_FLOAT: {
83 const FloatList& values = feature.float_list();
84 if (static_cast<size_t>(values.value_size()) != num_elements) {
85 return errors::InvalidArgument(
86 "Name: ", name, ", Key: ", key, ", Index: ", out_index,
87 ". Number of float values != expected. "
88 "values size: ",
89 values.value_size(), " but output shape: ", shape.DebugString());
90 }
91 auto out_p = out->flat<float>().data() + offset;
92 std::copy_n(values.value().data(), num_elements, out_p);
93 return Status::OK();
94 }
95 case DT_STRING: {
96 const BytesList& values = feature.bytes_list();
97 if (static_cast<size_t>(values.value_size()) != num_elements) {
98 return errors::InvalidArgument(
99 "Name: ", name, ", Key ", key, ", Index: ", out_index,
100 ". Number of bytes values != expected. "
101 "Values size: ",
102 values.value_size(), " but output shape: ", shape.DebugString());
103 }
104 auto out_p = out->flat<tstring>().data() + offset;
105 std::transform(values.value().data(),
106 values.value().data() + num_elements, out_p,
107 [](const string* s) { return *s; });
108 return Status::OK();
109 }
110 default:
111 return errors::InvalidArgument("Invalid input dtype: ",
112 DataTypeString(dtype));
113 }
114}
115
116Tensor FeatureSparseCopy(const std::size_t batch, const string& key,
117 const DataType& dtype, const Feature& feature) {

Callers 2

ComputeMethod · 0.85

Calls 7

InvalidArgumentFunction · 0.85
transformFunction · 0.50
DataTypeStringFunction · 0.50
num_elementsMethod · 0.45
DebugStringMethod · 0.45
dataMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected