Use std::uint64_t for row index. (#10120)
- Use std::uint64_t instead of size_t to avoid implementation-defined type. - Rename to bst_idx_t, to account for other types of indexing. - Small cleanup to the base header.
This commit is contained in:
@@ -1,20 +1,18 @@
|
||||
/**
|
||||
* Copyright 2015-2023 by XGBoost Contributors
|
||||
* Copyright 2015-2024, XGBoost Contributors
|
||||
* \file base.h
|
||||
* \brief Defines configuration macros and basic types for xgboost.
|
||||
*/
|
||||
#ifndef XGBOOST_BASE_H_
|
||||
#define XGBOOST_BASE_H_
|
||||
|
||||
#include <dmlc/base.h>
|
||||
#include <dmlc/omp.h>
|
||||
#include <dmlc/omp.h> // for omp_uint, omp_ulong
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <cstdint> // for int32_t, uint64_t, int16_t
|
||||
#include <ostream> // for ostream
|
||||
#include <string> // for string
|
||||
#include <utility> // for pair
|
||||
#include <vector> // for vector
|
||||
|
||||
/*!
|
||||
* \brief string flag for R library, to leave hooks when needed.
|
||||
@@ -86,34 +84,31 @@
|
||||
|
||||
#endif // !defined(XGBOOST_MM_PREFETCH_PRESENT) && !defined()
|
||||
|
||||
/*! \brief namespace of xgboost*/
|
||||
namespace xgboost {
|
||||
|
||||
/*! \brief unsigned integer type used for feature index. */
|
||||
using bst_uint = uint32_t; // NOLINT
|
||||
using bst_uint = std::uint32_t; // NOLINT
|
||||
/*! \brief unsigned long integers */
|
||||
using bst_ulong = uint64_t; // NOLINT
|
||||
using bst_ulong = std::uint64_t; // NOLINT
|
||||
/*! \brief float type, used for storing statistics */
|
||||
using bst_float = float; // NOLINT
|
||||
/*! \brief Categorical value type. */
|
||||
using bst_cat_t = int32_t; // NOLINT
|
||||
using bst_cat_t = std::int32_t; // NOLINT
|
||||
/*! \brief Type for data column (feature) index. */
|
||||
using bst_feature_t = uint32_t; // NOLINT
|
||||
/*! \brief Type for histogram bin index. */
|
||||
using bst_bin_t = int32_t; // NOLINT
|
||||
/*! \brief Type for data row index.
|
||||
*
|
||||
* Be careful `std::size_t' is implementation-defined. Meaning that the binary
|
||||
* representation of DMatrix might not be portable across platform. Booster model should
|
||||
* be portable as parameters are floating points.
|
||||
using bst_feature_t = std::uint32_t; // NOLINT
|
||||
/**
|
||||
* @brief Type for histogram bin index. We sometimes use -1 to indicate invalid bin.
|
||||
*/
|
||||
using bst_row_t = std::size_t; // NOLINT
|
||||
using bst_bin_t = std::int32_t; // NOLINT
|
||||
/**
|
||||
* @brief Type for data row index (sample).
|
||||
*/
|
||||
using bst_idx_t = std::uint64_t; // NOLINT
|
||||
/*! \brief Type for tree node index. */
|
||||
using bst_node_t = std::int32_t; // NOLINT
|
||||
/*! \brief Type for ranking group index. */
|
||||
using bst_group_t = std::uint32_t; // NOLINT
|
||||
/**
|
||||
* \brief Type for indexing into output targets.
|
||||
* @brief Type for indexing into output targets.
|
||||
*/
|
||||
using bst_target_t = std::uint32_t; // NOLINT
|
||||
/**
|
||||
@@ -306,8 +301,7 @@ class GradientPairInt64 {
|
||||
XGBOOST_DEVICE bool operator==(const GradientPairInt64 &rhs) const {
|
||||
return grad_ == rhs.grad_ && hess_ == rhs.hess_;
|
||||
}
|
||||
friend std::ostream &operator<<(std::ostream &os,
|
||||
const GradientPairInt64 &g) {
|
||||
friend std::ostream &operator<<(std::ostream &os, const GradientPairInt64 &g) {
|
||||
os << g.GetQuantisedGrad() << "/" << g.GetQuantisedHess();
|
||||
return os;
|
||||
}
|
||||
@@ -323,7 +317,7 @@ using omp_ulong = dmlc::omp_ulong; // NOLINT
|
||||
/*! \brief define unsigned int for openmp loop */
|
||||
using bst_omp_uint = dmlc::omp_uint; // NOLINT
|
||||
/*! \brief Type used for representing version number in binary form.*/
|
||||
using XGBoostVersionT = int32_t;
|
||||
using XGBoostVersionT = std::int32_t;
|
||||
} // namespace xgboost
|
||||
|
||||
#endif // XGBOOST_BASE_H_
|
||||
|
||||
@@ -315,7 +315,7 @@ struct BatchParam {
|
||||
struct HostSparsePageView {
|
||||
using Inst = common::Span<Entry const>;
|
||||
|
||||
common::Span<bst_row_t const> offset;
|
||||
common::Span<bst_idx_t const> offset;
|
||||
common::Span<Entry const> data;
|
||||
|
||||
Inst operator[](size_t i) const {
|
||||
@@ -333,7 +333,7 @@ struct HostSparsePageView {
|
||||
class SparsePage {
|
||||
public:
|
||||
// Offset for each row.
|
||||
HostDeviceVector<bst_row_t> offset;
|
||||
HostDeviceVector<bst_idx_t> offset;
|
||||
/*! \brief the data of the segments */
|
||||
HostDeviceVector<Entry> data;
|
||||
|
||||
|
||||
@@ -60,9 +60,7 @@ class Value {
|
||||
virtual Json& operator[](int ind);
|
||||
|
||||
virtual bool operator==(Value const& rhs) const = 0;
|
||||
#if !defined(__APPLE__)
|
||||
virtual Value& operator=(Value const& rhs) = delete;
|
||||
#endif // !defined(__APPLE__)
|
||||
|
||||
std::string TypeStr() const;
|
||||
|
||||
@@ -105,6 +103,7 @@ class JsonString : public Value {
|
||||
std::string& GetString() & { return str_; }
|
||||
|
||||
bool operator==(Value const& rhs) const override;
|
||||
Value& operator=(Value const& rhs) override = delete;
|
||||
|
||||
static bool IsClassOf(Value const* value) {
|
||||
return value->Type() == ValueKind::kString;
|
||||
@@ -134,6 +133,7 @@ class JsonArray : public Value {
|
||||
std::vector<Json>& GetArray() & { return vec_; }
|
||||
|
||||
bool operator==(Value const& rhs) const override;
|
||||
Value& operator=(Value const& rhs) override = delete;
|
||||
|
||||
static bool IsClassOf(Value const* value) {
|
||||
return value->Type() == ValueKind::kArray;
|
||||
@@ -158,6 +158,7 @@ class JsonTypedArray : public Value {
|
||||
JsonTypedArray(JsonTypedArray&& that) noexcept : Value{kind}, vec_{std::move(that.vec_)} {}
|
||||
|
||||
bool operator==(Value const& rhs) const override;
|
||||
Value& operator=(Value const& rhs) override = delete;
|
||||
|
||||
void Set(size_t i, T v) { vec_[i] = v; }
|
||||
size_t Size() const { return vec_.size(); }
|
||||
@@ -216,6 +217,7 @@ class JsonObject : public Value {
|
||||
Map& GetObject() & { return object_; }
|
||||
|
||||
bool operator==(Value const& rhs) const override;
|
||||
Value& operator=(Value const& rhs) override = delete;
|
||||
|
||||
static bool IsClassOf(Value const* value) { return value->Type() == ValueKind::kObject; }
|
||||
~JsonObject() override = default;
|
||||
@@ -249,6 +251,7 @@ class JsonNumber : public Value {
|
||||
Float& GetNumber() & { return number_; }
|
||||
|
||||
bool operator==(Value const& rhs) const override;
|
||||
Value& operator=(Value const& rhs) override = delete;
|
||||
|
||||
static bool IsClassOf(Value const* value) {
|
||||
return value->Type() == ValueKind::kNumber;
|
||||
@@ -287,6 +290,7 @@ class JsonInteger : public Value {
|
||||
: Value{ValueKind::kInteger}, integer_{that.integer_} {}
|
||||
|
||||
bool operator==(Value const& rhs) const override;
|
||||
Value& operator=(Value const& rhs) override = delete;
|
||||
|
||||
Int const& GetInteger() && { return integer_; }
|
||||
Int const& GetInteger() const & { return integer_; }
|
||||
@@ -307,6 +311,7 @@ class JsonNull : public Value {
|
||||
void Save(JsonWriter* writer) const override;
|
||||
|
||||
bool operator==(Value const& rhs) const override;
|
||||
Value& operator=(Value const& rhs) override = delete;
|
||||
|
||||
static bool IsClassOf(Value const* value) {
|
||||
return value->Type() == ValueKind::kNull;
|
||||
@@ -336,6 +341,7 @@ class JsonBoolean : public Value {
|
||||
bool& GetBoolean() & { return boolean_; }
|
||||
|
||||
bool operator==(Value const& rhs) const override;
|
||||
Value& operator=(Value const& rhs) override = delete;
|
||||
|
||||
static bool IsClassOf(Value const* value) {
|
||||
return value->Type() == ValueKind::kBoolean;
|
||||
|
||||
Reference in New Issue
Block a user