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

Function TEST_F

tests/core/algorithm/flat_sparse/flat_sparse_streamer_test.cc:99–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected