1
1
/* *
2
- * Copyright 2019-2024 , XGBoost Contributors
2
+ * Copyright 2019-2025 , XGBoost Contributors
3
3
*/
4
4
#include < thrust/functional.h>
5
5
#include < thrust/random.h>
21
21
22
22
namespace xgboost ::tree {
23
23
/* ! \brief A functor that returns random weights. */
24
- class RandomWeight : public thrust ::unary_function< size_t , float > {
24
+ class RandomWeight {
25
25
public:
26
26
explicit RandomWeight (size_t seed) : seed_(seed) {}
27
27
@@ -37,7 +37,7 @@ class RandomWeight : public thrust::unary_function<size_t, float> {
37
37
};
38
38
39
39
/* ! \brief A functor that performs a Bernoulli trial to discard a gradient pair. */
40
- class BernoulliTrial : public thrust ::unary_function< size_t , bool > {
40
+ class BernoulliTrial {
41
41
public:
42
42
BernoulliTrial (size_t seed, float p) : rnd_(seed), p_(p) {}
43
43
@@ -51,14 +51,14 @@ class BernoulliTrial : public thrust::unary_function<size_t, bool> {
51
51
};
52
52
53
53
/* ! \brief A functor that returns true if the gradient pair is non-zero. */
54
- struct IsNonZero : public thrust ::unary_function<GradientPair, bool > {
54
+ struct IsNonZero {
55
55
XGBOOST_DEVICE bool operator ()(const GradientPair& gpair) const {
56
56
return gpair.GetGrad () != 0 || gpair.GetHess () != 0 ;
57
57
}
58
58
};
59
59
60
60
/* ! \brief A functor that clears the row indexes with empty gradient. */
61
- struct ClearEmptyRows : public thrust ::binary_function<GradientPair, bst_idx_t , bst_idx_t > {
61
+ struct ClearEmptyRows {
62
62
static constexpr bst_idx_t InvalidRow () { return std::numeric_limits<std::size_t >::max (); }
63
63
64
64
XGBOOST_DEVICE size_t operator ()(const GradientPair& gpair, size_t row_index) const {
@@ -77,7 +77,7 @@ struct ClearEmptyRows : public thrust::binary_function<GradientPair, bst_idx_t,
77
77
* \see Ibragimov, B., & Gusev, G. (2019). Minimal Variance Sampling in Stochastic Gradient
78
78
* Boosting. In Advances in Neural Information Processing Systems (pp. 15061-15071).
79
79
*/
80
- class CombineGradientPair : public thrust ::unary_function<GradientPair, float > {
80
+ class CombineGradientPair {
81
81
public:
82
82
XGBOOST_DEVICE float operator ()(const GradientPair& gpair) const {
83
83
return sqrtf (powf (gpair.GetGrad (), 2 ) + kLambda * powf (gpair.GetHess (), 2 ));
@@ -90,7 +90,7 @@ class CombineGradientPair : public thrust::unary_function<GradientPair, float> {
90
90
/* ! \brief A functor that calculates the difference between the sample rate and the desired sample
91
91
* rows, given a cumulative gradient sum.
92
92
*/
93
- class SampleRateDelta : public thrust ::binary_function< float , size_t , float > {
93
+ class SampleRateDelta {
94
94
public:
95
95
SampleRateDelta (common::Span<float > threshold, size_t n_rows, size_t sample_rows)
96
96
: threshold_(threshold), n_rows_(n_rows), sample_rows_(sample_rows) {}
@@ -114,7 +114,7 @@ class SampleRateDelta : public thrust::binary_function<float, size_t, float> {
114
114
};
115
115
116
116
/* ! \brief A functor that performs Poisson sampling, and scales gradient pairs by 1/p_i. */
117
- class PoissonSampling : public thrust ::binary_function<GradientPair, size_t , GradientPair> {
117
+ class PoissonSampling {
118
118
public:
119
119
PoissonSampling (common::Span<float > threshold, size_t threshold_index, RandomWeight rnd)
120
120
: threshold_(threshold), threshold_index_(threshold_index), rnd_(rnd) {}
0 commit comments