| 839 | } |
| 840 | |
| 841 | int LGBM_DatasetCreateFromCSC(const void* col_ptr, |
| 842 | int col_ptr_type, |
| 843 | const int32_t* indices, |
| 844 | const void* data, |
| 845 | int data_type, |
| 846 | int64_t ncol_ptr, |
| 847 | int64_t nelem, |
| 848 | int64_t num_row, |
| 849 | const char* parameters, |
| 850 | const DatasetHandle reference, |
| 851 | DatasetHandle* out) { |
| 852 | API_BEGIN(); |
| 853 | auto param = Config::Str2Map(parameters); |
| 854 | Config config; |
| 855 | config.Set(param); |
| 856 | if (config.num_threads > 0) { |
| 857 | omp_set_num_threads(config.num_threads); |
| 858 | } |
| 859 | std::unique_ptr<Dataset> ret; |
| 860 | int32_t nrow = static_cast<int32_t>(num_row); |
| 861 | if (reference == nullptr) { |
| 862 | // sample data first |
| 863 | Random rand(config.data_random_seed); |
| 864 | int sample_cnt = static_cast<int>(nrow < config.bin_construct_sample_cnt ? nrow : config.bin_construct_sample_cnt); |
| 865 | auto sample_indices = rand.Sample(nrow, sample_cnt); |
| 866 | sample_cnt = static_cast<int>(sample_indices.size()); |
| 867 | std::vector<std::vector<double>> sample_values(ncol_ptr - 1); |
| 868 | std::vector<std::vector<int>> sample_idx(ncol_ptr - 1); |
| 869 | OMP_INIT_EX(); |
| 870 | #pragma omp parallel for schedule(static) |
| 871 | for (int i = 0; i < static_cast<int>(sample_values.size()); ++i) { |
| 872 | OMP_LOOP_EX_BEGIN(); |
| 873 | CSC_RowIterator col_it(col_ptr, col_ptr_type, indices, data, data_type, ncol_ptr, nelem, i); |
| 874 | for (int j = 0; j < sample_cnt; j++) { |
| 875 | auto val = col_it.Get(sample_indices[j]); |
| 876 | if (std::fabs(val) > kZeroThreshold || std::isnan(val)) { |
| 877 | sample_values[i].emplace_back(val); |
| 878 | sample_idx[i].emplace_back(j); |
| 879 | } |
| 880 | } |
| 881 | OMP_LOOP_EX_END(); |
| 882 | } |
| 883 | OMP_THROW_EX(); |
| 884 | DatasetLoader loader(config, nullptr, 1, nullptr); |
| 885 | ret.reset(loader.CostructFromSampleData(Common::Vector2Ptr<double>(&sample_values).data(), |
| 886 | Common::Vector2Ptr<int>(&sample_idx).data(), |
| 887 | static_cast<int>(sample_values.size()), |
| 888 | Common::VectorSize<double>(sample_values).data(), |
| 889 | sample_cnt, nrow)); |
| 890 | } else { |
| 891 | ret.reset(new Dataset(nrow)); |
| 892 | ret->CreateValid( |
| 893 | reinterpret_cast<const Dataset*>(reference)); |
| 894 | } |
| 895 | OMP_INIT_EX(); |
| 896 | #pragma omp parallel for schedule(static) |
| 897 | for (int i = 0; i < ncol_ptr - 1; ++i) { |
| 898 | OMP_LOOP_EX_BEGIN(); |
no test coverage detected