| 80 | |
| 81 | namespace { |
| 82 | void VerifyGetSetFeatureColumnSplit() { |
| 83 | xgboost::MetaInfo info; |
| 84 | info.data_split_mode = DataSplitMode::kCol; |
| 85 | auto const world_size = collective::GetWorldSize(); |
| 86 | |
| 87 | auto constexpr kCols{2}; |
| 88 | std::vector<std::string> types{u8"float", u8"c"}; |
| 89 | std::vector<char const *> c_types(kCols); |
| 90 | std::transform(types.cbegin(), types.cend(), c_types.begin(), |
| 91 | [](auto const &str) { return str.c_str(); }); |
| 92 | info.num_col_ = kCols; |
| 93 | ASSERT_THAT([&] { info.SetFeatureInfo(u8"feature_type", c_types.data(), c_types.size()); }, |
| 94 | GMockThrow("Length of feature_type must be equal to number of columns")); |
| 95 | info.num_col_ = kCols * world_size; |
| 96 | EXPECT_NO_THROW(info.SetFeatureInfo(u8"feature_type", c_types.data(), c_types.size())); |
| 97 | std::vector<std::string> expected_type_names{u8"float", u8"c", u8"float", |
| 98 | u8"c", u8"float", u8"c"}; |
| 99 | EXPECT_EQ(info.feature_type_names, expected_type_names); |
| 100 | std::vector<xgboost::FeatureType> expected_types{ |
| 101 | xgboost::FeatureType::kNumerical, xgboost::FeatureType::kCategorical, |
| 102 | xgboost::FeatureType::kNumerical, xgboost::FeatureType::kCategorical, |
| 103 | xgboost::FeatureType::kNumerical, xgboost::FeatureType::kCategorical}; |
| 104 | EXPECT_EQ(info.feature_types.HostVector(), expected_types); |
| 105 | |
| 106 | std::vector<std::string> names{u8"feature0", u8"feature1"}; |
| 107 | std::vector<char const *> c_names(kCols); |
| 108 | std::transform(names.cbegin(), names.cend(), c_names.begin(), |
| 109 | [](auto const &str) { return str.c_str(); }); |
| 110 | info.num_col_ = kCols; |
| 111 | ASSERT_THAT([&] { info.SetFeatureInfo(u8"feature_name", c_names.data(), c_names.size()); }, |
| 112 | GMockThrow("Length of feature_name must be equal to number of columns")); |
| 113 | info.num_col_ = kCols * world_size; |
| 114 | EXPECT_NO_THROW(info.SetFeatureInfo(u8"feature_name", c_names.data(), c_names.size())); |
| 115 | std::vector<std::string> expected_names{u8"0.feature0", u8"0.feature1", u8"1.feature0", |
| 116 | u8"1.feature1", u8"2.feature0", u8"2.feature1"}; |
| 117 | EXPECT_EQ(info.feature_names, expected_names); |
| 118 | } |
| 119 | } // anonymous namespace |
| 120 | |
| 121 | TEST(MetaInfo, GetSetFeatureColumnSplit) { |
nothing calls this directly
no test coverage detected