Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 64bit seed. #5643

Merged
merged 1 commit into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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