From 674c409e9d24b496d925781a3345b626efbf9dd9 Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Thu, 13 Aug 2020 08:26:20 +0800 Subject: [PATCH] Remove rabit dependency on public headers. (#6005) --- include/xgboost/data.h | 10 +--------- include/xgboost/learner.h | 3 +-- tests/cpp/common/test_span.cc | 7 +++++++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/include/xgboost/data.h b/include/xgboost/data.h index 05b75323f..1ee292a89 100644 --- a/include/xgboost/data.h +++ b/include/xgboost/data.h @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -273,14 +272,7 @@ class SparsePage { inline Inst operator[](size_t i) const { const auto& data_vec = data.HostVector(); const auto& offset_vec = offset.HostVector(); - size_t size; - // in distributed mode, some partitions may not get any instance for a feature. Therefore - // we should set the size as zero - if (rabit::IsDistributed() && i + 1 >= offset_vec.size()) { - size = 0; - } else { - size = offset_vec[i + 1] - offset_vec[i]; - } + size_t size = offset_vec[i + 1] - offset_vec[i]; return {data_vec.data() + offset_vec[i], static_cast(size)}; } diff --git a/include/xgboost/learner.h b/include/xgboost/learner.h index bfe9fd4d5..1b4d12d59 100644 --- a/include/xgboost/learner.h +++ b/include/xgboost/learner.h @@ -9,7 +9,6 @@ #define XGBOOST_LEARNER_H_ #include -#include #include #include #include @@ -63,7 +62,7 @@ struct XGBAPIThreadLocalEntry { * * \endcode */ -class Learner : public Model, public Configurable, public rabit::Serializable { +class Learner : public Model, public Configurable, public dmlc::Serializable { public: /*! \brief virtual destructor */ ~Learner() override; diff --git a/tests/cpp/common/test_span.cc b/tests/cpp/common/test_span.cc index 53fd32e1a..b743b2d6e 100644 --- a/tests/cpp/common/test_span.cc +++ b/tests/cpp/common/test_span.cc @@ -519,5 +519,12 @@ TEST(Span, Empty) { } } +TEST(SpanDeathTest, Empty) { + std::vector data(1, 0); + ASSERT_TRUE(data.data()); + Span s{data.data(), Span::index_type(0)}; // ok to define 0 size span. + EXPECT_DEATH(s[0], "\\[xgboost\\] Condition .* failed.\n"); // not ok to use it. +} + } // namespace common } // namespace xgboost