| 708 | ArrayIterForTest::~ArrayIterForTest() { XGDMatrixFree(proxy_); } |
| 709 | |
| 710 | void 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 | |