Medial Code Documentation
Loading...
Searching...
No Matches
simple_dmatrix.h
Go to the documentation of this file.
1
7#ifndef XGBOOST_DATA_SIMPLE_DMATRIX_H_
8#define XGBOOST_DATA_SIMPLE_DMATRIX_H_
9
10#include <xgboost/base.h>
11#include <xgboost/data.h>
12
13#include <memory>
14#include <string>
15
16#include "gradient_index.h"
17
18namespace xgboost {
19namespace data {
20// Used for single batch data.
21class SimpleDMatrix : public DMatrix {
22 public:
23 SimpleDMatrix() = default;
24 template <typename AdapterT>
25 explicit SimpleDMatrix(AdapterT* adapter, float missing, int nthread,
26 DataSplitMode data_split_mode = DataSplitMode::kRow);
27
28 explicit SimpleDMatrix(dmlc::Stream* in_stream);
29 ~SimpleDMatrix() override = default;
30
31 void SaveToLocalFile(const std::string& fname);
32
33 MetaInfo& Info() override;
34 const MetaInfo& Info() const override;
35 Context const* Ctx() const override { return &fmat_ctx_; }
36
37 bool SingleColBlock() const override { return true; }
38 DMatrix* Slice(common::Span<int32_t const> ridxs) override;
39 DMatrix* SliceCol(int num_slices, int slice_id) override;
40
42 static const int kMagic = 0xffffab01;
43
44 protected:
45 BatchSet<SparsePage> GetRowBatches() override;
46 BatchSet<CSCPage> GetColumnBatches(Context const* ctx) override;
47 BatchSet<SortedCSCPage> GetSortedColumnBatches(Context const* ctx) override;
48 BatchSet<EllpackPage> GetEllpackBatches(Context const* ctx, const BatchParam& param) override;
49 BatchSet<GHistIndexMatrix> GetGradientIndex(Context const* ctx, const BatchParam& param) override;
50 BatchSet<ExtSparsePage> GetExtBatches(Context const* ctx, BatchParam const& param) override;
51
52 MetaInfo info_;
53 // Primary storage type
54 std::shared_ptr<SparsePage> sparse_page_ = std::make_shared<SparsePage>();
55 std::shared_ptr<CSCPage> column_page_{nullptr};
56 std::shared_ptr<SortedCSCPage> sorted_column_page_{nullptr};
57 std::shared_ptr<EllpackPage> ellpack_page_{nullptr};
58 std::shared_ptr<GHistIndexMatrix> gradient_index_{nullptr};
59 BatchParam batch_param_;
60
61 bool EllpackExists() const override { return static_cast<bool>(ellpack_page_); }
62 bool GHistIndexExists() const override { return static_cast<bool>(gradient_index_); }
63 bool SparsePageExists() const override { return true; }
64
72 void ReindexFeatures(Context const* ctx);
73
74 private:
75 // Context used only for DMatrix initialization.
76 Context fmat_ctx_;
77};
78} // namespace data
79} // namespace xgboost
80#endif // XGBOOST_DATA_SIMPLE_DMATRIX_H_
interface of stream I/O for serialization
Definition io.h:30
Definition data.h:494
Meta information about dataset, always sit in memory.
Definition data.h:48
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition span.h:424
Definition core.py:748
Definition core.py:741
Definition simple_dmatrix.h:21
void ReindexFeatures(Context const *ctx)
Reindex the features based on a global view.
Definition simple_dmatrix.cc:77
static const int kMagic
magic number used to identify SimpleDMatrix binary files
Definition simple_dmatrix.h:42
Copyright 2015-2023 by XGBoost Contributors.
Copyright 2015-2023 by XGBoost Contributors.
namespace of xgboost
Definition base.h:90
Parameters for constructing histogram index batches.
Definition data.h:244
Runtime context for XGBoost.
Definition context.h:84