| 612 | |
| 613 | |
| 614 | int LGBM_DatasetCreateFromMats(int32_t nmat, |
| 615 | const void** data, |
| 616 | int data_type, |
| 617 | int32_t* nrow, |
| 618 | int32_t ncol, |
| 619 | int is_row_major, |
| 620 | const char* parameters, |
| 621 | const DatasetHandle reference, |
| 622 | DatasetHandle* out) { |
| 623 | API_BEGIN(); |
| 624 | auto param = Config::Str2Map(parameters); |
| 625 | Config config; |
| 626 | config.Set(param); |
| 627 | if (config.num_threads > 0) { |
| 628 | omp_set_num_threads(config.num_threads); |
| 629 | } |
| 630 | std::unique_ptr<Dataset> ret; |
| 631 | int32_t total_nrow = 0; |
| 632 | for (int j = 0; j < nmat; ++j) { |
| 633 | total_nrow += nrow[j]; |
| 634 | } |
| 635 | |
| 636 | std::vector<std::function<std::vector<double>(int row_idx)>> get_row_fun; |
| 637 | for (int j = 0; j < nmat; ++j) { |
| 638 | get_row_fun.push_back(RowFunctionFromDenseMatric(data[j], nrow[j], ncol, data_type, is_row_major)); |
| 639 | } |
| 640 | |
| 641 | if (reference == nullptr) { |
| 642 | // sample data first |
| 643 | Random rand(config.data_random_seed); |
| 644 | int sample_cnt = static_cast<int>(total_nrow < config.bin_construct_sample_cnt ? total_nrow : config.bin_construct_sample_cnt); |
| 645 | auto sample_indices = rand.Sample(total_nrow, sample_cnt); |
| 646 | sample_cnt = static_cast<int>(sample_indices.size()); |
| 647 | std::vector<std::vector<double>> sample_values(ncol); |
| 648 | std::vector<std::vector<int>> sample_idx(ncol); |
| 649 | |
| 650 | int offset = 0; |
| 651 | int j = 0; |
| 652 | for (size_t i = 0; i < sample_indices.size(); ++i) { |
| 653 | auto idx = sample_indices[i]; |
| 654 | while ((idx - offset) >= nrow[j]) { |
| 655 | offset += nrow[j]; |
| 656 | ++j; |
| 657 | } |
| 658 | |
| 659 | auto row = get_row_fun[j](static_cast<int>(idx - offset)); |
| 660 | for (size_t k = 0; k < row.size(); ++k) { |
| 661 | if (std::fabs(row[k]) > kZeroThreshold || std::isnan(row[k])) { |
| 662 | sample_values[k].emplace_back(row[k]); |
| 663 | sample_idx[k].emplace_back(static_cast<int>(i)); |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | DatasetLoader loader(config, nullptr, 1, nullptr); |
| 668 | ret.reset(loader.CostructFromSampleData(Common::Vector2Ptr<double>(&sample_values).data(), |
| 669 | Common::Vector2Ptr<int>(&sample_idx).data(), |
| 670 | ncol, |
| 671 | Common::VectorSize<double>(sample_values).data(), |
no test coverage detected