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

Function TEST_F

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

IndexMetaClass · 0.85
ParamsClass · 0.85
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
create_providerMethod · 0.45
set_topkMethod · 0.45

Tested by

no test coverage detected