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

Method load_from_string_sparse

tools/core/txt_input_reader.h:429–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

427 }
428
429 bool load_from_string_sparse(uint64_t key, const std::string &record,
430 const std::string &second_sep,
431 std::vector<uint32_t> &sparse_indices,
432 std::vector<T> &sparse_feature,
433 uint32_t *sparse_count) {
434 const std::string sparse_sep = ":";
435 std::vector<std::string> res;
436 ailego::StringHelper::Split(record, sparse_sep, &res);
437
438 if (res.size() == 2) {
439 ailego::StringHelper::Split(res[0], second_sep, &sparse_indices);
440 ailego::StringHelper::Split(res[1], second_sep, &sparse_feature);
441
442 uint32_t index_count = sparse_indices.size();
443 uint32_t feature_count = sparse_feature.size();
444
445 if (feature_count == index_count) {
446 *sparse_count = feature_count;
447 } else {
448 std::cerr << "sparse feature count (" << feature_count
449 << ") is not equal with sparse index count(" << index_count
450 << ") key : " << key << std::endl;
451 *sparse_count = 0;
452
453 return false;
454 }
455
456 // check order
457 for (size_t i = 1; i < sparse_indices.size(); ++i) {
458 if (sparse_indices[i - 1] >= sparse_indices[i]) {
459 std::cerr << "sparse indices not ordered, key : " << key
460 << ", dim info: [" << sparse_indices[i - 1] << ", "
461 << sparse_indices[i] << "]" << std::endl;
462
463 return false;
464 }
465 }
466 }
467
468 return true;
469 }
470
471 // LINE FORMAT is as follows:
472 // key:key0 key1 key2 ... keyN:score0 score1 score2 ... scoreN

Callers

nothing calls this directly

Calls 2

SplitFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected