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

Function TEST_F

tests/core/algorithm/flat_sparse/flat_sparse_searcher_test.cc:100–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100TEST_F(FlatSparseSearcherTest, TestGeneral) {
101 // init storage
102 Params stg_params;
103 auto storage = IndexFactory::CreateStorage("MMapFileStorage");
104 ASSERT_TRUE(storage != nullptr);
105 ASSERT_EQ(0, storage->init(stg_params));
106 ASSERT_EQ(0, storage->open(dir_ + "TestGeneral", true));
107
108
109 // init streamer
110 IndexStreamer::Pointer streamer =
111 IndexFactory::CreateStreamer("FlatSparseStreamer");
112 ASSERT_TRUE(streamer != nullptr);
113
114 IndexMeta index_meta(IndexMeta::MetaType::MT_SPARSE,
115 IndexMeta::DataType::DT_FP32);
116 index_meta.set_metric("InnerProductSparse", 0, Params());
117
118 Params params;
119 ASSERT_EQ(0, streamer->init(index_meta, params));
120 ASSERT_EQ(0, streamer->open(storage));
121
122 // generate sparse data
123 size_t sparse_dim_count = 32;
124 size_t cnt = 100U;
125 std::vector<NumericalVector<uint32_t>> sparse_indices_list;
126 std::vector<NumericalVector<float>> sparse_vec_list;
127
128 generate_sparse_data(cnt, sparse_dim_count, sparse_indices_list,
129 sparse_vec_list, true);
130
131 // test add data
132 auto ctx = streamer->create_context();
133 ASSERT_TRUE(!!ctx);
134 IndexQueryMeta qmeta(IndexMeta::DT_FP32);
135 for (size_t i = 0; i < cnt; i++) {
136 ASSERT_EQ(0, streamer->add_impl(i, sparse_dim_count,
137 sparse_indices_list[i].data(),
138 sparse_vec_list[i].data(), qmeta, ctx));
139 }
140
141 // test get data
142 uint32_t sparse_count;
143 std::string sparse_indices_buffer;
144 std::string sparse_values_buffer;
145 for (size_t i = 0; i < cnt; i++) {
146 ASSERT_EQ(
147 0, streamer->get_sparse_vector(i, &sparse_count, &sparse_indices_buffer,
148 &sparse_values_buffer));
149 ASSERT_EQ(sparse_dim_count, sparse_count);
150 const uint32_t *sparse_indices_ptr =
151 reinterpret_cast<const uint32_t *>(sparse_indices_buffer.data());
152 const float *sparse_values_ptr =
153 reinterpret_cast<const float *>(sparse_values_buffer.data());
154 for (size_t j = 0; j < sparse_count; ++j) {
155 ASSERT_EQ(sparse_indices_ptr[j], sparse_indices_list[i][j]);
156 ASSERT_FLOAT_EQ(sparse_values_ptr[j], sparse_vec_list[i][j]);
157 // std::cout << "1: " << sparse_values_ptr[j]

Callers

nothing calls this directly

Calls 15

ParamsFunction · 0.85
push_backMethod · 0.80
waitMethod · 0.80
initMethod · 0.45
openMethod · 0.45
set_metricMethod · 0.45
create_contextMethod · 0.45
add_implMethod · 0.45
dataMethod · 0.45
get_sparse_vectorMethod · 0.45
clearMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected