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

Function TEST_F

tests/core/algorithm/flat/flat_streamer_test.cc:160–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160TEST_F(FlatStreamerTest, TestAddVector) {
161 IndexStreamer::Pointer streamer =
162 IndexFactory::CreateStreamer("FlatStreamer");
163 ASSERT_TRUE(streamer != nullptr);
164
165 Params params;
166 ASSERT_EQ(0, streamer->init(*index_meta_ptr_, params));
167 auto storage = IndexFactory::CreateStorage("MMapFileStorage");
168 ASSERT_NE(nullptr, storage);
169 Params stg_params;
170 ASSERT_EQ(0, storage->init(stg_params));
171 ASSERT_EQ(0, storage->open(dir_ + "Test/AddVector", true));
172 ASSERT_EQ(0, streamer->open(storage));
173
174 auto ctx = streamer->create_context();
175 auto provider = streamer->create_provider();
176 ASSERT_TRUE(!!ctx);
177
178 IndexQueryMeta qmeta(IndexMeta::DT_FP32, dim);
179 for (size_t i = 0; i < 1000UL; i++) {
180 NumericalVector<float> vec(dim);
181 for (size_t j = 0; j < dim; ++j) {
182 vec[j] = i;
183 }
184 streamer->add_impl(i, vec.data(), qmeta, ctx);
185 const float *data = (float *)provider->get_vector(i);
186 for (size_t j = 0; j < dim; ++j) {
187 ASSERT_FLOAT_EQ(data[j], i);
188 }
189 }
190
191 std::vector<uint64_t> keys{3, 127, 999};
192 std::vector<IndexStorage::MemoryBlock> blocks;
193 ASSERT_EQ(0, provider->get_vectors(
194 keys.data(), static_cast<uint32_t>(keys.size()), blocks));
195 ASSERT_EQ(keys.size(), blocks.size());
196 for (size_t i = 0; i < keys.size(); ++i) {
197 const float *data = static_cast<const float *>(blocks[i].data());
198 ASSERT_NE(nullptr, data);
199 for (size_t j = 0; j < dim; ++j) {
200 ASSERT_FLOAT_EQ(data[j], keys[i]);
201 }
202 }
203
204 streamer->flush(0UL);
205 streamer.reset();
206}
207
208// The entity creates its own metric during open(). Its distance callbacks
209// must remain valid after open() returns, including after a storage reopen.

Callers

nothing calls this directly

Calls 15

ParamsFunction · 0.85
ToFP16Function · 0.85
fillFunction · 0.85
ConcatFunction · 0.85
IndexQueryMetaClass · 0.85
push_backMethod · 0.80
take_topk_resultMethod · 0.80
entityMethod · 0.80
search_scratchMethod · 0.80
waitMethod · 0.80
mutable_metaMethod · 0.80

Tested by

no test coverage detected