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

Function TEST_F

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

ParamsClass · 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