Coverage Report

Created: 2026-03-26 18:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
contrib/faiss/faiss/impl/code_distance/code_distance-generic.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 <cstddef>
11
#include <cstdint>
12
13
namespace faiss {
14
15
/// Returns the distance to a single code.
16
template <typename PQDecoderT>
17
inline float distance_single_code_generic(
18
        // number of subquantizers
19
        const size_t M,
20
        // number of bits per quantization index
21
        const size_t nbits,
22
        // precomputed distances, layout (M, ksub)
23
        const float* sim_table,
24
        // the code
25
0
        const uint8_t* code) {
26
0
    PQDecoderT decoder(code, nbits);
27
0
    const size_t ksub = 1 << nbits;
28
29
0
    const float* tab = sim_table;
30
0
    float result = 0;
31
32
0
    for (size_t m = 0; m < M; m++) {
33
0
        result += tab[decoder.decode()];
34
0
        tab += ksub;
35
0
    }
36
37
0
    return result;
38
0
}
Unexecuted instantiation: _ZN5faiss28distance_single_code_genericINS_11PQDecoder16EEEfmmPKfPKh
Unexecuted instantiation: _ZN5faiss28distance_single_code_genericINS_16PQDecoderGenericEEEfmmPKfPKh
39
40
/// Combines 4 operations of distance_single_code()
41
/// General-purpose version.
42
template <typename PQDecoderT>
43
inline void distance_four_codes_generic(
44
        // number of subquantizers
45
        const size_t M,
46
        // number of bits per quantization index
47
        const size_t nbits,
48
        // precomputed distances, layout (M, ksub)
49
        const float* sim_table,
50
        // codes
51
        const uint8_t* __restrict code0,
52
        const uint8_t* __restrict code1,
53
        const uint8_t* __restrict code2,
54
        const uint8_t* __restrict code3,
55
        // computed distances
56
        float& result0,
57
        float& result1,
58
        float& result2,
59
0
        float& result3) {
60
0
    PQDecoderT decoder0(code0, nbits);
61
0
    PQDecoderT decoder1(code1, nbits);
62
0
    PQDecoderT decoder2(code2, nbits);
63
0
    PQDecoderT decoder3(code3, nbits);
64
0
    const size_t ksub = 1 << nbits;
65
66
0
    const float* tab = sim_table;
67
0
    result0 = 0;
68
0
    result1 = 0;
69
0
    result2 = 0;
70
0
    result3 = 0;
71
72
0
    for (size_t m = 0; m < M; m++) {
73
0
        result0 += tab[decoder0.decode()];
74
0
        result1 += tab[decoder1.decode()];
75
0
        result2 += tab[decoder2.decode()];
76
0
        result3 += tab[decoder3.decode()];
77
0
        tab += ksub;
78
0
    }
79
0
}
Unexecuted instantiation: _ZN5faiss27distance_four_codes_genericINS_11PQDecoder16EEEvmmPKfPKhS5_S5_S5_RfS6_S6_S6_
Unexecuted instantiation: _ZN5faiss27distance_four_codes_genericINS_16PQDecoderGenericEEEvmmPKfPKhS5_S5_S5_RfS6_S6_S6_
80
81
} // namespace faiss