/root/doris/contrib/faiss/faiss/impl/CodePacker.cpp
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 | | #include <faiss/impl/CodePacker.h> |
9 | | |
10 | | #include <cassert> |
11 | | #include <cstring> |
12 | | |
13 | | namespace faiss { |
14 | | |
15 | | /********************************************* |
16 | | * CodePacker |
17 | | * default of pack_all / unpack_all loops over the _1 versions |
18 | | */ |
19 | | |
20 | 0 | void CodePacker::pack_all(const uint8_t* flat_codes, uint8_t* block) const { |
21 | 0 | for (size_t i = 0; i < nvec; i++) { |
22 | 0 | pack_1(flat_codes + code_size * i, i, block); |
23 | 0 | } |
24 | 0 | } |
25 | | |
26 | 0 | void CodePacker::unpack_all(const uint8_t* block, uint8_t* flat_codes) const { |
27 | 0 | for (size_t i = 0; i < nvec; i++) { |
28 | 0 | unpack_1(block, i, flat_codes + code_size * i); |
29 | 0 | } |
30 | 0 | } |
31 | | |
32 | | /********************************************* |
33 | | * CodePackerFlat |
34 | | */ |
35 | | |
36 | 0 | CodePackerFlat::CodePackerFlat(size_t code_size) { |
37 | 0 | this->code_size = code_size; |
38 | 0 | nvec = 1; |
39 | 0 | block_size = code_size; |
40 | 0 | } |
41 | | |
42 | 0 | void CodePackerFlat::pack_all(const uint8_t* flat_codes, uint8_t* block) const { |
43 | 0 | memcpy(block, flat_codes, code_size); |
44 | 0 | } |
45 | | |
46 | | void CodePackerFlat::unpack_all(const uint8_t* block, uint8_t* flat_codes) |
47 | 0 | const { |
48 | 0 | memcpy(flat_codes, block, code_size); |
49 | 0 | } |
50 | | |
51 | | void CodePackerFlat::pack_1( |
52 | | const uint8_t* flat_code, |
53 | | size_t offset, |
54 | 0 | uint8_t* block) const { |
55 | 0 | assert(offset == 0); |
56 | 0 | pack_all(flat_code, block); |
57 | 0 | } |
58 | | |
59 | | void CodePackerFlat::unpack_1( |
60 | | const uint8_t* block, |
61 | | size_t offset, |
62 | 0 | uint8_t* flat_code) const { |
63 | 0 | assert(offset == 0); |
64 | 0 | unpack_all(block, flat_code); |
65 | 0 | } |
66 | | |
67 | | } // namespace faiss |