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>
107 void Validate(int32_t device)
const;
121 return label_order_cache_;
124 std::iota(label_order_cache_.begin(), label_order_cache_.end(), 0);
127 [&l](
size_t i1,
size_t i2) {return std::abs(l[i1]) < std::abs(l[i2]);});
129 return label_order_cache_;
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);
163 const void** out_dptr)
const;
166 void GetFeatureInfo(
const char *field, std::vector<std::string>* out_str_vecs)
const;
179 void Extend(
MetaInfo const& that,
bool accumulate_rows,
bool check_column);
183 mutable std::vector<size_t> label_order_cache_;
205 return (this->index == other.
index && this->fvalue == other.
fvalue);
230 bool regenerate =
false)
296 offset_vec.push_back(0);
297 data.HostVector().clear();
309 dmlc::OMPException exc;
310 #pragma omp parallel for schedule(dynamic, 1)
313 if (this->offset.
HostVector()[i] < this->offset.HostVector()[i + 1]) {
315 this->data.
HostVector().begin() + this->offset.HostVector()[i],
316 this->data.HostVector().begin() + this->offset.HostVector()[i + 1],
334 template <
typename AdapterBatchT>
335 uint64_t
Push(
const AdapterBatchT& batch,
float missing,
int nthread);
361 class EllpackPageImpl;
397 const EllpackPageImpl*
Impl()
const {
return impl_.get(); }
398 EllpackPageImpl*
Impl() {
return impl_.get(); }
401 std::unique_ptr<EllpackPageImpl> impl_;
404 class GHistIndexMatrix;
413 virtual bool AtEnd()
const = 0;
414 virtual std::shared_ptr<T const>
Page()
const = 0;
425 CHECK(impl_ !=
nullptr);
431 CHECK(impl_ !=
nullptr);
436 CHECK(impl_ !=
nullptr);
437 return !impl_->AtEnd();
441 CHECK(impl_ !=
nullptr);
442 return impl_->AtEnd();
445 std::shared_ptr<T const>
Page()
const {
446 return impl_->Page();
450 std::shared_ptr<BatchIteratorImpl<T>> impl_;
464 struct XGBAPIThreadLocalEntry;
479 virtual void SetInfo(
const char* key, std::string
const& interface_str) {
493 template <
typename T>
520 const std::string& file_format =
"auto");
534 template <
typename AdapterT>
535 static DMatrix*
Create(AdapterT* adapter,
float missing,
int nthread,
536 const std::string& cache_prefix =
"");
587 int32_t nthread, std::string cache);
611 inline bool DMatrix::PageExists<EllpackPage>()
const {
616 inline bool DMatrix::PageExists<SparsePage>()
const {
644 namespace serializer {
649 strm->Write(data.
index);
654 return strm->Read(&data->
index) && strm->Read(&data->
fvalue);
660 #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:216
virtual BatchSet< EllpackPage > GetEllpackBatches(const BatchParam ¶m)=0
virtual BatchIteratorImpl & operator++()=0
common::Span< Entry const > data
Definition: data.h:245
virtual ~BatchIteratorImpl()=default
size_t Size() const
Definition: data.h:282
void SetBaseRowId(size_t row_id)
Set the base row id for this page.
Definition: data.h:301
CSCPage()
Definition: data.h:351
virtual ~DMatrix()
virtual destructor
A page stored in ELLPACK format.
Definition: data.h:368
In-memory storage unit of sparse batch, stored in CSR format.
Definition: data.h:259
uint64_t Push(const AdapterBatchT &batch, float missing, int nthread)
Pushes external data batch onto this page.
CSCPage(SparsePage page)
Definition: data.h:352
std::size_t index_type
Definition: span.h:421
void SortRows()
Definition: data.h:307
Element from a sparse vector.
Definition: data.h:187
const EllpackPageImpl * Impl() const
Definition: data.h:397
virtual BatchSet< SparsePage > GetRowBatches()=0
BatchSet(BatchIterator< T > begin_iter)
Definition: data.h:456
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:358
bool AtEnd() const
Definition: data.h:440
SortedCSCPage()
Definition: data.h:357
virtual void SetInfo(const char *key, std::string const &interface_str)
Definition: data.h:479
BatchIterator(BatchIteratorImpl< T > *impl)
Definition: data.h:421
defines configuration macros of xgboost.
bool operator!=(const BatchParam &other) const
Definition: data.h:233
common::Span< T const > ConstHostSpan() const
Definition: host_device_vector.h:114
std::shared_ptr< T const > Page() const
Definition: data.h:445
void * DataIterHandle
handle to a external data iterator
Definition: c_api.h:287
BatchIterator< T > begin()
Definition: data.h:457
const T & operator*() const
Definition: data.h:430
Internal data structured used by XGBoost during training.
Definition: data.h:469
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:424
BatchParam(int32_t device, int32_t max_bin)
Definition: data.h:223
uint64_t bst_ulong
unsigned long integers
Definition: base.h:117
common::Span< bst_row_t const > offset
Definition: data.h:244
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:247
dmlc::omp_uint bst_omp_uint
define unsigned int for openmp loop
Definition: base.h:273
constexpr XGBOOST_DEVICE bool empty() const __span_noexcept
Definition: span.h:554
std::forward_iterator_tag iterator_category
Definition: data.h:409
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:214
virtual bool EllpackExists() const =0
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:503
bool operator==(const Entry &other) const
Definition: data.h:204
bool operator!=(const BatchIterator &) const
Definition: data.h:435
static void Write(Stream *strm, const xgboost::Entry &data)
Definition: data.h:648
size_t Size() const
Definition: data.h:253
HostSparsePageView GetView() const
Definition: data.h:271
Parameters for constructing batches.
Definition: data.h:212
size_t base_rowid
Definition: data.h:266
DataType
data type accepted by xgboost interface
Definition: data.h:29
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:592
size_t MemCostBytes() const
Definition: data.h:287
#define XGBOOST_PARALLEL_SORT(X, Y, Z)
Definition: base.h:68
void PushCSC(const SparsePage &batch)
Push a SparsePage stored in CSC format.
SparsePage GetTranspose(int num_columns) const
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
EllpackPageImpl * Impl()
Definition: data.h:398
FeatureType
Definition: data.h:37
Entry()=default
default constructor
virtual bool AtEnd() const =0
BatchIterator< T > end()
Definition: data.h:458
virtual BatchSet< CSCPage > GetColumnBatches()=0
EllpackPage()
Default constructor.
entry to to easily hold returning information
Definition: learner.h:44
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:142
Definition: intrusive_ptr.h:206
BatchIterator(std::shared_ptr< BatchIteratorImpl< T >> impl)
Definition: data.h:422
HostDeviceVector< bst_row_t > offset
Definition: data.h:262
void * DMatrixHandle
handle to DMatrix
Definition: c_api.h:30
constexpr XGBOOST_DEVICE index_type size() const __span_noexcept
Definition: span.h:547
constexpr XGBOOST_DEVICE pointer data() const __span_noexcept
Definition: span.h:542
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
DMLC_DECLARE_TRAITS(is_pod, xgboost::Entry, true)
bst_float fvalue
feature value
Definition: data.h:191
BatchSet< T > GetBatches(const BatchParam ¶m={})
Gets batches. Use range based for loop over BatchSet to access individual batches.
#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:475
HostDeviceVector< Entry > data
the data of the segments
Definition: data.h:264
static bool Read(Stream *strm, xgboost::Entry *data)
Definition: data.h:653
std::forward_iterator_tag iterator_category
Definition: data.h:420
common::Span< float > hess
Hessian, used for sketching with future approx implementation.
Definition: data.h:218
namespace of xgboost
Definition: base.h:110
void Clear()
clear the page
Definition: data.h:292
float bst_float
float type, used for storing statistics
Definition: base.h:119
SparsePage()
constructor
Definition: data.h:277
bool regen
Whether should DMatrix regenerate the batch. Only used for GHistIndex.
Definition: data.h:220