Allow empty page in external memory. (#9361)

This commit is contained in:
Jiaming Yuan 2023-07-08 09:24:35 +08:00 committed by GitHub
parent 15ca12a77e
commit 59787b23af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,7 +68,6 @@ class GHistIndexRawFormat : public SparsePageFormat<GHistIndexMatrix> {
} }
std::size_t Write(GHistIndexMatrix const& page, common::AlignedFileWriteStream* fo) override { std::size_t Write(GHistIndexMatrix const& page, common::AlignedFileWriteStream* fo) override {
CHECK_NE(page.index.Size(), 0) << "Empty page is not supported.";
std::size_t bytes = 0; std::size_t bytes = 0;
bytes += WriteHistogramCuts(page.cut, fo); bytes += WriteHistogramCuts(page.cut, fo);
// indptr // indptr
@ -81,7 +80,9 @@ class GHistIndexRawFormat : public SparsePageFormat<GHistIndexMatrix> {
// - index buffer // - index buffer
std::vector<std::uint8_t> data(page.index.begin(), page.index.end()); std::vector<std::uint8_t> data(page.index.begin(), page.index.end());
bytes += fo->Write(static_cast<std::uint64_t>(data.size())); bytes += fo->Write(static_cast<std::uint64_t>(data.size()));
bytes += fo->Write(data.data(), data.size()); if (!data.empty()) {
bytes += fo->Write(data.data(), data.size());
}
// hit count // hit count
bytes += common::WriteVec(fo, page.hit_count); bytes += common::WriteVec(fo, page.hit_count);