Skip to content

Commit

Permalink
Support 64bit seed. (#5643)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis authored May 7, 2020
1 parent eaf2a00 commit 21ed1f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/xgboost/generic_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct GenericParameter : public XGBoostParameter<GenericParameter> {

public:
// stored random seed
int seed;
int64_t seed;
// whether seed the PRNG each iteration
bool seed_per_iteration;
// number of threads to use if OpenMP is enabled
Expand Down
22 changes: 22 additions & 0 deletions tests/cpp/test_learner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,26 @@ TEST(Learner, GPUConfiguration) {
}
}
#endif // defined(XGBOOST_USE_CUDA)

TEST(Learner, Seed) {
auto m = RandomDataGenerator{10, 10, 0}.GenerateDMatrix();
std::unique_ptr<Learner> learner {
Learner::Create({m})
};
auto seed = std::numeric_limits<int64_t>::max();
learner->SetParam("seed", std::to_string(seed));
learner->Configure();
Json config { Object() };
learner->SaveConfig(&config);
ASSERT_EQ(std::to_string(seed),
get<String>(config["learner"]["generic_param"]["seed"]));

seed = std::numeric_limits<int64_t>::min();
learner->SetParam("seed", std::to_string(seed));
learner->Configure();
learner->SaveConfig(&config);
ASSERT_EQ(std::to_string(seed),
get<String>(config["learner"]["generic_param"]["seed"]));
}

} // namespace xgboost

0 comments on commit 21ed1f0

Please sign in to comment.