| 119 | } // namespace |
| 120 | |
| 121 | TEST_F(FlatSparseStreamerTest, Fp16QueryDoesNotReadPastBuffer) { |
| 122 | auto storage = IndexFactory::CreateStorage("MMapFileStorage"); |
| 123 | ASSERT_EQ(0, storage->init(Params{})); |
| 124 | ASSERT_EQ(0, storage->open(dir_ + "fp16_query_boundary", true)); |
| 125 | auto streamer = IndexFactory::CreateStreamer("FlatSparseStreamer"); |
| 126 | IndexMeta meta(IndexMeta::MT_SPARSE, IndexMeta::DT_FP16); |
| 127 | meta.set_metric("InnerProductSparse", 0, Params{}); |
| 128 | ASSERT_EQ(0, streamer->init(meta, Params{})); |
| 129 | ASSERT_EQ(0, streamer->open(storage)); |
| 130 | |
| 131 | const uint32_t indices[] = {128, 256, 512}; |
| 132 | const Float16 values[] = {1.0f, -1.0f, 0.5f}; |
| 133 | GuardedQueryBuffer query(sizeof(values)); |
| 134 | ASSERT_NE(nullptr, query.data()); |
| 135 | std::memcpy(query.data(), values, sizeof(values)); |
| 136 | IndexQueryMeta qmeta(IndexMeta::DT_FP16); |
| 137 | auto context = streamer->create_context(); |
| 138 | ASSERT_EQ(0, streamer->add_impl(7, 3, indices, values, qmeta, context)); |
| 139 | |
| 140 | for (bool grouped : {false, true}) { |
| 141 | for (bool candidates : {false, true}) { |
| 142 | SCOPED_TRACE(grouped); |
| 143 | SCOPED_TRACE(candidates); |
| 144 | context = streamer->create_context(); |
| 145 | context->set_topk(1); |
| 146 | if (grouped) { |
| 147 | context->set_group_params(1, 1); |
| 148 | context->set_group_by([](uint64_t) { return std::string("all"); }); |
| 149 | } |
| 150 | ASSERT_EQ(0, candidates |
| 151 | ? streamer->search_bf_by_p_keys_impl( |
| 152 | 3, indices, query.data(), {{7}}, qmeta, context) |
| 153 | : streamer->search_impl(3, indices, query.data(), qmeta, |
| 154 | context)); |
| 155 | if (grouped) ASSERT_EQ(1, context->group_result().size()); |
| 156 | const auto &results = |
| 157 | grouped ? context->group_result()[0].docs() : context->result(); |
| 158 | ASSERT_EQ(1, results.size()); |
| 159 | EXPECT_EQ(7, results[0].key()); |
| 160 | EXPECT_FLOAT_EQ(-2.25f, results[0].score()); |
| 161 | } |
| 162 | } |
| 163 | ASSERT_EQ(0, streamer->close()); |
| 164 | ASSERT_EQ(0, storage->close()); |
| 165 | } |
| 166 | |
| 167 | void FlatSparseStreamerTest::generate_sparse_data( |
| 168 | size_t cnt, uint32_t sparse_dim_count, |
nothing calls this directly
no test coverage detected