Rename and extract Context. (#8528)

* Rename `GenericParameter` to `Context`.
* Rename header file to reflect the change.
* Rename all references.
This commit is contained in:
Jiaming Yuan
2022-12-07 04:58:54 +08:00
committed by GitHub
parent 05fc6f3ca9
commit 3e26107a9c
105 changed files with 548 additions and 574 deletions

View File

@@ -5,9 +5,9 @@
#if !defined(__CUDACC__)
TEST(Metric, AMS) {
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
EXPECT_ANY_THROW(xgboost::Metric::Create("ams", &tparam));
xgboost::Metric * metric = xgboost::Metric::Create("ams@0.5f", &tparam);
auto ctx = xgboost::CreateEmptyGenericParam(GPUIDX);
EXPECT_ANY_THROW(xgboost::Metric::Create("ams", &ctx));
xgboost::Metric* metric = xgboost::Metric::Create("ams@0.5f", &ctx);
ASSERT_STREQ(metric->Name(), "ams@0.5");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 0.311f, 0.001f);
EXPECT_NEAR(GetMetricEval(metric,
@@ -16,7 +16,7 @@ TEST(Metric, AMS) {
0.29710f, 0.001f);
delete metric;
metric = xgboost::Metric::Create("ams@0", &tparam);
metric = xgboost::Metric::Create("ams@0", &ctx);
ASSERT_STREQ(metric->Name(), "ams@0");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 0.311f, 0.001f);
@@ -28,8 +28,8 @@ TEST(Metric, DeclareUnifiedTest(Precision)) {
// When the limit for precision is not given, it takes the limit at
// std::numeric_limits<unsigned>::max(); hence all values are very small
// NOTE(AbdealiJK): Maybe this should be fixed to be num_row by default.
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("pre", &tparam);
auto ctx = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("pre", &ctx);
ASSERT_STREQ(metric->Name(), "pre");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 0, 1e-7);
EXPECT_NEAR(GetMetricEval(metric,
@@ -38,7 +38,7 @@ TEST(Metric, DeclareUnifiedTest(Precision)) {
0, 1e-7);
delete metric;
metric = xgboost::Metric::Create("pre@2", &tparam);
metric = xgboost::Metric::Create("pre@2", &ctx);
ASSERT_STREQ(metric->Name(), "pre@2");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 0.5f, 1e-7);
EXPECT_NEAR(GetMetricEval(metric,
@@ -52,8 +52,8 @@ TEST(Metric, DeclareUnifiedTest(Precision)) {
}
TEST(Metric, DeclareUnifiedTest(NDCG)) {
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("ndcg", &tparam);
auto ctx = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("ndcg", &ctx);
ASSERT_STREQ(metric->Name(), "ndcg");
EXPECT_ANY_THROW(GetMetricEval(metric, {0, 1}, {}));
EXPECT_NEAR(GetMetricEval(metric,
@@ -66,7 +66,7 @@ TEST(Metric, DeclareUnifiedTest(NDCG)) {
0.6509f, 0.001f);
delete metric;
metric = xgboost::Metric::Create("ndcg@2", &tparam);
metric = xgboost::Metric::Create("ndcg@2", &ctx);
ASSERT_STREQ(metric->Name(), "ndcg@2");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 1, 1e-10);
EXPECT_NEAR(GetMetricEval(metric,
@@ -75,7 +75,7 @@ TEST(Metric, DeclareUnifiedTest(NDCG)) {
0.3868f, 0.001f);
delete metric;
metric = xgboost::Metric::Create("ndcg@-", &tparam);
metric = xgboost::Metric::Create("ndcg@-", &ctx);
ASSERT_STREQ(metric->Name(), "ndcg-");
EXPECT_NEAR(GetMetricEval(metric,
xgboost::HostDeviceVector<xgboost::bst_float>{},
@@ -86,7 +86,7 @@ TEST(Metric, DeclareUnifiedTest(NDCG)) {
{ 0, 0, 1, 1}),
0.6509f, 0.001f);
delete metric;
metric = xgboost::Metric::Create("ndcg-", &tparam);
metric = xgboost::Metric::Create("ndcg-", &ctx);
ASSERT_STREQ(metric->Name(), "ndcg-");
EXPECT_NEAR(GetMetricEval(metric,
xgboost::HostDeviceVector<xgboost::bst_float>{},
@@ -98,7 +98,7 @@ TEST(Metric, DeclareUnifiedTest(NDCG)) {
0.6509f, 0.001f);
delete metric;
metric = xgboost::Metric::Create("ndcg@2-", &tparam);
metric = xgboost::Metric::Create("ndcg@2-", &ctx);
ASSERT_STREQ(metric->Name(), "ndcg@2-");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 1, 1e-10);
EXPECT_NEAR(GetMetricEval(metric,
@@ -110,8 +110,8 @@ TEST(Metric, DeclareUnifiedTest(NDCG)) {
}
TEST(Metric, DeclareUnifiedTest(MAP)) {
auto tparam = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("map", &tparam);
auto ctx = xgboost::CreateEmptyGenericParam(GPUIDX);
xgboost::Metric * metric = xgboost::Metric::Create("map", &ctx);
ASSERT_STREQ(metric->Name(), "map");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 1, 1e-10);
EXPECT_NEAR(GetMetricEval(metric,
@@ -131,21 +131,21 @@ TEST(Metric, DeclareUnifiedTest(MAP)) {
0.8611f, 0.001f);
delete metric;
metric = xgboost::Metric::Create("map@-", &tparam);
metric = xgboost::Metric::Create("map@-", &ctx);
ASSERT_STREQ(metric->Name(), "map-");
EXPECT_NEAR(GetMetricEval(metric,
xgboost::HostDeviceVector<xgboost::bst_float>{},
{}), 0, 1e-10);
delete metric;
metric = xgboost::Metric::Create("map-", &tparam);
metric = xgboost::Metric::Create("map-", &ctx);
ASSERT_STREQ(metric->Name(), "map-");
EXPECT_NEAR(GetMetricEval(metric,
xgboost::HostDeviceVector<xgboost::bst_float>{},
{}), 0, 1e-10);
delete metric;
metric = xgboost::Metric::Create("map@2", &tparam);
metric = xgboost::Metric::Create("map@2", &ctx);
ASSERT_STREQ(metric->Name(), "map@2");
EXPECT_NEAR(GetMetricEval(metric, {0, 1}, {0, 1}), 1, 1e-10);
EXPECT_NEAR(GetMetricEval(metric,