MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / LoadFromBinFile

Method LoadFromBinFile

src/io/dataset_loader.cpp:274–571  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272}
273
274Dataset* DatasetLoader::LoadFromBinFile(const char* data_filename, const char* bin_filename,
275 int rank, int num_machines, int* num_global_data,
276 std::vector<data_size_t>* used_data_indices) {
277 auto dataset = std::unique_ptr<Dataset>(new Dataset());
278 auto reader = VirtualFileReader::Make(bin_filename);
279 dataset->data_filename_ = data_filename;
280 if (!reader->Init()) {
281 Log::Fatal("Could not read binary data from %s", bin_filename);
282 }
283
284 // buffer to read binary file
285 size_t buffer_size = 16 * 1024 * 1024;
286 auto buffer = std::vector<char>(buffer_size);
287
288 // check token
289 size_t size_of_token = std::strlen(Dataset::binary_file_token);
290 size_t read_cnt = reader->Read(buffer.data(), sizeof(char) * size_of_token);
291 if (read_cnt != sizeof(char) * size_of_token) {
292 Log::Fatal("Binary file error: token has the wrong size");
293 }
294 if (std::string(buffer.data()) != std::string(Dataset::binary_file_token)) {
295 Log::Fatal("Input file is not LightGBM binary file");
296 }
297
298 // read size of header
299 read_cnt = reader->Read(buffer.data(), sizeof(size_t));
300
301 if (read_cnt != sizeof(size_t)) {
302 Log::Fatal("Binary file error: header has the wrong size");
303 }
304
305 size_t size_of_head = *(reinterpret_cast<size_t*>(buffer.data()));
306
307 // re-allocmate space if not enough
308 if (size_of_head > buffer_size) {
309 buffer_size = size_of_head;
310 buffer.resize(buffer_size);
311 }
312 // read header
313 read_cnt = reader->Read(buffer.data(), size_of_head);
314
315 if (read_cnt != size_of_head) {
316 Log::Fatal("Binary file error: header is incorrect");
317 }
318 // get header
319 const char* mem_ptr = buffer.data();
320 dataset->num_data_ = *(reinterpret_cast<const data_size_t*>(mem_ptr));
321 mem_ptr += sizeof(dataset->num_data_);
322 dataset->num_features_ = *(reinterpret_cast<const int*>(mem_ptr));
323 mem_ptr += sizeof(dataset->num_features_);
324 dataset->num_total_features_ = *(reinterpret_cast<const int*>(mem_ptr));
325 mem_ptr += sizeof(dataset->num_total_features_);
326 dataset->label_idx_ = *(reinterpret_cast<const int*>(mem_ptr));
327 mem_ptr += sizeof(dataset->label_idx_);
328 dataset->max_bin_ = *(reinterpret_cast<const int*>(mem_ptr));
329 mem_ptr += sizeof(dataset->max_bin_);
330 dataset->bin_construct_sample_cnt_ = *(reinterpret_cast<const int*>(mem_ptr));
331 mem_ptr += sizeof(dataset->bin_construct_sample_cnt_);

Callers

nothing calls this directly

Calls 15

min_elementFunction · 0.85
dataMethod · 0.80
push_backMethod · 0.80
assignMethod · 0.80
InitMethod · 0.45
ReadMethod · 0.45
resizeMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
InnerFeatureIndexMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected