/root/doris/contrib/faiss/faiss/impl/Quantizer.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | | * |
4 | | * This source code is licensed under the MIT license found in the |
5 | | * LICENSE file in the root directory of this source tree. |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <stdint.h> |
11 | | |
12 | | namespace faiss { |
13 | | |
14 | | /** General interface for quantizer objects */ |
15 | | struct Quantizer { |
16 | | size_t d; ///< size of the input vectors |
17 | | size_t code_size; ///< bytes per indexed vector |
18 | | |
19 | | explicit Quantizer(size_t d = 0, size_t code_size = 0) |
20 | 0 | : d(d), code_size(code_size) {} |
21 | | |
22 | | /** Train the quantizer |
23 | | * |
24 | | * @param x training vectors, size n * d |
25 | | */ |
26 | | virtual void train(size_t n, const float* x) = 0; |
27 | | |
28 | | /** Quantize a set of vectors |
29 | | * |
30 | | * @param x input vectors, size n * d |
31 | | * @param codes output codes, size n * code_size |
32 | | */ |
33 | | virtual void compute_codes(const float* x, uint8_t* codes, size_t n) |
34 | | const = 0; |
35 | | |
36 | | /** Decode a set of vectors |
37 | | * |
38 | | * @param codes input codes, size n * code_size |
39 | | * @param x output vectors, size n * d |
40 | | */ |
41 | | virtual void decode(const uint8_t* code, float* x, size_t n) const = 0; |
42 | | |
43 | 0 | virtual ~Quantizer() {} |
44 | | }; |
45 | | |
46 | | } // namespace faiss |