xgboost
data.h
Go to the documentation of this file.
1 
7 #ifndef XGBOOST_DATA_H_
8 #define XGBOOST_DATA_H_
9 
10 #include <dmlc/base.h>
11 #include <dmlc/data.h>
12 #include <dmlc/serializer.h>
13 #include <xgboost/base.h>
14 #include <xgboost/span.h>
16 
17 #include <memory>
18 #include <numeric>
19 #include <algorithm>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 namespace xgboost {
25 // forward declare dmatrix.
26 class DMatrix;
27 
29 enum class DataType : uint8_t {
30  kFloat32 = 1,
31  kDouble = 2,
32  kUInt32 = 3,
33  kUInt64 = 4,
34  kStr = 5
35 };
36 
37 enum class FeatureType : uint8_t {
38  kNumerical,
40 };
41 
45 class MetaInfo {
46  public:
48  static constexpr uint64_t kNumField = 11;
49 
51  uint64_t num_row_{0}; // NOLINT
53  uint64_t num_col_{0}; // NOLINT
55  uint64_t num_nonzero_{0}; // NOLINT
62  std::vector<bst_group_t> group_ptr_; // NOLINT
79 
83  std::vector<std::string> feature_type_names;
87  std::vector<std::string> feature_names;
88  /*
89  * \brief Type of each feature. Automatically set when feature_type_names is specifed.
90  */
92  /*
93  * \brief Weight of each feature, used to define the probability of each feature being
94  * selected when using column sampling.
95  */
97 
99  MetaInfo() = default;
100  MetaInfo(MetaInfo&& that) = default;
101  MetaInfo& operator=(MetaInfo&& that) = default;
102  MetaInfo& operator=(MetaInfo const& that) = delete;
103 
107  void Validate(int32_t device) const;
108 
115  inline bst_float GetWeight(size_t i) const {
116  return weights_.Size() != 0 ? weights_.HostVector()[i] : 1.0f;
117  }
119  inline const std::vector<size_t>& LabelAbsSort() const {
120  if (label_order_cache_.size() == labels_.Size()) {
121  return label_order_cache_;
122  }
123  label_order_cache_.resize(labels_.Size());
124  std::iota(label_order_cache_.begin(), label_order_cache_.end(), 0);
125  const auto& l = labels_.HostVector();
126  XGBOOST_PARALLEL_SORT(label_order_cache_.begin(), label_order_cache_.end(),
127  [&l](size_t i1, size_t i2) {return std::abs(l[i1]) < std::abs(l[i2]);});
128 
129  return label_order_cache_;
130  }
132  void Clear();
137  void LoadBinary(dmlc::Stream* fi);
142  void SaveBinary(dmlc::Stream* fo) const;
150  void SetInfo(const char* key, const void* dptr, DataType dtype, size_t num);
160  void SetInfo(const char* key, std::string const& interface_str);
161 
162  void GetInfo(char const* key, bst_ulong* out_len, DataType dtype,
163  const void** out_dptr) const;
164 
165  void SetFeatureInfo(const char *key, const char **info, const bst_ulong size);
166  void GetFeatureInfo(const char *field, std::vector<std::string>* out_str_vecs) const;
167 
168  /*
169  * \brief Extend with other MetaInfo.
170  *
171  * \param that The other MetaInfo object.
172  *
173  * \param accumulate_rows Whether rows need to be accumulated in this function. If
174  * client code knows number of rows in advance, set this
175  * parameter to false.
176  * \param check_column Whether the extend method should check the consistency of
177  * columns.
178  */
179  void Extend(MetaInfo const& that, bool accumulate_rows, bool check_column);
180 
181  private:
183  mutable std::vector<size_t> label_order_cache_;
184 };
185 
187 struct Entry {
193  Entry() = default;
201  inline static bool CmpValue(const Entry& a, const Entry& b) {
202  return a.fvalue < b.fvalue;
203  }
204  inline bool operator==(const Entry& other) const {
205  return (this->index == other.index && this->fvalue == other.fvalue);
206  }
207 };
208 
212 struct BatchParam {
214  int gpu_id {-1};
216  int max_bin{0};
220  bool regen {false};
221 
222  BatchParam() = default;
223  BatchParam(int32_t device, int32_t max_bin)
224  : gpu_id{device}, max_bin{max_bin} {}
229  BatchParam(int32_t device, int32_t max_bin, common::Span<float> hessian,
230  bool regenerate = false)
231  : gpu_id{device}, max_bin{max_bin}, hess{hessian}, regen{regenerate} {}
232 
233  bool operator!=(const BatchParam& other) const {
234  if (hess.empty() && other.hess.empty()) {
235  return gpu_id != other.gpu_id || max_bin != other.max_bin;
236  }
237  return gpu_id != other.gpu_id || max_bin != other.max_bin || hess.data() != other.hess.data();
238  }
239 };
240 
243 
246 
247  Inst operator[](size_t i) const {
248  auto size = *(offset.data() + i + 1) - *(offset.data() + i);
249  return {data.data() + *(offset.data() + i),
250  static_cast<Inst::index_type>(size)};
251  }
252 
253  size_t Size() const { return offset.size() == 0 ? 0 : offset.size() - 1; }
254 };
255 
259 class SparsePage {
260  public:
261  // Offset for each row.
265 
266  size_t base_rowid {0};
267 
270 
272  return {offset.ConstHostSpan(), data.ConstHostSpan()};
273  }
274 
275 
278  this->Clear();
279  }
280 
282  inline size_t Size() const {
283  return offset.Size() == 0 ? 0 : offset.Size() - 1;
284  }
285 
287  inline size_t MemCostBytes() const {
288  return offset.Size() * sizeof(size_t) + data.Size() * sizeof(Entry);
289  }
290 
292  inline void Clear() {
293  base_rowid = 0;
294  auto& offset_vec = offset.HostVector();
295  offset_vec.clear();
296  offset_vec.push_back(0);
297  data.HostVector().clear();
298  }
299 
301  inline void SetBaseRowId(size_t row_id) {
302  base_rowid = row_id;
303  }
304 
305  SparsePage GetTranspose(int num_columns) const;
306 
307  void SortRows() {
308  auto ncol = static_cast<bst_omp_uint>(this->Size());
309  dmlc::OMPException exc;
310 #pragma omp parallel for schedule(dynamic, 1)
311  for (bst_omp_uint i = 0; i < ncol; ++i) {
312  exc.Run([&]() {
313  if (this->offset.HostVector()[i] < this->offset.HostVector()[i + 1]) {
314  std::sort(
315  this->data.HostVector().begin() + this->offset.HostVector()[i],
316  this->data.HostVector().begin() + this->offset.HostVector()[i + 1],
318  }
319  });
320  }
321  exc.Rethrow();
322  }
323 
334  template <typename AdapterBatchT>
335  uint64_t Push(const AdapterBatchT& batch, float missing, int nthread);
336 
341  void Push(const SparsePage &batch);
346  void PushCSC(const SparsePage& batch);
347 };
348 
349 class CSCPage: public SparsePage {
350  public:
352  explicit CSCPage(SparsePage page) : SparsePage(std::move(page)) {}
353 };
354 
355 class SortedCSCPage : public SparsePage {
356  public:
358  explicit SortedCSCPage(SparsePage page) : SparsePage(std::move(page)) {}
359 };
360 
361 class EllpackPageImpl;
368 class EllpackPage {
369  public:
376  EllpackPage();
377 
384  explicit EllpackPage(DMatrix* dmat, const BatchParam& param);
385 
387  ~EllpackPage();
388 
389  EllpackPage(EllpackPage&& that);
390 
392  size_t Size() const;
393 
395  void SetBaseRowId(size_t row_id);
396 
397  const EllpackPageImpl* Impl() const { return impl_.get(); }
398  EllpackPageImpl* Impl() { return impl_.get(); }
399 
400  private:
401  std::unique_ptr<EllpackPageImpl> impl_;
402 };
403 
404 class GHistIndexMatrix;
405 
406 template<typename T>
408  public:
409  using iterator_category = std::forward_iterator_tag; // NOLINT
410  virtual ~BatchIteratorImpl() = default;
411  virtual const T& operator*() const = 0;
412  virtual BatchIteratorImpl& operator++() = 0;
413  virtual bool AtEnd() const = 0;
414  virtual std::shared_ptr<T const> Page() const = 0;
415 };
416 
417 template<typename T>
419  public:
420  using iterator_category = std::forward_iterator_tag; // NOLINT
421  explicit BatchIterator(BatchIteratorImpl<T>* impl) { impl_.reset(impl); }
422  explicit BatchIterator(std::shared_ptr<BatchIteratorImpl<T>> impl) { impl_ = impl; }
423 
425  CHECK(impl_ != nullptr);
426  ++(*impl_);
427  return *this;
428  }
429 
430  const T& operator*() const {
431  CHECK(impl_ != nullptr);
432  return *(*impl_);
433  }
434 
435  bool operator!=(const BatchIterator&) const {
436  CHECK(impl_ != nullptr);
437  return !impl_->AtEnd();
438  }
439 
440  bool AtEnd() const {
441  CHECK(impl_ != nullptr);
442  return impl_->AtEnd();
443  }
444 
445  std::shared_ptr<T const> Page() const {
446  return impl_->Page();
447  }
448 
449  private:
450  std::shared_ptr<BatchIteratorImpl<T>> impl_;
451 };
452 
453 template<typename T>
454 class BatchSet {
455  public:
456  explicit BatchSet(BatchIterator<T> begin_iter) : begin_iter_(std::move(begin_iter)) {}
457  BatchIterator<T> begin() { return begin_iter_; } // NOLINT
458  BatchIterator<T> end() { return BatchIterator<T>(nullptr); } // NOLINT
459 
460  private:
461  BatchIterator<T> begin_iter_;
462 };
463 
464 struct XGBAPIThreadLocalEntry;
465 
469 class DMatrix {
470  public:
472  DMatrix() = default;
474  virtual MetaInfo& Info() = 0;
475  virtual void SetInfo(const char *key, const void *dptr, DataType dtype,
476  size_t num) {
477  this->Info().SetInfo(key, dptr, dtype, num);
478  }
479  virtual void SetInfo(const char* key, std::string const& interface_str) {
480  this->Info().SetInfo(key, interface_str);
481  }
483  virtual const MetaInfo& Info() const = 0;
484 
487 
491  template<typename T>
492  BatchSet<T> GetBatches(const BatchParam& param = {});
493  template <typename T>
494  bool PageExists() const;
495 
496  // the following are column meta data, should be able to answer them fast.
498  virtual bool SingleColBlock() const = 0;
500  virtual ~DMatrix();
501 
503  bool IsDense() const {
504  return Info().num_nonzero_ == Info().num_row_ * Info().num_col_;
505  }
506 
517  static DMatrix* Load(const std::string& uri,
518  bool silent,
519  bool load_row_split,
520  const std::string& file_format = "auto");
521 
534  template <typename AdapterT>
535  static DMatrix* Create(AdapterT* adapter, float missing, int nthread,
536  const std::string& cache_prefix = "");
537 
556  template <typename DataIterHandle, typename DMatrixHandle,
557  typename DataIterResetCallback, typename XGDMatrixCallbackNext>
558  static DMatrix *Create(DataIterHandle iter, DMatrixHandle proxy,
559  DataIterResetCallback *reset,
560  XGDMatrixCallbackNext *next, float missing,
561  int nthread,
562  int max_bin);
563 
582  template <typename DataIterHandle, typename DMatrixHandle,
583  typename DataIterResetCallback, typename XGDMatrixCallbackNext>
584  static DMatrix *Create(DataIterHandle iter, DMatrixHandle proxy,
585  DataIterResetCallback *reset,
586  XGDMatrixCallbackNext *next, float missing,
587  int32_t nthread, std::string cache);
588 
589  virtual DMatrix *Slice(common::Span<int32_t const> ridxs) = 0;
592  static const size_t kPageSize = 32UL << 12UL;
593 
594  protected:
595  virtual BatchSet<SparsePage> GetRowBatches() = 0;
596  virtual BatchSet<CSCPage> GetColumnBatches() = 0;
598  virtual BatchSet<EllpackPage> GetEllpackBatches(const BatchParam& param) = 0;
599  virtual BatchSet<GHistIndexMatrix> GetGradientIndex(const BatchParam& param) = 0;
600 
601  virtual bool EllpackExists() const = 0;
602  virtual bool SparsePageExists() const = 0;
603 };
604 
605 template<>
607  return GetRowBatches();
608 }
609 
610 template<>
611 inline bool DMatrix::PageExists<EllpackPage>() const {
612  return this->EllpackExists();
613 }
614 
615 template<>
616 inline bool DMatrix::PageExists<SparsePage>() const {
617  return this->SparsePageExists();
618 }
619 
620 template<>
622  return GetColumnBatches();
623 }
624 
625 template<>
626 inline BatchSet<SortedCSCPage> DMatrix::GetBatches(const BatchParam&) {
627  return GetSortedColumnBatches();
628 }
629 
630 template<>
631 inline BatchSet<EllpackPage> DMatrix::GetBatches(const BatchParam& param) {
632  return GetEllpackBatches(param);
633 }
634 
635 template<>
636 inline BatchSet<GHistIndexMatrix> DMatrix::GetBatches(const BatchParam& param) {
637  return GetGradientIndex(param);
638 }
639 } // namespace xgboost
640 
641 namespace dmlc {
642 DMLC_DECLARE_TRAITS(is_pod, xgboost::Entry, true);
643 
644 namespace serializer {
645 
646 template <>
647 struct Handler<xgboost::Entry> {
648  inline static void Write(Stream* strm, const xgboost::Entry& data) {
649  strm->Write(data.index);
650  strm->Write(data.fvalue);
651  }
652 
653  inline static bool Read(Stream* strm, xgboost::Entry* data) {
654  return strm->Read(&data->index) && strm->Read(&data->fvalue);
655  }
656 };
657 
658 } // namespace serializer
659 } // namespace dmlc
660 #endif // XGBOOST_DATA_H_
xgboost::MetaInfo::GetFeatureInfo
void GetFeatureInfo(const char *field, std::vector< std::string > *out_str_vecs) const
xgboost::Entry::index
bst_feature_t index
feature index
Definition: data.h:189
xgboost::BatchIteratorImpl::Page
virtual std::shared_ptr< T const > Page() const =0
xgboost::DMatrix::Info
virtual MetaInfo & Info()=0
meta information of the dataset
xgboost::BatchParam::max_bin
int max_bin
Maximum number of bins per feature for histograms.
Definition: data.h:216
xgboost::MetaInfo::feature_type_names
std::vector< std::string > feature_type_names
Name of type for each feature provided by users. Eg. "int"/"float"/"i"/"q".
Definition: data.h:83
xgboost::DMatrix::GetEllpackBatches
virtual BatchSet< EllpackPage > GetEllpackBatches(const BatchParam &param)=0
xgboost::BatchIteratorImpl::operator++
virtual BatchIteratorImpl & operator++()=0
xgboost::MetaInfo::num_row_
uint64_t num_row_
number of rows in the data
Definition: data.h:51
xgboost::HostSparsePageView::data
common::Span< Entry const > data
Definition: data.h:245
xgboost::BatchIteratorImpl::~BatchIteratorImpl
virtual ~BatchIteratorImpl()=default
xgboost::SparsePage::Size
size_t Size() const
Definition: data.h:282
xgboost::SparsePage::SetBaseRowId
void SetBaseRowId(size_t row_id)
Set the base row id for this page.
Definition: data.h:301
xgboost::DataType::kUInt64
@ kUInt64
xgboost::MetaInfo::Extend
void Extend(MetaInfo const &that, bool accumulate_rows, bool check_column)
xgboost::CSCPage::CSCPage
CSCPage()
Definition: data.h:351
dmlc
Definition: data.h:641
xgboost::MetaInfo::LabelAbsSort
const std::vector< size_t > & LabelAbsSort() const
get sorted indexes (argsort) of labels by absolute value (used by cox loss)
Definition: data.h:119
xgboost::DMatrix::~DMatrix
virtual ~DMatrix()
virtual destructor
xgboost::EllpackPage
A page stored in ELLPACK format.
Definition: data.h:368
xgboost::SparsePage
In-memory storage unit of sparse batch, stored in CSR format.
Definition: data.h:259
xgboost::SparsePage::Push
uint64_t Push(const AdapterBatchT &batch, float missing, int nthread)
Pushes external data batch onto this page.
xgboost::CSCPage::CSCPage
CSCPage(SparsePage page)
Definition: data.h:352
xgboost::common::Span::index_type
std::size_t index_type
Definition: span.h:421
xgboost::SparsePage::SortRows
void SortRows()
Definition: data.h:307
xgboost::Entry
Element from a sparse vector.
Definition: data.h:187
xgboost::MetaInfo::base_margin_
HostDeviceVector< bst_float > base_margin_
initialized margins, if specified, xgboost will start from this init margin can be used to specify in...
Definition: data.h:70
xgboost::EllpackPage::Impl
const EllpackPageImpl * Impl() const
Definition: data.h:397
xgboost::DMatrix::GetRowBatches
virtual BatchSet< SparsePage > GetRowBatches()=0
xgboost::HostDeviceVector< bst_float >
xgboost::BatchSet::BatchSet
BatchSet(BatchIterator< T > begin_iter)
Definition: data.h:456
xgboost::DMatrix::Create
static DMatrix * Create(AdapterT *adapter, float missing, int nthread, const std::string &cache_prefix="")
Creates a new DMatrix from an external data adapter.
host_device_vector.h
A device-and-host vector abstraction layer.
xgboost::DMatrix::SingleColBlock
virtual bool SingleColBlock() const =0
xgboost::SortedCSCPage::SortedCSCPage
SortedCSCPage(SparsePage page)
Definition: data.h:358
xgboost::MetaInfo::Clear
void Clear()
clear all the information
xgboost::BatchIterator::AtEnd
bool AtEnd() const
Definition: data.h:440
xgboost::EllpackPage::Size
size_t Size() const
xgboost::SortedCSCPage::SortedCSCPage
SortedCSCPage()
Definition: data.h:357
xgboost::DMatrix::SetInfo
virtual void SetInfo(const char *key, std::string const &interface_str)
Definition: data.h:479
xgboost::BatchIterator::BatchIterator
BatchIterator(BatchIteratorImpl< T > *impl)
Definition: data.h:421
xgboost::MetaInfo::SetInfo
void SetInfo(const char *key, const void *dptr, DataType dtype, size_t num)
Set information in the meta info.
base.h
defines configuration macros of xgboost.
xgboost::MetaInfo::MetaInfo
MetaInfo()=default
default constructor
xgboost::BatchParam::operator!=
bool operator!=(const BatchParam &other) const
Definition: data.h:233
xgboost::MetaInfo::labels_lower_bound_
HostDeviceVector< bst_float > labels_lower_bound_
lower bound of the label, to be used for survival analysis (censored regression)
Definition: data.h:74
xgboost::HostDeviceVector::ConstHostSpan
common::Span< T const > ConstHostSpan() const
Definition: host_device_vector.h:114
xgboost::MetaInfo::Slice
MetaInfo Slice(common::Span< int32_t const > ridxs) const
xgboost::BatchIterator::Page
std::shared_ptr< T const > Page() const
Definition: data.h:445
xgboost::BatchIteratorImpl
Definition: data.h:407
DataIterHandle
void * DataIterHandle
handle to a external data iterator
Definition: c_api.h:287
xgboost::BatchSet::begin
BatchIterator< T > begin()
Definition: data.h:457
xgboost::BatchParam::BatchParam
BatchParam()=default
xgboost::MetaInfo::num_col_
uint64_t num_col_
number of columns in the data
Definition: data.h:53
xgboost::MetaInfo::SetFeatureInfo
void SetFeatureInfo(const char *key, const char **info, const bst_ulong size)
xgboost::MetaInfo::group_ptr_
std::vector< bst_group_t > group_ptr_
the index of begin and end of a group needed when the learning task is ranking.
Definition: data.h:62
xgboost::BatchIterator::operator*
const T & operator*() const
Definition: data.h:430
xgboost::DMatrix
Internal data structured used by XGBoost during training.
Definition: data.h:469
xgboost::MetaInfo::LoadBinary
void LoadBinary(dmlc::Stream *fi)
Load the Meta info from binary stream.
xgboost::DMatrix::Load
static DMatrix * Load(const std::string &uri, bool silent, bool load_row_split, const std::string &file_format="auto")
Load DMatrix from URI.
XGDMatrixCallbackNext
XGB_EXTERN_C typedef int XGDMatrixCallbackNext(DataIterHandle iter)
Callback function prototype for getting next batch of data.
xgboost::BatchIterator::operator++
BatchIterator & operator++()
Definition: data.h:424
xgboost::BatchParam::BatchParam
BatchParam(int32_t device, int32_t max_bin)
Definition: data.h:223
xgboost::DataType::kDouble
@ kDouble
xgboost::MetaInfo::feature_names
std::vector< std::string > feature_names
Name for each feature.
Definition: data.h:87
xgboost::DataType::kUInt32
@ kUInt32
xgboost::bst_ulong
uint64_t bst_ulong
unsigned long integers
Definition: base.h:117
xgboost::HostSparsePageView::offset
common::Span< bst_row_t const > offset
Definition: data.h:244
xgboost::DMatrix::GetGradientIndex
virtual BatchSet< GHistIndexMatrix > GetGradientIndex(const BatchParam &param)=0
xgboost::bst_feature_t
uint32_t bst_feature_t
Type for data column (feature) index.
Definition: base.h:123
xgboost::DMatrix::GetSortedColumnBatches
virtual BatchSet< SortedCSCPage > GetSortedColumnBatches()=0
xgboost::HostSparsePageView::operator[]
Inst operator[](size_t i) const
Definition: data.h:247
xgboost::bst_omp_uint
dmlc::omp_uint bst_omp_uint
define unsigned int for openmp loop
Definition: base.h:273
xgboost::common::Span::empty
constexpr XGBOOST_DEVICE bool empty() const __span_noexcept
Definition: span.h:554
xgboost::BatchIteratorImpl::iterator_category
std::forward_iterator_tag iterator_category
Definition: data.h:409
xgboost::DMatrix::DMatrix
DMatrix()=default
default constructor
xgboost::HostDeviceVector::HostVector
std::vector< T > & HostVector()
DataIterResetCallback
XGB_EXTERN_C typedef void DataIterResetCallback(DataIterHandle handle)
Callback function prototype for resetting external iterator.
xgboost::BatchParam::gpu_id
int gpu_id
The GPU device to use.
Definition: data.h:214
xgboost::MetaInfo::feature_types
HostDeviceVector< FeatureType > feature_types
Definition: data.h:91
span.h
xgboost::DMatrix::EllpackExists
virtual bool EllpackExists() const =0
xgboost::Entry::Entry
XGBOOST_DEVICE Entry(bst_feature_t index, bst_float fvalue)
constructor with index and value
Definition: data.h:199
xgboost::EllpackPage::~EllpackPage
~EllpackPage()
Destructor.
xgboost::DMatrix::IsDense
bool IsDense() const
Whether the matrix is dense.
Definition: data.h:503
xgboost::SortedCSCPage
Definition: data.h:355
xgboost::Entry::operator==
bool operator==(const Entry &other) const
Definition: data.h:204
xgboost::BatchIterator::operator!=
bool operator!=(const BatchIterator &) const
Definition: data.h:435
dmlc::serializer::Handler< xgboost::Entry >::Write
static void Write(Stream *strm, const xgboost::Entry &data)
Definition: data.h:648
xgboost::MetaInfo::GetWeight
bst_float GetWeight(size_t i) const
Get weight of each instances.
Definition: data.h:115
xgboost::HostSparsePageView::Size
size_t Size() const
Definition: data.h:253
xgboost::SparsePage::GetView
HostSparsePageView GetView() const
Definition: data.h:271
xgboost::BatchParam
Parameters for constructing batches.
Definition: data.h:212
xgboost::SparsePage::base_rowid
size_t base_rowid
Definition: data.h:266
xgboost::HostSparsePageView
Definition: data.h:241
xgboost::DataType
DataType
data type accepted by xgboost interface
Definition: data.h:29
xgboost::DMatrix::SparsePageExists
virtual bool SparsePageExists() const =0
xgboost::FeatureType::kNumerical
@ kNumerical
xgboost::DMatrix::kPageSize
static const size_t kPageSize
Number of rows per page in external memory. Approximately 100MB per page for dataset with 100 feature...
Definition: data.h:592
xgboost::SparsePage::MemCostBytes
size_t MemCostBytes() const
Definition: data.h:287
XGBOOST_PARALLEL_SORT
#define XGBOOST_PARALLEL_SORT(X, Y, Z)
Definition: base.h:68
xgboost::SparsePage::PushCSC
void PushCSC(const SparsePage &batch)
Push a SparsePage stored in CSC format.
xgboost::MetaInfo::Validate
void Validate(int32_t device) const
Validate all metainfo.
xgboost::SparsePage::GetTranspose
SparsePage GetTranspose(int num_columns) const
xgboost::BatchParam::BatchParam
BatchParam(int32_t device, int32_t max_bin, common::Span< float > hessian, bool regenerate=false)
Get batch with sketch weighted by hessian. The batch will be regenerated if the span is changed,...
Definition: data.h:229
xgboost::EllpackPage::Impl
EllpackPageImpl * Impl()
Definition: data.h:398
xgboost::MetaInfo::feature_weigths
HostDeviceVector< float > feature_weigths
Definition: data.h:96
xgboost::HostDeviceVector::Size
size_t Size() const
xgboost::FeatureType
FeatureType
Definition: data.h:37
xgboost::CSCPage
Definition: data.h:349
xgboost::Entry::Entry
Entry()=default
default constructor
xgboost::BatchIteratorImpl::AtEnd
virtual bool AtEnd() const =0
xgboost::BatchSet::end
BatchIterator< T > end()
Definition: data.h:458
xgboost::DataType::kStr
@ kStr
xgboost::DMatrix::GetColumnBatches
virtual BatchSet< CSCPage > GetColumnBatches()=0
xgboost::MetaInfo::weights_
HostDeviceVector< bst_float > weights_
weights of each instance, optional
Definition: data.h:64
xgboost::EllpackPage::EllpackPage
EllpackPage()
Default constructor.
xgboost::MetaInfo::num_nonzero_
uint64_t num_nonzero_
number of nonzero entries in the data
Definition: data.h:55
xgboost::XGBAPIThreadLocalEntry
entry to to easily hold returning information
Definition: learner.h:44
xgboost::DataType::kFloat32
@ kFloat32
xgboost::DMatrix::Slice
virtual DMatrix * Slice(common::Span< int32_t const > ridxs)=0
xgboost::common::Span
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:142
std
Definition: intrusive_ptr.h:206
xgboost::MetaInfo::operator=
MetaInfo & operator=(MetaInfo &&that)=default
xgboost::MetaInfo::SaveBinary
void SaveBinary(dmlc::Stream *fo) const
Save the Meta info to binary stream.
xgboost::BatchIterator::BatchIterator
BatchIterator(std::shared_ptr< BatchIteratorImpl< T >> impl)
Definition: data.h:422
xgboost::SparsePage::offset
HostDeviceVector< bst_row_t > offset
Definition: data.h:262
xgboost::MetaInfo::GetInfo
void GetInfo(char const *key, bst_ulong *out_len, DataType dtype, const void **out_dptr) const
DMatrixHandle
void * DMatrixHandle
handle to DMatrix
Definition: c_api.h:30
xgboost::common::Span::size
constexpr XGBOOST_DEVICE index_type size() const __span_noexcept
Definition: span.h:547
xgboost::BatchIterator
Definition: data.h:418
xgboost::common::Span::data
constexpr XGBOOST_DEVICE pointer data() const __span_noexcept
Definition: span.h:542
xgboost::Entry::CmpValue
static bool CmpValue(const Entry &a, const Entry &b)
reversely compare feature values
Definition: data.h:201
xgboost::MetaInfo
Meta information about dataset, always sit in memory.
Definition: data.h:45
xgboost::DMatrix::GetThreadLocal
XGBAPIThreadLocalEntry & GetThreadLocal() const
Get thread local memory for returning data from DMatrix.
xgboost::EllpackPage::SetBaseRowId
void SetBaseRowId(size_t row_id)
Set the base row id for this page.
xgboost::BatchIteratorImpl::operator*
virtual const T & operator*() const =0
dmlc::DMLC_DECLARE_TRAITS
DMLC_DECLARE_TRAITS(is_pod, xgboost::Entry, true)
xgboost::Entry::fvalue
bst_float fvalue
feature value
Definition: data.h:191
xgboost::DMatrix::GetBatches
BatchSet< T > GetBatches(const BatchParam &param={})
Gets batches. Use range based for loop over BatchSet to access individual batches.
xgboost::MetaInfo::labels_
HostDeviceVector< bst_float > labels_
label of each instance
Definition: data.h:57
xgboost::FeatureType::kCategorical
@ kCategorical
XGBOOST_DEVICE
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:84
xgboost::DMatrix::SetInfo
virtual void SetInfo(const char *key, const void *dptr, DataType dtype, size_t num)
Definition: data.h:475
xgboost::DMatrix::PageExists
bool PageExists() const
xgboost::SparsePage::data
HostDeviceVector< Entry > data
the data of the segments
Definition: data.h:264
dmlc::serializer::Handler< xgboost::Entry >::Read
static bool Read(Stream *strm, xgboost::Entry *data)
Definition: data.h:653
xgboost::BatchIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: data.h:420
xgboost::BatchParam::hess
common::Span< float > hess
Hessian, used for sketching with future approx implementation.
Definition: data.h:218
xgboost::MetaInfo::kNumField
static constexpr uint64_t kNumField
number of data fields in MetaInfo
Definition: data.h:48
xgboost::BatchSet
Definition: data.h:454
xgboost
namespace of xgboost
Definition: base.h:110
xgboost::SparsePage::Clear
void Clear()
clear the page
Definition: data.h:292
xgboost::MetaInfo::labels_upper_bound_
HostDeviceVector< bst_float > labels_upper_bound_
upper bound of the label, to be used for survival analysis (censored regression)
Definition: data.h:78
xgboost::bst_float
float bst_float
float type, used for storing statistics
Definition: base.h:119
xgboost::SparsePage::SparsePage
SparsePage()
constructor
Definition: data.h:277
xgboost::BatchParam::regen
bool regen
Whether should DMatrix regenerate the batch. Only used for GHistIndex.
Definition: data.h:220