Go to the documentation of this file.
7 #ifndef XGBOOST_DATA_H_
8 #define XGBOOST_DATA_H_
10 #include <dmlc/base.h>
11 #include <dmlc/data.h>
12 #include <dmlc/serializer.h>
108 void Validate(int32_t device)
const;
121 if (label_order_cache_.size() ==
labels.
Size()) {
122 return label_order_cache_;
125 std::iota(label_order_cache_.begin(), label_order_cache_.end(), 0);
128 [&l](
size_t i1,
size_t i2) {return std::abs(l[i1]) < std::abs(l[i2]);});
130 return label_order_cache_;
160 const void** out_dptr)
const;
163 void GetFeatureInfo(
const char *field, std::vector<std::string>* out_str_vecs)
const;
176 void Extend(
MetaInfo const& that,
bool accumulate_rows,
bool check_column);
183 mutable std::vector<size_t> label_order_cache_;
208 return (this->index == other.
index && this->fvalue == other.
fvalue);
249 return !(*
this != other);
308 offset_vec.push_back(0);
309 data.HostVector().clear();
340 template <
typename AdapterBatchT>
341 uint64_t
Push(
const AdapterBatchT& batch,
float missing,
int nthread);
367 class EllpackPageImpl;
403 const EllpackPageImpl*
Impl()
const {
return impl_.get(); }
404 EllpackPageImpl*
Impl() {
return impl_.get(); }
407 std::unique_ptr<EllpackPageImpl> impl_;
410 class GHistIndexMatrix;
419 virtual bool AtEnd()
const = 0;
420 virtual std::shared_ptr<T const>
Page()
const = 0;
431 CHECK(impl_ !=
nullptr);
437 CHECK(impl_ !=
nullptr);
442 CHECK(impl_ !=
nullptr);
443 return !impl_->AtEnd();
447 CHECK(impl_ !=
nullptr);
448 return impl_->AtEnd();
451 std::shared_ptr<T const>
Page()
const {
452 return impl_->Page();
456 std::shared_ptr<BatchIteratorImpl<T>> impl_;
470 struct XGBAPIThreadLocalEntry;
482 auto const& ctx = *this->
Ctx();
485 virtual void SetInfo(
const char* key, std::string
const& interface_str) {
486 auto const& ctx = *this->
Ctx();
503 template <
typename T>
505 template <
typename T>
507 template <
typename T>
534 const std::string& file_format =
"auto");
548 template <
typename AdapterT>
549 static DMatrix*
Create(AdapterT* adapter,
float missing,
int nthread,
550 const std::string& cache_prefix =
"");
601 int32_t nthread, std::string cache);
625 inline bool DMatrix::PageExists<EllpackPage>()
const {
630 inline bool DMatrix::PageExists<SparsePage>()
const {
658 namespace serializer {
663 strm->Write(data.
index);
668 return strm->Read(&data->
index) && strm->Read(&data->
fvalue);
674 #endif // XGBOOST_DATA_H_
bst_feature_t index
feature index
Definition: data.h:189
virtual std::shared_ptr< T const > Page() const =0
virtual MetaInfo & Info()=0
meta information of the dataset
int max_bin
Maximum number of bins per feature for histograms.
Definition: data.h:219
bool IsIndicesSorted(int32_t n_threads) const
Check wether the column index is sorted.
virtual BatchSet< EllpackPage > GetEllpackBatches(const BatchParam ¶m)=0
virtual BatchIteratorImpl & operator++()=0
common::Span< Entry const > data
Definition: data.h:257
virtual Context const * Ctx() const =0
Get the context object of this DMatrix. The context is created during construction of DMatrix with us...
virtual ~BatchIteratorImpl()=default
size_t Size() const
Definition: data.h:294
void SetBaseRowId(size_t row_id)
Set the base row id for this page.
Definition: data.h:313
CSCPage()
Definition: data.h:357
virtual ~DMatrix()
virtual destructor
A page stored in ELLPACK format.
Definition: data.h:374
In-memory storage unit of sparse batch, stored in CSR format.
Definition: data.h:271
uint64_t Push(const AdapterBatchT &batch, float missing, int nthread)
Pushes external data batch onto this page.
CSCPage(SparsePage page)
Definition: data.h:358
Definition: string_view.h:14
std::size_t index_type
Definition: span.h:427
Definition: generic_parameters.h:15
Element from a sparse vector.
Definition: data.h:187
bool operator!=(BatchParam const &other) const
Definition: data.h:242
const EllpackPageImpl * Impl() const
Definition: data.h:403
virtual BatchSet< SparsePage > GetRowBatches()=0
BatchSet(BatchIterator< T > begin_iter)
Definition: data.h:462
static DMatrix * Create(AdapterT *adapter, float missing, int nthread, const std::string &cache_prefix="")
Creates a new DMatrix from an external data adapter.
A device-and-host vector abstraction layer.
virtual bool SingleColBlock() const =0
SortedCSCPage(SparsePage page)
Definition: data.h:364
bool AtEnd() const
Definition: data.h:446
#define XGBOOST_PARALLEL_STABLE_SORT(X, Y, Z)
Definition: base.h:69
SortedCSCPage()
Definition: data.h:363
virtual void SetInfo(const char *key, std::string const &interface_str)
Definition: data.h:485
BatchIterator(BatchIteratorImpl< T > *impl)
Definition: data.h:427
defines configuration macros of xgboost.
common::Span< T const > ConstHostSpan() const
Definition: host_device_vector.h:114
std::shared_ptr< T const > Page() const
Definition: data.h:451
void * DataIterHandle
handle to a external data iterator
Definition: c_api.h:296
BatchIterator< T > begin()
Definition: data.h:463
const T & operator*() const
Definition: data.h:436
Internal data structured used by XGBoost during training.
Definition: data.h:475
static DMatrix * Load(const std::string &uri, bool silent, bool load_row_split, const std::string &file_format="auto")
Load DMatrix from URI.
XGB_EXTERN_C typedef int XGDMatrixCallbackNext(DataIterHandle iter)
Callback function prototype for getting next batch of data.
BatchIterator & operator++()
Definition: data.h:430
BatchParam(int32_t device, int32_t max_bin)
Definition: data.h:229
uint64_t bst_ulong
unsigned long integers
Definition: base.h:117
common::Span< bst_row_t const > offset
Definition: data.h:256
HostDeviceVector< T > * Data()
Definition: linalg.h:738
virtual BatchSet< GHistIndexMatrix > GetGradientIndex(const BatchParam ¶m)=0
uint32_t bst_feature_t
Type for data column (feature) index.
Definition: base.h:123
virtual BatchSet< SortedCSCPage > GetSortedColumnBatches()=0
Inst operator[](size_t i) const
Definition: data.h:259
constexpr XGBOOST_DEVICE bool empty() const __span_noexcept
Definition: span.h:560
std::forward_iterator_tag iterator_category
Definition: data.h:415
DMatrix()=default
default constructor
std::vector< T > & HostVector()
XGB_EXTERN_C typedef void DataIterResetCallback(DataIterHandle handle)
Callback function prototype for resetting external iterator.
int gpu_id
The GPU device to use.
Definition: data.h:217
SparsePage GetTranspose(int num_columns, int32_t n_threads) const
virtual bool EllpackExists() const =0
BatchParam(int32_t max_bin, double sparse_thresh)
Definition: data.h:232
XGBOOST_DEVICE Entry(bst_feature_t index, bst_float fvalue)
constructor with index and value
Definition: data.h:199
~EllpackPage()
Destructor.
bool IsDense() const
Whether the matrix is dense.
Definition: data.h:517
bool operator==(const Entry &other) const
Definition: data.h:207
bool operator==(BatchParam const &other) const
Definition: data.h:248
double sparse_thresh
Parameter used to generate column matrix for hist.
Definition: data.h:225
bool operator!=(const BatchIterator &) const
Definition: data.h:441
static void Write(Stream *strm, const xgboost::Entry &data)
Definition: data.h:662
BatchSet< T > GetBatches()
Gets batches. Use range based for loop over BatchSet to access individual batches.
size_t Size() const
Definition: data.h:265
HostSparsePageView GetView() const
Definition: data.h:283
Linear algebra related utilities.
Parameters for constructing batches.
Definition: data.h:215
size_t base_rowid
Definition: data.h:278
static bool CmpIndex(Entry const &a, Entry const &b)
Definition: data.h:204
DataType
data type accepted by xgboost interface
Definition: data.h:33
virtual bool SparsePageExists() const =0
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:606
size_t MemCostBytes() const
Definition: data.h:299
BatchParam(int32_t max_bin, common::Span< float > hessian, bool regenerate)
Get batch with sketch weighted by hessian. The batch will be regenerated if the span is changed,...
Definition: data.h:239
void PushCSC(const SparsePage &batch)
Push a SparsePage stored in CSC format.
EllpackPageImpl * Impl()
Definition: data.h:404
FeatureType
Definition: data.h:41
Entry()=default
default constructor
virtual bool AtEnd() const =0
BatchIterator< T > end()
Definition: data.h:464
virtual BatchSet< CSCPage > GetColumnBatches()=0
EllpackPage()
Default constructor.
entry to to easily hold returning information
Definition: learner.h:45
virtual DMatrix * Slice(common::Span< int32_t const > ridxs)=0
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:148
void SortRows(int32_t n_threads)
Definition: intrusive_ptr.h:207
BatchIterator(std::shared_ptr< BatchIteratorImpl< T >> impl)
Definition: data.h:428
HostDeviceVector< bst_row_t > offset
Definition: data.h:274
void * DMatrixHandle
handle to DMatrix
Definition: c_api.h:30
constexpr XGBOOST_DEVICE index_type size() const __span_noexcept
Definition: span.h:553
constexpr XGBOOST_DEVICE pointer data() const __span_noexcept
Definition: span.h:548
static bool CmpValue(const Entry &a, const Entry &b)
reversely compare feature values
Definition: data.h:201
XGBAPIThreadLocalEntry & GetThreadLocal() const
Get thread local memory for returning data from DMatrix.
void SetBaseRowId(size_t row_id)
Set the base row id for this page.
virtual const T & operator*() const =0
Data structure representing JSON format.
Definition: json.h:352
DMLC_DECLARE_TRAITS(is_pod, xgboost::Entry, true)
size_t Size() const
Definition: linalg.h:734
bst_float fvalue
feature value
Definition: data.h:191
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:84
virtual void SetInfo(const char *key, const void *dptr, DataType dtype, size_t num)
Definition: data.h:481
HostDeviceVector< Entry > data
the data of the segments
Definition: data.h:276
static bool Read(Stream *strm, xgboost::Entry *data)
Definition: data.h:667
std::forward_iterator_tag iterator_category
Definition: data.h:426
common::Span< float > hess
Hessian, used for sketching with future approx implementation.
Definition: data.h:221
namespace of xgboost
Definition: base.h:110
void Clear()
clear the page
Definition: data.h:304
float bst_float
float type, used for storing statistics
Definition: base.h:119
void SortIndices(int32_t n_threads)
Sort the column index.
SparsePage()
constructor
Definition: data.h:289
bool regen
Whether should DMatrix regenerate the batch. Only used for GHistIndex.
Definition: data.h:223