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

Function LGBM_DatasetCreateFromCSR

src/c_api.cpp:698–767  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

696}
697
698int 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)

Callers

nothing calls this directly

Calls 12

resetMethod · 0.80
dataMethod · 0.80
RowFunctionFromCSRFunction · 0.70
omp_set_num_threadsFunction · 0.50
omp_get_thread_numFunction · 0.50
SetMethod · 0.45
SampleMethod · 0.45
sizeMethod · 0.45
CreateValidMethod · 0.45
PushOneRowMethod · 0.45
FinishLoadMethod · 0.45

Tested by

no test coverage detected