| 58 | } |
| 59 | |
| 60 | bool SlotReader::readOneFile(const DataConfig& data, int ith_file) { |
| 61 | if (FLAGS_verbose) { |
| 62 | Lock l(mu_); |
| 63 | LI << "loading data file [" << data.file(0) << "]; loaded [" << |
| 64 | loaded_file_count_ << "/" << data_.file_size() << "]"; |
| 65 | } |
| 66 | // check if hit cache |
| 67 | string info_name = cache_ + getFilename(data.file(0)) + ".info"; |
| 68 | ExampleInfo info; |
| 69 | if (readFileToProto(info_name, &info)) { |
| 70 | // the data is already in cache_dir |
| 71 | Lock l(mu_); |
| 72 | info_ = mergeExampleInfo(info_, info); |
| 73 | num_ex_[ith_file] = info.num_ex(); |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | InfoParser info_parser; |
| 78 | struct VSlot { |
| 79 | SArray<float> val; |
| 80 | SArray<uint64> col_idx; |
| 81 | SArray<uint16> row_siz; |
| 82 | bool writeToFile(const string& name) { |
| 83 | return val.compressTo().writeToFile(name+".value") |
| 84 | && col_idx.compressTo().writeToFile(name+".colidx") |
| 85 | && row_siz.compressTo().writeToFile(name+".rowsiz"); |
| 86 | } |
| 87 | }; |
| 88 | VSlot vslots[kSlotIDmax]; |
| 89 | uint32 num_ex = 0; |
| 90 | Example ex; |
| 91 | |
| 92 | // store ex in slots and also extract the info |
| 93 | auto store = [&]() { |
| 94 | if (!info_parser.add(ex)) return; |
| 95 | for (int i = 0; i < ex.slot_size(); ++i) { |
| 96 | const auto& slot = ex.slot(i); |
| 97 | CHECK_LT(slot.id(), kSlotIDmax); |
| 98 | auto& vslot = vslots[slot.id()]; |
| 99 | int key_size = slot.key_size(); |
| 100 | for (int j = 0; j < key_size; ++j) vslot.col_idx.pushBack(slot.key(j)); |
| 101 | int val_size = slot.val_size(); |
| 102 | for (int j = 0; j < val_size; ++j) vslot.val.pushBack(slot.val(j)); |
| 103 | while (vslot.row_siz.size() < num_ex) vslot.row_siz.pushBack(0); |
| 104 | vslot.row_siz.pushBack(std::max(key_size, val_size)); |
| 105 | } |
| 106 | ++ num_ex; |
| 107 | }; |
| 108 | |
| 109 | // read examples one by one |
| 110 | if (data_.format() == DataConfig::TEXT) { |
| 111 | ExampleParser text_parser; |
| 112 | text_parser.init(data.text(), data.ignore_feature_group()); |
| 113 | std::function<void(char*)> handle = [&] (char *line) { |
| 114 | if (!text_parser.toProto(line, &ex)) return; |
| 115 | store(); |
| 116 | }; |
| 117 | FileLineReader reader(data); |
nothing calls this directly
no test coverage detected