MCPcopy Create free account
hub / github.com/dmlc/xgboost / DMatrixToCSR

Function DMatrixToCSR

tests/cpp/helpers.cc:710–735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

708ArrayIterForTest::~ArrayIterForTest() { XGDMatrixFree(proxy_); }
709
710void DMatrixToCSR(DMatrix* dmat, std::vector<float>* p_data, std::vector<size_t>* p_row_ptr,
711 std::vector<bst_feature_t>* p_cids) {
712 auto& data = *p_data;
713 auto& row_ptr = *p_row_ptr;
714 auto& cids = *p_cids;
715
716 data.resize(dmat->Info().num_nonzero_);
717 cids.resize(data.size());
718 row_ptr.resize(dmat->Info().num_row_ + 1);
719 SparsePage page;
720 for (const auto& batch : dmat->GetBatches<SparsePage>()) {
721 page.Push(batch);
722 }
723
724 auto const& in_offset = page.offset.HostVector();
725 auto const& in_data = page.data.HostVector();
726
727 CHECK_EQ(in_offset.size(), row_ptr.size());
728 std::copy(in_offset.cbegin(), in_offset.cend(), row_ptr.begin());
729 ASSERT_EQ(in_data.size(), data.size());
730 std::transform(in_data.cbegin(), in_data.cend(), data.begin(),
731 [](Entry const& e) { return e.fvalue; });
732 ASSERT_EQ(in_data.size(), cids.size());
733 std::transform(in_data.cbegin(), in_data.cend(), cids.begin(),
734 [](Entry const& e) { return e.index; });
735}
736
737#if defined(XGBOOST_USE_RMM) && XGBOOST_USE_RMM == 1
738

Callers 1

Calls 7

resizeMethod · 0.80
InfoMethod · 0.45
sizeMethod · 0.45
PushMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45
beginMethod · 0.45

Tested by 1