MCPcopy Create free account
hub / github.com/alibaba/zvec / TEST_F

Function TEST_F

tests/core/algorithm/flat/flat_streamer_buffer_time_test.cc:48–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48TEST_F(FlatStreamerTest, TestLinearSearchMMap) {
49 IndexStreamer::Pointer write_streamer =
50 IndexFactory::CreateStreamer("FlatStreamer");
51 ASSERT_TRUE(write_streamer != nullptr);
52
53 Params params;
54 ASSERT_EQ(0, write_streamer->init(*index_meta_ptr_, params));
55 auto storage = IndexFactory::CreateStorage("MMapFileStorage");
56 ASSERT_NE(nullptr, storage);
57 Params stg_params;
58 ASSERT_EQ(0, storage->init(stg_params));
59 ASSERT_EQ(0, storage->open(dir_ + "/Test/LinearSearchMMap", true));
60 ASSERT_EQ(0, write_streamer->open(storage));
61
62 auto ctx = write_streamer->create_context();
63 ASSERT_TRUE(!!ctx);
64
65 size_t data_cnt = 300000UL, cnt = 500UL;
66 IndexQueryMeta qmeta(IndexMeta::DT_FP32, dim);
67 for (size_t i = 0; i < data_cnt; i++) {
68 NumericalVector<float> vec(dim);
69 for (size_t j = 0; j < dim; ++j) {
70 vec[j] = i;
71 }
72 write_streamer->add_impl(i, vec.data(), qmeta, ctx);
73 }
74 write_streamer->flush(0UL);
75 write_streamer->close();
76 write_streamer.reset();
77
78 IndexStreamer::Pointer read_streamer =
79 IndexFactory::CreateStreamer("FlatStreamer");
80 ASSERT_EQ(0, read_streamer->init(*index_meta_ptr_, params));
81 auto read_storage = IndexFactory::CreateStorage("MMapFileStorage");
82 ASSERT_NE(nullptr, read_storage);
83 ASSERT_EQ(0, read_storage->init(stg_params));
84 ASSERT_EQ(0, read_storage->open(dir_ + "/Test/LinearSearchMMap", false));
85 ASSERT_EQ(0, read_streamer->open(read_storage));
86 size_t topk = 30;
87 ElapsedTime elapsed_time;
88 for (size_t i = 0; i < cnt; i += 1) {
89 NumericalVector<float> vec(dim);
90 for (size_t j = 0; j < dim; ++j) {
91 vec[j] = i;
92 }
93 ctx->set_topk(topk);
94 ASSERT_EQ(0, read_streamer->search_impl(vec.data(), qmeta, ctx));
95 // auto &result1 = ctx->result();
96 // ASSERT_EQ(topk, result1.size());
97 // ASSERT_EQ(i, result1[0].key());
98
99 // for (size_t j = 0; j < dim; ++j) {
100 // vec[j] = i + 0.1f;
101 // }
102 // ctx->set_topk(topk);
103 // ASSERT_EQ(0, read_streamer->search_impl(vec.data(), qmeta, ctx));
104 // auto &result2 = ctx->result();
105 // ASSERT_EQ(topk, result2.size());

Callers

nothing calls this directly

Calls 10

initMethod · 0.45
openMethod · 0.45
create_contextMethod · 0.45
add_implMethod · 0.45
dataMethod · 0.45
flushMethod · 0.45
closeMethod · 0.45
resetMethod · 0.45
set_topkMethod · 0.45
search_implMethod · 0.45

Tested by

no test coverage detected