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>
15 #include <xgboost/linalg.h>
16 #include <xgboost/span.h>
17 #include <xgboost/string_view.h>
18 
19 #include <algorithm>
20 #include <limits>
21 #include <memory>
22 #include <string>
23 #include <utility>
24 #include <vector>
25 
26 namespace xgboost {
27 // forward declare dmatrix.
28 class DMatrix;
29 struct Context;
30 
32 enum class DataType : uint8_t {
33  kFloat32 = 1,
34  kDouble = 2,
35  kUInt32 = 3,
36  kUInt64 = 4,
37  kStr = 5
38 };
39 
40 enum class FeatureType : uint8_t { kNumerical = 0, kCategorical = 1 };
41 
42 enum class DataSplitMode : int { kRow = 0, kCol = 1 };
43 
47 class MetaInfo {
48  public:
50  static constexpr uint64_t kNumField = 12;
51 
53  uint64_t num_row_{0}; // NOLINT
55  uint64_t num_col_{0}; // NOLINT
57  uint64_t num_nonzero_{0}; // NOLINT
66  std::vector<bst_group_t> group_ptr_; // NOLINT
83 
87  std::vector<std::string> feature_type_names;
91  std::vector<std::string> feature_names;
92  /*
93  * \brief Type of each feature. Automatically set when feature_type_names is specifed.
94  */
96  /*
97  * \brief Weight of each feature, used to define the probability of each feature being
98  * selected when using column sampling.
99  */
101 
103  MetaInfo() = default;
104  MetaInfo(MetaInfo&& that) = default;
105  MetaInfo& operator=(MetaInfo&& that) = default;
106  MetaInfo& operator=(MetaInfo const& that) = delete;
107 
111  void Validate(DeviceOrd device) const;
112 
114 
115  MetaInfo Copy() const;
116 
122  inline bst_float GetWeight(size_t i) const {
123  return weights_.Size() != 0 ? weights_.HostVector()[i] : 1.0f;
124  }
126  const std::vector<size_t>& LabelAbsSort(Context const* ctx) const;
128  void Clear();
133  void LoadBinary(dmlc::Stream* fi);
138  void SaveBinary(dmlc::Stream* fo) const;
144  void SetInfo(Context const& ctx, StringView key, StringView interface_str);
145 
146  void GetInfo(char const* key, bst_ulong* out_len, DataType dtype,
147  const void** out_dptr) const;
148 
149  void SetFeatureInfo(const char *key, const char **info, const bst_ulong size);
150  void GetFeatureInfo(const char *field, std::vector<std::string>* out_str_vecs) const;
151 
163  void Extend(MetaInfo const& that, bool accumulate_rows, bool check_column);
164 
173 
175  bool IsRowSplit() const {
177  }
178 
182  bool IsRanking() const { return !group_ptr_.empty(); }
183 
188  bool IsVerticalFederated() const;
189 
196  bool ShouldHaveLabels() const;
200  bool HasCategorical() const { return has_categorical_; }
201 
202  private:
203  void SetInfoFromHost(Context const& ctx, StringView key, Json arr);
204  void SetInfoFromCUDA(Context const& ctx, StringView key, Json arr);
205 
207  mutable std::vector<size_t> label_order_cache_;
208  bool has_categorical_{false};
209 };
210 
212 struct Entry {
218  Entry() = default;
226  inline static bool CmpValue(const Entry& a, const Entry& b) {
227  return a.fvalue < b.fvalue;
228  }
229  static bool CmpIndex(Entry const& a, Entry const& b) {
230  return a.index < b.index;
231  }
232  inline bool operator==(const Entry& other) const {
233  return (this->index == other.index && this->fvalue == other.fvalue);
234  }
235 };
236 
240 struct BatchParam {
253  bool regen{false};
257  bool forbid_regen{false};
261  double sparse_thresh{std::numeric_limits<double>::quiet_NaN()};
262 
266  BatchParam() = default;
279  : max_bin{max_bin}, hess{hessian}, regen{regenerate} {}
280 
281  [[nodiscard]] bool ParamNotEqual(BatchParam const& other) const {
282  // Check non-floating parameters.
283  bool cond = max_bin != other.max_bin;
284  // Check sparse thresh.
285  bool l_nan = std::isnan(sparse_thresh);
286  bool r_nan = std::isnan(other.sparse_thresh);
287  bool st_chg = (l_nan != r_nan) || (!l_nan && !r_nan && (sparse_thresh != other.sparse_thresh));
288  cond |= st_chg;
289 
290  return cond;
291  }
292  [[nodiscard]] bool Initialized() const { return max_bin != 0; }
296  [[nodiscard]] BatchParam MakeCache() const {
297  auto p = *this;
298  // These parameters have nothing to do with how the gradient index was generated in the
299  // first place.
300  p.regen = false;
301  p.forbid_regen = false;
302  return p;
303  }
304 };
305 
308 
311 
312  Inst operator[](size_t i) const {
313  auto size = *(offset.data() + i + 1) - *(offset.data() + i);
314  return {data.data() + *(offset.data() + i),
315  static_cast<Inst::index_type>(size)};
316  }
317 
318  [[nodiscard]] size_t Size() const { return offset.size() == 0 ? 0 : offset.size() - 1; }
319 };
320 
324 class SparsePage {
325  public:
326  // Offset for each row.
330 
331  size_t base_rowid {0};
332 
335 
336  [[nodiscard]] HostSparsePageView GetView() const {
337  return {offset.ConstHostSpan(), data.ConstHostSpan()};
338  }
339 
342  this->Clear();
343  }
344 
345  SparsePage(SparsePage const& that) = delete;
346  SparsePage(SparsePage&& that) = default;
347  SparsePage& operator=(SparsePage const& that) = delete;
348  SparsePage& operator=(SparsePage&& that) = default;
349  virtual ~SparsePage() = default;
350 
352  [[nodiscard]] size_t Size() const {
353  return offset.Size() == 0 ? 0 : offset.Size() - 1;
354  }
355 
357  [[nodiscard]] size_t MemCostBytes() const {
358  return offset.Size() * sizeof(size_t) + data.Size() * sizeof(Entry);
359  }
360 
362  inline void Clear() {
363  base_rowid = 0;
364  auto& offset_vec = offset.HostVector();
365  offset_vec.clear();
366  offset_vec.push_back(0);
367  data.HostVector().clear();
368  }
369 
371  inline void SetBaseRowId(size_t row_id) {
372  base_rowid = row_id;
373  }
374 
375  [[nodiscard]] SparsePage GetTranspose(int num_columns, int32_t n_threads) const;
376 
380  void SortIndices(int32_t n_threads);
384  [[nodiscard]] bool IsIndicesSorted(int32_t n_threads) const;
388  void Reindex(uint64_t feature_offset, int32_t n_threads);
389 
390  void SortRows(int32_t n_threads);
391 
402  template <typename AdapterBatchT>
403  uint64_t Push(const AdapterBatchT& batch, float missing, int nthread);
404 
409  void Push(const SparsePage &batch);
414  void PushCSC(const SparsePage& batch);
415 };
416 
417 class CSCPage: public SparsePage {
418  public:
420  explicit CSCPage(SparsePage page) : SparsePage(std::move(page)) {}
421 };
422 
428  public:
429  std::shared_ptr<SparsePage const> page;
430  explicit ExtSparsePage(std::shared_ptr<SparsePage const> p) : page{std::move(p)} {}
431 };
432 
433 class SortedCSCPage : public SparsePage {
434  public:
436  explicit SortedCSCPage(SparsePage page) : SparsePage(std::move(page)) {}
437 };
438 
439 class EllpackPage;
440 class GHistIndexMatrix;
441 
442 template<typename T>
444  public:
445  using iterator_category = std::forward_iterator_tag; // NOLINT
446  virtual ~BatchIteratorImpl() = default;
447  virtual const T& operator*() const = 0;
449  [[nodiscard]] virtual bool AtEnd() const = 0;
450  virtual std::shared_ptr<T const> Page() const = 0;
451 };
452 
453 template<typename T>
455  public:
456  using iterator_category = std::forward_iterator_tag; // NOLINT
457  explicit BatchIterator(BatchIteratorImpl<T>* impl) { impl_.reset(impl); }
458  explicit BatchIterator(std::shared_ptr<BatchIteratorImpl<T>> impl) { impl_ = impl; }
459 
461  CHECK(impl_ != nullptr);
462  ++(*impl_);
463  return *this;
464  }
465 
466  const T& operator*() const {
467  CHECK(impl_ != nullptr);
468  return *(*impl_);
469  }
470 
471  bool operator!=(const BatchIterator&) const {
472  CHECK(impl_ != nullptr);
473  return !impl_->AtEnd();
474  }
475 
476  [[nodiscard]] bool AtEnd() const {
477  CHECK(impl_ != nullptr);
478  return impl_->AtEnd();
479  }
480 
481  [[nodiscard]] std::shared_ptr<T const> Page() const {
482  return impl_->Page();
483  }
484 
485  private:
486  std::shared_ptr<BatchIteratorImpl<T>> impl_;
487 };
488 
489 template<typename T>
490 class BatchSet {
491  public:
492  explicit BatchSet(BatchIterator<T> begin_iter) : begin_iter_(std::move(begin_iter)) {}
493  BatchIterator<T> begin() { return begin_iter_; } // NOLINT
494  BatchIterator<T> end() { return BatchIterator<T>(nullptr); } // NOLINT
495 
496  private:
497  BatchIterator<T> begin_iter_;
498 };
499 
500 struct XGBAPIThreadLocalEntry;
501 
505 class DMatrix {
506  public:
508  DMatrix() = default;
510  virtual MetaInfo& Info() = 0;
511  virtual void SetInfo(const char* key, std::string const& interface_str) {
512  auto const& ctx = *this->Ctx();
513  this->Info().SetInfo(ctx, key, StringView{interface_str});
514  }
516  [[nodiscard]] virtual const MetaInfo& Info() const = 0;
517 
519  [[nodiscard]] XGBAPIThreadLocalEntry& GetThreadLocal() const;
524  [[nodiscard]] virtual Context const* Ctx() const = 0;
525 
529  template <typename T>
531  template <typename T>
533  template <typename T>
534  BatchSet<T> GetBatches(Context const* ctx, const BatchParam& param);
535  template <typename T>
536  [[nodiscard]] bool PageExists() const;
537 
538  // the following are column meta data, should be able to answer them fast.
540  [[nodiscard]] virtual bool SingleColBlock() const = 0;
542  virtual ~DMatrix();
543 
545  [[nodiscard]] bool IsDense() const {
546  return Info().num_nonzero_ == Info().num_row_ * Info().num_col_;
547  }
548 
557  static DMatrix* Load(const std::string& uri, bool silent = true,
558  DataSplitMode data_split_mode = DataSplitMode::kRow);
559 
572  template <typename AdapterT>
573  static DMatrix* Create(AdapterT* adapter, float missing, int nthread,
574  const std::string& cache_prefix = "",
575  DataSplitMode data_split_mode = DataSplitMode::kRow);
576 
596  template <typename DataIterHandle, typename DMatrixHandle, typename DataIterResetCallback,
597  typename XGDMatrixCallbackNext>
598  static DMatrix* Create(DataIterHandle iter, DMatrixHandle proxy, std::shared_ptr<DMatrix> ref,
599  DataIterResetCallback* reset, XGDMatrixCallbackNext* next, float missing,
600  int nthread, bst_bin_t max_bin);
601 
620  template <typename DataIterHandle, typename DMatrixHandle,
621  typename DataIterResetCallback, typename XGDMatrixCallbackNext>
623  DataIterResetCallback *reset,
624  XGDMatrixCallbackNext *next, float missing,
625  int32_t nthread, std::string cache);
626 
628 
636  virtual DMatrix *SliceCol(int num_slices, int slice_id) = 0;
637 
638  protected:
640  virtual BatchSet<CSCPage> GetColumnBatches(Context const* ctx) = 0;
642  virtual BatchSet<EllpackPage> GetEllpackBatches(Context const* ctx, BatchParam const& param) = 0;
644  BatchParam const& param) = 0;
645  virtual BatchSet<ExtSparsePage> GetExtBatches(Context const* ctx, BatchParam const& param) = 0;
646 
647  [[nodiscard]] virtual bool EllpackExists() const = 0;
648  [[nodiscard]] virtual bool GHistIndexExists() const = 0;
649  [[nodiscard]] virtual bool SparsePageExists() const = 0;
650 };
651 
652 template <>
654  return GetRowBatches();
655 }
656 
657 template <>
658 inline bool DMatrix::PageExists<EllpackPage>() const {
659  return this->EllpackExists();
660 }
661 
662 template <>
663 inline bool DMatrix::PageExists<GHistIndexMatrix>() const {
664  return this->GHistIndexExists();
665 }
666 
667 template <>
668 inline bool DMatrix::PageExists<SparsePage>() const {
669  return this->SparsePageExists();
670 }
671 
672 template <>
674  return GetRowBatches();
675 }
676 
677 template <>
678 inline BatchSet<CSCPage> DMatrix::GetBatches(Context const* ctx) {
679  return GetColumnBatches(ctx);
680 }
681 
682 template <>
683 inline BatchSet<SortedCSCPage> DMatrix::GetBatches(Context const* ctx) {
684  return GetSortedColumnBatches(ctx);
685 }
686 
687 template <>
689  return GetEllpackBatches(ctx, param);
690 }
691 
692 template <>
693 inline BatchSet<GHistIndexMatrix> DMatrix::GetBatches(Context const* ctx, BatchParam const& param) {
694  return GetGradientIndex(ctx, param);
695 }
696 
697 template <>
698 inline BatchSet<ExtSparsePage> DMatrix::GetBatches(Context const* ctx, BatchParam const& param) {
699  return GetExtBatches(ctx, param);
700 }
701 } // namespace xgboost
702 
704 
705 namespace dmlc {
707 
708 namespace serializer {
709 
710 template <>
711 struct Handler<xgboost::Entry> {
712  inline static void Write(Stream* strm, const xgboost::Entry& data) {
713  strm->Write(data.index);
714  strm->Write(data.fvalue);
715  }
716 
717  inline static bool Read(Stream* strm, xgboost::Entry* data) {
718  return strm->Read(&data->index) && strm->Read(&data->fvalue);
719  }
720 };
721 
722 } // namespace serializer
723 } // namespace dmlc
724 #endif // XGBOOST_DATA_H_
Defines configuration macros and basic types for xgboost.
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:62
Definition: data.h:443
virtual BatchIteratorImpl & operator++()=0
std::forward_iterator_tag iterator_category
Definition: data.h:445
virtual std::shared_ptr< T const > Page() const =0
virtual bool AtEnd() const =0
virtual const T & operator*() const =0
virtual ~BatchIteratorImpl()=default
Definition: data.h:454
BatchIterator(std::shared_ptr< BatchIteratorImpl< T >> impl)
Definition: data.h:458
std::forward_iterator_tag iterator_category
Definition: data.h:456
BatchIterator(BatchIteratorImpl< T > *impl)
Definition: data.h:457
const T & operator*() const
Definition: data.h:466
std::shared_ptr< T const > Page() const
Definition: data.h:481
BatchIterator & operator++()
Definition: data.h:460
bool operator!=(const BatchIterator &) const
Definition: data.h:471
bool AtEnd() const
Definition: data.h:476
Definition: data.h:490
BatchSet(BatchIterator< T > begin_iter)
Definition: data.h:492
BatchIterator< T > begin()
Definition: data.h:493
BatchIterator< T > end()
Definition: data.h:494
Definition: data.h:417
CSCPage()
Definition: data.h:419
CSCPage(SparsePage page)
Definition: data.h:420
Internal data structured used by XGBoost during training.
Definition: data.h:505
virtual BatchSet< EllpackPage > GetEllpackBatches(Context const *ctx, BatchParam const &param)=0
static DMatrix * Load(const std::string &uri, bool silent=true, DataSplitMode data_split_mode=DataSplitMode::kRow)
Load DMatrix from URI.
virtual BatchSet< SparsePage > GetRowBatches()=0
virtual BatchSet< GHistIndexMatrix > GetGradientIndex(Context const *ctx, BatchParam const &param)=0
virtual void SetInfo(const char *key, std::string const &interface_str)
Definition: data.h:511
static DMatrix * Create(DataIterHandle iter, DMatrixHandle proxy, std::shared_ptr< DMatrix > ref, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, float missing, int nthread, bst_bin_t max_bin)
Create a new Quantile based DMatrix used for histogram based algorithm.
virtual BatchSet< ExtSparsePage > GetExtBatches(Context const *ctx, BatchParam const &param)=0
bool PageExists() const
BatchSet< T > GetBatches(Context const *ctx)
virtual ~DMatrix()
virtual destructor
virtual MetaInfo & Info()=0
meta information of the dataset
static DMatrix * Create(AdapterT *adapter, float missing, int nthread, const std::string &cache_prefix="", DataSplitMode data_split_mode=DataSplitMode::kRow)
Creates a new DMatrix from an external data adapter.
virtual DMatrix * SliceCol(int num_slices, int slice_id)=0
Slice a DMatrix by columns.
virtual bool GHistIndexExists() const =0
XGBAPIThreadLocalEntry & GetThreadLocal() const
Get thread local memory for returning data from DMatrix.
virtual bool SparsePageExists() const =0
static DMatrix * Create(DataIterHandle iter, DMatrixHandle proxy, DataIterResetCallback *reset, XGDMatrixCallbackNext *next, float missing, int32_t nthread, std::string cache)
Create an external memory DMatrix with callbacks.
virtual DMatrix * Slice(common::Span< int32_t const > ridxs)=0
virtual Context const * Ctx() const =0
Get the context object of this DMatrix. The context is created during construction of DMatrix with us...
virtual bool SingleColBlock() const =0
BatchSet< T > GetBatches()
Gets batches. Use range based for loop over BatchSet to access individual batches.
virtual const MetaInfo & Info() const =0
meta information of the dataset
virtual bool EllpackExists() const =0
virtual BatchSet< CSCPage > GetColumnBatches(Context const *ctx)=0
virtual BatchSet< SortedCSCPage > GetSortedColumnBatches(Context const *ctx)=0
BatchSet< T > GetBatches(Context const *ctx, const BatchParam &param)
bool IsDense() const
Whether the matrix is dense.
Definition: data.h:545
DMatrix()=default
default constructor
Sparse page for exporting DMatrix. Same as SparsePage, just a different type to prevent being used in...
Definition: data.h:427
ExtSparsePage(std::shared_ptr< SparsePage const > p)
Definition: data.h:430
std::shared_ptr< SparsePage const > page
Definition: data.h:429
std::size_t Size() const
common::Span< T const > ConstHostSpan() const
Definition: host_device_vector.h:115
std::vector< T > & HostVector()
Data structure representing JSON format.
Definition: json.h:368
Meta information about dataset, always sit in memory.
Definition: data.h:47
linalg::Tensor< float, 2 > base_margin_
initialized margins, if specified, xgboost will start from this init margin can be used to specify in...
Definition: data.h:74
std::vector< std::string > feature_names
Name for each feature.
Definition: data.h:91
MetaInfo(MetaInfo &&that)=default
HostDeviceVector< bst_float > labels_upper_bound_
upper bound of the label, to be used for survival analysis (censored regression)
Definition: data.h:82
uint64_t num_col_
number of columns in the data
Definition: data.h:55
std::vector< std::string > feature_type_names
Name of type for each feature provided by users. Eg. "int"/"float"/"i"/"q".
Definition: data.h:87
HostDeviceVector< bst_float > weights_
weights of each instance, optional
Definition: data.h:68
bool IsVerticalFederated() const
A convenient method to check if we are doing vertical federated learning, which requires some special...
MetaInfo & operator=(MetaInfo const &that)=delete
void GetInfo(char const *key, bst_ulong *out_len, DataType dtype, const void **out_dptr) const
bool IsColumnSplit() const
Whether the data is split column-wise.
Definition: data.h:180
bst_float GetWeight(size_t i) const
Get weight of each instances.
Definition: data.h:122
HostDeviceVector< FeatureType > feature_types
Definition: data.h:95
DataSplitMode data_split_mode
data split mode
Definition: data.h:61
void LoadBinary(dmlc::Stream *fi)
Load the Meta info from binary stream.
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:66
void Validate(DeviceOrd device) const
Validate all metainfo.
HostDeviceVector< float > feature_weights
Definition: data.h:100
void GetFeatureInfo(const char *field, std::vector< std::string > *out_str_vecs) const
bool HasCategorical() const
Flag for whether the DMatrix has categorical features.
Definition: data.h:200
uint64_t num_row_
number of rows in the data
Definition: data.h:53
MetaInfo & operator=(MetaInfo &&that)=default
void Clear()
clear all the information
void Extend(MetaInfo const &that, bool accumulate_rows, bool check_column)
Extend with other MetaInfo.
bool IsRanking() const
Whether this is a learning to rank data.
Definition: data.h:182
uint64_t num_nonzero_
number of nonzero entries in the data
Definition: data.h:57
MetaInfo Slice(common::Span< int32_t const > ridxs) const
MetaInfo Copy() const
linalg::Tensor< float, 2 > labels
label of each instance
Definition: data.h:59
void SaveBinary(dmlc::Stream *fo) const
Save the Meta info to binary stream.
bool ShouldHaveLabels() const
A convenient method to check if the MetaInfo should contain labels.
MetaInfo()=default
default constructor
void SetInfo(Context const &ctx, StringView key, StringView interface_str)
Set information in the meta info with array interface.
void SynchronizeNumberOfColumns(Context const *ctx)
Synchronize the number of columns across all workers.
static constexpr uint64_t kNumField
number of data fields in MetaInfo
Definition: data.h:50
bool IsRowSplit() const
Whether the data is split row-wise.
Definition: data.h:175
HostDeviceVector< bst_float > labels_lower_bound_
lower bound of the label, to be used for survival analysis (censored regression)
Definition: data.h:78
const std::vector< size_t > & LabelAbsSort(Context const *ctx) const
get sorted indexes (argsort) of labels by absolute value (used by cox loss)
void SetFeatureInfo(const char *key, const char **info, const bst_ulong size)
Definition: data.h:433
SortedCSCPage(SparsePage page)
Definition: data.h:436
SortedCSCPage()
Definition: data.h:435
In-memory storage unit of sparse batch, stored in CSR format.
Definition: data.h:324
void Push(const SparsePage &batch)
Push a sparse page.
SparsePage()
constructor
Definition: data.h:341
SparsePage GetTranspose(int num_columns, int32_t n_threads) const
void SetBaseRowId(size_t row_id)
Set the base row id for this page.
Definition: data.h:371
void Reindex(uint64_t feature_offset, int32_t n_threads)
Reindex the column index with an offset.
uint64_t Push(const AdapterBatchT &batch, float missing, int nthread)
Pushes external data batch onto this page.
void PushCSC(const SparsePage &batch)
Push a SparsePage stored in CSC format.
bool IsIndicesSorted(int32_t n_threads) const
Check wether the column index is sorted.
virtual ~SparsePage()=default
void SortIndices(int32_t n_threads)
Sort the column index.
HostDeviceVector< Entry > data
the data of the segments
Definition: data.h:329
HostSparsePageView GetView() const
Definition: data.h:336
SparsePage & operator=(SparsePage const &that)=delete
size_t MemCostBytes() const
Definition: data.h:357
void Clear()
clear the page
Definition: data.h:362
SparsePage(SparsePage const &that)=delete
size_t Size() const
Definition: data.h:352
void SortRows(int32_t n_threads)
HostDeviceVector< bst_idx_t > offset
Definition: data.h:327
SparsePage & operator=(SparsePage &&that)=default
SparsePage(SparsePage &&that)=default
size_t base_rowid
Definition: data.h:331
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:422
constexpr XGBOOST_DEVICE pointer data() const __span_noexcept
Definition: span.h:547
std::size_t index_type
Definition: span.h:426
constexpr XGBOOST_DEVICE index_type size() const __span_noexcept
Definition: span.h:552
DECLARE_FIELD_ENUM_CLASS(xgboost::DataSplitMode)
void * DMatrixHandle
handle to DMatrix
Definition: c_api.h:50
int XGDMatrixCallbackNext(DataIterHandle iter)
Callback function prototype for getting next batch of data.
Definition: c_api.h:435
void * DataIterHandle
handle to a external data iterator
Definition: c_api.h:348
void DataIterResetCallback(DataIterHandle handle)
Callback function prototype for resetting external iterator.
Definition: c_api.h:440
A device-and-host vector abstraction layer.
Linear algebra related utilities.
Definition: data.h:705
DMLC_DECLARE_TRAITS(is_pod, xgboost::Entry, true)
Definition: intrusive_ptr.h:207
Core data structure for multi-target trees.
Definition: base.h:87
FeatureType
Definition: data.h:40
std::int32_t bst_bin_t
Type for histogram bin index. We sometimes use -1 to indicate invalid bin.
Definition: base.h:101
DataSplitMode
Definition: data.h:42
std::uint32_t bst_feature_t
Type for data column (feature) index.
Definition: base.h:97
DataType
data type accepted by xgboost interface
Definition: data.h:32
std::uint64_t bst_ulong
unsigned long integers
Definition: base.h:91
float bst_float
float type, used for storing statistics
Definition: base.h:93
static void Write(Stream *strm, const xgboost::Entry &data)
Definition: data.h:712
static bool Read(Stream *strm, xgboost::Entry *data)
Definition: data.h:717
Parameters for constructing histogram index batches.
Definition: data.h:240
bool forbid_regen
Forbid regenerating the gradient index. Used for internal validation.
Definition: data.h:257
bst_bin_t max_bin
Maximum number of bins per feature for histograms.
Definition: data.h:244
common::Span< float const > hess
Hessian, used for sketching with future approx implementation.
Definition: data.h:248
bool regen
Whether should we force DMatrix to regenerate the batch. Only used for GHistIndex.
Definition: data.h:253
bool ParamNotEqual(BatchParam const &other) const
Definition: data.h:281
BatchParam()=default
Exact or others that don't need histogram.
double sparse_thresh
Parameter used to generate column matrix for hist.
Definition: data.h:261
bool Initialized() const
Definition: data.h:292
BatchParam(bst_bin_t max_bin, common::Span< float const > hessian, bool regenerate)
Used by the approx tree method.
Definition: data.h:278
BatchParam MakeCache() const
Make a copy of self for DMatrix to describe how its existing index was generated.
Definition: data.h:296
BatchParam(bst_bin_t max_bin, double sparse_thresh)
Used by the hist tree method.
Definition: data.h:270
Runtime context for XGBoost. Contains information like threads and device.
Definition: context.h:133
A type for device ordinal. The type is packed into 32-bit for efficient use in viewing types like lin...
Definition: context.h:34
Element from a sparse vector.
Definition: data.h:212
XGBOOST_DEVICE Entry(bst_feature_t index, bst_float fvalue)
constructor with index and value
Definition: data.h:224
Entry()=default
default constructor
bst_feature_t index
feature index
Definition: data.h:214
static bool CmpIndex(Entry const &a, Entry const &b)
Definition: data.h:229
bst_float fvalue
feature value
Definition: data.h:216
bool operator==(const Entry &other) const
Definition: data.h:232
static bool CmpValue(const Entry &a, const Entry &b)
reversely compare feature values
Definition: data.h:226
Definition: data.h:306
size_t Size() const
Definition: data.h:318
common::Span< bst_idx_t const > offset
Definition: data.h:309
common::Span< Entry const > data
Definition: data.h:310
Inst operator[](size_t i) const
Definition: data.h:312
Definition: string_view.h:16