| 696 | } |
| 697 | |
| 698 | int LGBM_DatasetCreateFromCSR(const void* indptr, |
| 699 | int indptr_type, |
| 700 | const int32_t* indices, |
| 701 | const void* data, |
| 702 | int data_type, |
| 703 | int64_t nindptr, |
| 704 | int64_t nelem, |
| 705 | int64_t num_col, |
| 706 | const char* parameters, |
| 707 | const DatasetHandle reference, |
| 708 | DatasetHandle* out) { |
| 709 | API_BEGIN(); |
| 710 | if (num_col <= 0) { |
| 711 | Log::Fatal("The number of columns should be greater than zero."); |
| 712 | } else if (num_col >= INT32_MAX) { |
| 713 | Log::Fatal("The number of columns should be smaller than INT32_MAX."); |
| 714 | } |
| 715 | auto param = Config::Str2Map(parameters); |
| 716 | Config config; |
| 717 | config.Set(param); |
| 718 | if (config.num_threads > 0) { |
| 719 | omp_set_num_threads(config.num_threads); |
| 720 | } |
| 721 | std::unique_ptr<Dataset> ret; |
| 722 | auto get_row_fun = RowFunctionFromCSR(indptr, indptr_type, indices, data, data_type, nindptr, nelem); |
| 723 | int32_t nrow = static_cast<int32_t>(nindptr - 1); |
| 724 | if (reference == nullptr) { |
| 725 | // sample data first |
| 726 | Random rand(config.data_random_seed); |
| 727 | int sample_cnt = static_cast<int>(nrow < config.bin_construct_sample_cnt ? nrow : config.bin_construct_sample_cnt); |
| 728 | auto sample_indices = rand.Sample(nrow, sample_cnt); |
| 729 | sample_cnt = static_cast<int>(sample_indices.size()); |
| 730 | std::vector<std::vector<double>> sample_values(num_col); |
| 731 | std::vector<std::vector<int>> sample_idx(num_col); |
| 732 | for (size_t i = 0; i < sample_indices.size(); ++i) { |
| 733 | auto idx = sample_indices[i]; |
| 734 | auto row = get_row_fun(static_cast<int>(idx)); |
| 735 | for (std::pair<int, double>& inner_data : row) { |
| 736 | CHECK(inner_data.first < num_col); |
| 737 | if (std::fabs(inner_data.second) > kZeroThreshold || std::isnan(inner_data.second)) { |
| 738 | sample_values[inner_data.first].emplace_back(inner_data.second); |
| 739 | sample_idx[inner_data.first].emplace_back(static_cast<int>(i)); |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | DatasetLoader loader(config, nullptr, 1, nullptr); |
| 744 | ret.reset(loader.CostructFromSampleData(Common::Vector2Ptr<double>(&sample_values).data(), |
| 745 | Common::Vector2Ptr<int>(&sample_idx).data(), |
| 746 | static_cast<int>(num_col), |
| 747 | Common::VectorSize<double>(sample_values).data(), |
| 748 | sample_cnt, nrow)); |
| 749 | } else { |
| 750 | ret.reset(new Dataset(nrow)); |
| 751 | ret->CreateValid( |
| 752 | reinterpret_cast<const Dataset*>(reference)); |
| 753 | } |
| 754 | OMP_INIT_EX(); |
| 755 | #pragma omp parallel for schedule(static) |
nothing calls this directly
no test coverage detected