| 114 | } |
| 115 | |
| 116 | Tensor 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 | |
| 150 | int64 CopyIntoSparseTensor(const Tensor& in, const int batch, |
| 151 | const int64 offset, Tensor* indices, |
no test coverage detected