MCPcopy Create free account
hub / github.com/alibaba/zvec / load_record_sparse

Method load_record_sparse

tools/core/txt_input_reader.h:233–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231 }
232
233 bool load_record_sparse(const std::string &input,
234 const std::string &first_sep,
235 const std::string &second_sep,
236 std::vector<uint64_t> &keys,
237 std::vector<SparseData<T>> &sparse_data,
238 std::vector<std::vector<uint64_t>> &taglists) {
239 std::fstream qf(input, std::ios::in);
240
241 if (!qf.is_open()) {
242 std::cerr << "open file failed! [" << input << "]" << std::endl;
243 return false;
244 }
245
246 bool ret;
247 uint32_t count = 0;
248 std::string buffer;
249
250 while (getline(qf, buffer)) {
251 buffer.erase(buffer.find_last_not_of('\n') + 1);
252 if (buffer.empty()) {
253 continue;
254 }
255 std::vector<std::string> res;
256 ailego::StringHelper::Split(buffer, first_sep, &res);
257 if (res.size() < 2) {
258 std::cerr << "skip record : " << buffer << std::endl;
259 continue;
260 }
261
262 uint64_t key = atol(res[0].c_str());
263
264 // load sparse feature
265 uint32_t sparse_count = 0;
266 std::vector<uint32_t> sparse_indices;
267 std::vector<T> sparse_feature;
268
269 if (res.size() <= 2) {
270 std::cerr << "field erorr, key: " << key << std::endl;
271 continue;
272 }
273
274 ret = load_from_string_sparse(key, res[2], second_sep, sparse_indices,
275 sparse_feature, &sparse_count);
276 if (!ret) {
277 std::cerr << "load sparse failed for key: " << key << std::endl;
278 return false;
279 }
280
281 keys.emplace_back(key);
282
283 sparse_data.emplace_back(sparse_count, std::move(sparse_indices),
284 std::move(sparse_feature));
285
286 if (res.size() >= 4) {
287 std::vector<uint64_t> taglist;
288 size_t tag_count;
289
290 ret = load_tags_from_string(res[4], second_sep, taglist, &tag_count);

Callers 1

processFunction · 0.80

Calls 6

SplitFunction · 0.85
eraseMethod · 0.80
c_strMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected