MCPcopy Create free account
hub / github.com/dmlc/xgboost / TestOrdinalEncoderMixed

Function TestOrdinalEncoderMixed

tests/cpp/encoder/test_ordinal.h:122–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120
121template <typename Encoder, typename DfTest>
122void TestOrdinalEncoderMixed() {
123 Encoder encoder;
124 auto sol = std::vector<std::int32_t>{0, 3, 1};
125
126 {
127 auto df =
128 DfTest::Make(DfTest::MakeInts(2, 1, 3, 0), DfTest::MakeStrs("cbd", "bbd", "dbd", "ab"));
129 auto orig_dict = df.View();
130
131 auto new_df = DfTest::Make(DfTest::MakeInts(2, 0, 1), DfTest::MakeStrs("cbd", "ab", "bbd"));
132 auto new_dict = new_df.View();
133
134 encoder.Recode(orig_dict, new_dict, new_df.MappingView());
135 ASSERT_EQ(new_df.Mapping().size(), 6);
136 for (std::size_t i = 0; i < new_df.Mapping().size(); ++i) {
137 ASSERT_EQ(new_df.Mapping()[i], sol[i % sol.size()]);
138 }
139 }
140 {
141 auto df =
142 DfTest::Make(DfTest::MakeStrs("cbd", "bbd", "dbd", "ab"), DfTest::MakeInts(2, 1, 3, 0));
143 auto orig_dict = df.View();
144
145 auto new_df = DfTest::Make(DfTest::MakeStrs("cbd", "ab", "bbd"), DfTest::MakeInts(2, 0, 1));
146 auto new_dict = new_df.View();
147
148 encoder.Recode(orig_dict, new_dict, new_df.MappingView());
149 ASSERT_EQ(new_df.Mapping().size(), 6);
150 for (std::size_t i = 0; i < new_df.Mapping().size(); ++i) {
151 ASSERT_EQ(new_df.Mapping()[i], sol[i % sol.size()]);
152 }
153 }
154 {
155 auto df =
156 DfTest::Make(DfTest::MakeStrs("cbd", "bbd", "dbd", "ab"), DfTest::MakeInts(2, 1, 3, 0),
157 DfTest::MakeStrs("cbd", "bbd", "dbd", "ab"));
158 auto orig_dict = df.View();
159
160 auto new_df = DfTest::Make(DfTest::MakeStrs("cbd", "ab", "bbd"), DfTest::MakeInts(2, 0),
161 DfTest::MakeStrs("cbd", "ab", "bbd"));
162 auto new_dict = new_df.View();
163
164 encoder.Recode(orig_dict, new_dict, new_df.MappingView());
165 ASSERT_EQ(new_df.Mapping().size(), 8);
166 for (std::size_t i = 0; i < 3; ++i) {
167 ASSERT_EQ(new_df.Mapping()[i], sol[i]);
168 }
169 for (std::size_t i = 3, k = 0; i < 5; ++i, ++k) {
170 ASSERT_EQ(new_df.Mapping()[i], sol[k]);
171 }
172 for (std::size_t i = 5, k = 0; i < 8; ++i, ++k) {
173 ASSERT_EQ(new_df.Mapping()[i], sol[k]);
174 }
175 }
176}
177
178template <typename Encoder, typename DfTest>
179void TestOrdinalEncoderEmpty() {

Callers

nothing calls this directly

Calls 4

RecodeMethod · 0.80
MappingViewMethod · 0.80
ViewMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected