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

Function FeatureSparseCopy

tensorflow/core/util/example_proto_helper.cc:116–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116Tensor FeatureSparseCopy(const std::size_t batch, const string& key,
117 const DataType& dtype, const Feature& feature) {
118 switch (dtype) {
119 case DT_INT64: {
120 const Int64List& values = feature.int64_list();
121 const int64 num_elements = values.value_size();
122 Tensor out(dtype, TensorShape({num_elements}));
123 auto out_p = out.flat<int64>().data();
124 std::copy_n(values.value().data(), num_elements, out_p);
125 return out;
126 }
127 case DT_FLOAT: {
128 const FloatList& values = feature.float_list();
129 const int64 num_elements = values.value_size();
130 Tensor out(dtype, TensorShape({num_elements}));
131 auto out_p = out.flat<float>().data();
132 std::copy_n(values.value().data(), num_elements, out_p);
133 return out;
134 }
135 case DT_STRING: {
136 const BytesList& values = feature.bytes_list();
137 const int64 num_elements = values.value_size();
138 Tensor out(dtype, TensorShape({num_elements}));
139 auto out_p = out.flat<tstring>().data();
140 std::transform(values.value().data(),
141 values.value().data() + num_elements, out_p,
142 [](const string* s) { return *s; });
143 return out;
144 }
145 default:
146 LOG(FATAL) << "not supposed to be here. dtype requested: " << dtype;
147 }
148}
149
150int64 CopyIntoSparseTensor(const Tensor& in, const int batch,
151 const int64 offset, Tensor* indices,

Callers 2

ComputeMethod · 0.85

Calls 4

TensorShapeClass · 0.50
transformFunction · 0.50
dataMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected