MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / TEST

Function TEST

tests/batching_test.cc:6–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "test_utils.h"
5
6TEST(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
40TEST(BatchingTest, BatchReaderGetNext_Examples) {
41 const std::vector<std::vector<std::string>> examples = {

Callers

nothing calls this directly

Calls 6

rebatch_inputFunction · 0.85
load_examplesFunction · 0.85
index_vectorFunction · 0.85
get_streamMethod · 0.80
get_nextMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected