| 4 | #include "test_utils.h" |
| 5 | |
| 6 | TEST(BatchingTest, RebatchInput) { |
| 7 | const std::vector<std::vector<std::string>> source = { |
| 8 | {"a", "b"}, |
| 9 | {"a", "b", "c"}, |
| 10 | {"a"}, |
| 11 | {}, |
| 12 | {"a", "b", "c", "d"}, |
| 13 | {"a", "b", "c", "d", "e"} |
| 14 | }; |
| 15 | const std::vector<std::vector<std::string>> target = { |
| 16 | {"1"}, |
| 17 | {"2"}, |
| 18 | {"3"}, |
| 19 | {"4"}, |
| 20 | {"5"}, |
| 21 | {"6"} |
| 22 | }; |
| 23 | const std::vector<std::vector<size_t>> expected_batches = { |
| 24 | {5, 4}, |
| 25 | {1, 0}, |
| 26 | {2, 3} |
| 27 | }; |
| 28 | |
| 29 | const auto batches = rebatch_input(load_examples({source, target}), 2, BatchType::Examples); |
| 30 | ASSERT_EQ(batches.size(), expected_batches.size()); |
| 31 | |
| 32 | for (size_t i = 0; i < batches.size(); ++i) { |
| 33 | const auto& batch = batches[i]; |
| 34 | EXPECT_EQ(batch.get_stream(0), index_vector(source, expected_batches[i])); |
| 35 | EXPECT_EQ(batch.get_stream(1), index_vector(target, expected_batches[i])); |
| 36 | EXPECT_EQ(batch.example_index, expected_batches[i]); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | TEST(BatchingTest, BatchReaderGetNext_Examples) { |
| 41 | const std::vector<std::vector<std::string>> examples = { |
nothing calls this directly
no test coverage detected