7 #ifndef XGBOOST_DATA_H_ 8 #define XGBOOST_DATA_H_ 10 #include <dmlc/base.h> 11 #include <dmlc/data.h> 12 #include <rabit/rabit.h> 42 static constexpr uint64_t kNumField = 7;
49 uint64_t num_nonzero_{0};
94 if (label_order_cache_.size() == labels_.
Size()) {
95 return label_order_cache_;
97 label_order_cache_.resize(labels_.
Size());
98 std::iota(label_order_cache_.begin(), label_order_cache_.end(), 0);
101 [&l](
size_t i1,
size_t i2) {
return std::abs(l[i1]) < std::abs(l[i2]);});
103 return label_order_cache_;
111 void LoadBinary(dmlc::Stream* fi);
116 void SaveBinary(dmlc::Stream* fo)
const;
124 void SetInfo(
const char* key,
const void* dptr,
DataType dtype,
size_t num);
134 void SetInfo(
const char* key, std::string
const& interface_str);
138 mutable std::vector<size_t> label_order_cache_;
160 return (this->index == other.
index && this->fvalue == other.
fvalue);
178 return gpu_id != other.
gpu_id ||
207 if (rabit::IsDistributed() && i + 1 >= offset_vec.size()) {
210 size = offset_vec[i + 1] - offset_vec[i];
212 return {data_vec.data() + offset_vec[i],
223 return offset.
Size() == 0 ? 0 : offset.
Size() - 1;
228 return offset.
Size() *
sizeof(size_t) + data.
Size() *
sizeof(
Entry);
236 offset_vec.push_back(0);
245 SparsePage GetTranspose(
int num_columns)
const;
249 #pragma omp parallel for default(none) shared(ncol) schedule(dynamic, 1) 264 void Push(
const dmlc::RowBlock<uint32_t>& batch);
276 template <
typename AdapterBatchT>
277 uint64_t Push(
const AdapterBatchT& batch,
float missing,
int nthread);
303 class EllpackPageImpl;
335 void SetBaseRowId(
size_t row_id);
337 const EllpackPageImpl*
Impl()
const {
return impl_.get(); }
338 EllpackPageImpl*
Impl() {
return impl_.get(); }
341 std::unique_ptr<EllpackPageImpl> impl_;
348 virtual T& operator*() = 0;
349 virtual const T& operator*()
const = 0;
350 virtual void operator++() = 0;
351 virtual bool AtEnd()
const = 0;
361 CHECK(impl_ !=
nullptr);
366 CHECK(impl_ !=
nullptr);
371 CHECK(impl_ !=
nullptr);
376 CHECK(impl_ !=
nullptr);
377 return !impl_->AtEnd();
381 CHECK(impl_ !=
nullptr);
382 return impl_->AtEnd();
386 std::shared_ptr<BatchIteratorImpl<T>> impl_;
435 virtual const MetaInfo& Info()
const = 0;
443 virtual bool SingleColBlock()
const = 0;
445 virtual float GetColDensity(
size_t cidx) = 0;
455 virtual void SaveToLocalFile(
const std::string& fname);
459 return Info().num_nonzero_ == Info().num_row_ * Info().num_col_;
472 static DMatrix* Load(
const std::string& uri,
475 const std::string& file_format =
"auto",
476 size_t page_size = kPageSize);
486 const std::string& cache_prefix =
"");
500 template <
typename AdapterT>
501 static DMatrix* Create(AdapterT* adapter,
float missing,
int nthread,
502 const std::string& cache_prefix =
"",
503 size_t page_size = kPageSize);
507 static const size_t kPageSize = 32UL << 20UL;
518 return GetRowBatches();
523 return GetColumnBatches();
528 return GetSortedColumnBatches();
533 return GetEllpackBatches(param);
540 #endif // XGBOOST_DATA_H_
void operator++()
Definition: data.h:360
std::forward_iterator_tag iterator_category
Definition: data.h:357
float bst_float
float type, used for storing statistics
Definition: base.h:111
bool IsDense() const
Whether the matrix is dense.
Definition: data.h:458
void Copy(const HostDeviceVector< T > &other)
BatchIterator(BatchIteratorImpl< T > *impl)
Definition: data.h:358
#define XGBOOST_PARALLEL_SORT(X, Y, Z)
Definition: base.h:68
A page stored in ELLPACK format.
Definition: data.h:310
const T & operator*() const
Definition: data.h:370
T & operator*()
Definition: data.h:365
SortedCSCPage()
Definition: data.h:299
std::size_t index_type
Definition: span.h:394
bool operator!=(const BatchParam &other) const
Definition: data.h:177
bool AtEnd() const
Definition: data.h:380
void SetBaseRowId(size_t row_id)
Set the base row id for this page.
Definition: data.h:241
void SortRows()
Definition: data.h:247
size_t gpu_page_size
Page size for external memory mode.
Definition: data.h:175
BatchSet(BatchIterator< T > begin_iter)
Definition: data.h:392
uint32_t bst_feature_t
Type for data column (feature) index.
Definition: base.h:114
dmlc::omp_uint bst_omp_uint
define unsigned int for openmp loop
Definition: base.h:246
Internal data structured used by XGBoost during training. There are two ways to create a customized D...
Definition: data.h:428
In-memory storage unit of sparse batch, stored in CSR format.
Definition: data.h:188
A device-and-host vector abstraction layer.
Parameters for constructing batches.
Definition: data.h:167
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:115
BatchSet< T > GetBatches(const BatchParam ¶m={})
Gets batches. Use range based for loop over BatchSet to access individual batches.
int gpu_id
The GPU device to use.
Definition: data.h:169
HostDeviceVector< bst_row_t > offset
Definition: data.h:191
XGBOOST_DEVICE Entry(bst_feature_t index, bst_float fvalue)
constructor with index and value
Definition: data.h:154
SparsePage()
constructor
Definition: data.h:217
BatchIterator< T > begin()
Definition: data.h:393
const EllpackPageImpl * Impl() const
Definition: data.h:337
SortedCSCPage(SparsePage page)
Definition: data.h:300
CSCPage()
Definition: data.h:293
std::vector< T > & HostVector()
bool operator==(const Entry &other) const
Definition: data.h:159
Inst operator[](size_t i) const
get i-th row from the batch
Definition: data.h:201
This is data structure that user can pass to DMatrix::Create to create a DMatrix for training...
Definition: data.h:408
bool operator!=(const BatchIterator &rhs) const
Definition: data.h:375
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:84
size_t MemCostBytes() const
Definition: data.h:227
namespace of xgboost
Definition: base.h:102
CSCPage(SparsePage page)
Definition: data.h:294
defines configuration macros of xgboost.
size_t Size() const
Definition: data.h:222
DataType
data type accepted by xgboost interface
Definition: data.h:29
HostDeviceVector< Entry > data
the data of the segments
Definition: data.h:193
Element from a sparse vector.
Definition: data.h:142
DMLC_DECLARE_TRAITS(is_pod, xgboost::Entry, true)
BatchIterator< T > end()
Definition: data.h:394
bst_feature_t index
feature index
Definition: data.h:144
bst_float fvalue
feature value
Definition: data.h:146
static bool CmpValue(const Entry &a, const Entry &b)
reversely compare feature values
Definition: data.h:156
void Resize(size_t new_size, T v=T())
void Clear()
clear the page
Definition: data.h:232
int gpu_batch_nrows
Number of rows in a GPU batch, used for finding quantiles on GPU.
Definition: data.h:173
int max_bin
Maximum number of bins per feature for histograms.
Definition: data.h:171
MetaInfo info
Meta information about the dataset The subclass need to be able to load this correctly from data...
Definition: data.h:414
EllpackPageImpl * Impl()
Definition: data.h:338