| 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 |
// -*- c -*- |
| 9 |
|
| 10 |
#ifndef FAISS_DISTANCES_C_H |
| 11 |
#define FAISS_DISTANCES_C_H |
| 12 |
|
| 13 |
#include <stdint.h> |
| 14 |
#include <stdlib.h> |
| 15 |
|
| 16 |
#ifdef __cplusplus |
| 17 |
extern "C" { |
| 18 |
#endif |
| 19 |
|
| 20 |
/********************************************************* |
| 21 |
* Optimized distance/norm/inner prod computations |
| 22 |
*********************************************************/ |
| 23 |
|
| 24 |
/// Compute pairwise distances between sets of vectors |
| 25 |
void faiss_pairwise_L2sqr( |
| 26 |
int64_t d, |
| 27 |
int64_t nq, |
| 28 |
const float* xq, |
| 29 |
int64_t nb, |
| 30 |
const float* xb, |
| 31 |
float* dis, |
| 32 |
int64_t ldq, |
| 33 |
int64_t ldb, |
| 34 |
int64_t ldd); |
| 35 |
|
| 36 |
/// Compute pairwise distances between sets of vectors |
| 37 |
/// arguments from "faiss_pairwise_L2sqr" |
| 38 |
/// ldq equal -1 by default |
| 39 |
/// ldb equal -1 by default |
| 40 |
/// ldd equal -1 by default |
| 41 |
void faiss_pairwise_L2sqr_with_defaults( |
| 42 |
int64_t d, |
| 43 |
int64_t nq, |
| 44 |
const float* xq, |
| 45 |
int64_t nb, |
| 46 |
const float* xb, |
| 47 |
float* dis); |
| 48 |
|
| 49 |
/// compute the inner product between nx vectors x and one y |
| 50 |
void faiss_fvec_inner_products_ny( |
| 51 |
float* ip, /* output inner product */ |
| 52 |
const float* x, |
| 53 |
const float* y, |
| 54 |
size_t d, |
| 55 |
size_t ny); |
| 56 |
|
| 57 |
/// compute ny square L2 distance between x and a set of contiguous y vectors |
| 58 |
void faiss_fvec_L2sqr_ny( |
| 59 |
float* dis, |
| 60 |
const float* x, |
| 61 |
const float* y, |
| 62 |
size_t d, |
| 63 |
size_t ny); |
| 64 |
|
| 65 |
/// squared norm of a vector |
| 66 |
float faiss_fvec_norm_L2sqr(const float* x, size_t d); |
| 67 |
|
| 68 |
/// compute the L2 norms for a set of vectors |
| 69 |
void faiss_fvec_norms_L2(float* norms, const float* x, size_t d, size_t nx); |
| 70 |
|
| 71 |
/// same as fvec_norms_L2, but computes squared norms |
| 72 |
void faiss_fvec_norms_L2sqr(float* norms, const float* x, size_t d, size_t nx); |
| 73 |
|
| 74 |
/// L2-renormalize a set of vector. Nothing done if the vector is 0-normed |
| 75 |
void faiss_fvec_renorm_L2(size_t d, size_t nx, float* x); |
| 76 |
|
| 77 |
/// Setter of threshold value on nx above which we switch to BLAS to compute |
| 78 |
/// distances |
| 79 |
void faiss_set_distance_compute_blas_threshold(int value); |
| 80 |
|
| 81 |
/// Getter of threshold value on nx above which we switch to BLAS to compute |
| 82 |
/// distances |
| 83 |
int faiss_get_distance_compute_blas_threshold(); |
| 84 |
|
| 85 |
/// Setter of block sizes value for BLAS distance computations |
| 86 |
void faiss_set_distance_compute_blas_query_bs(int value); |
| 87 |
|
| 88 |
/// Getter of block sizes value for BLAS distance computations |
| 89 |
int faiss_get_distance_compute_blas_query_bs(); |
| 90 |
|
| 91 |
/// Setter of block sizes value for BLAS distance computations |
| 92 |
void faiss_set_distance_compute_blas_database_bs(int value); |
| 93 |
|
| 94 |
/// Getter of block sizes value for BLAS distance computations |
| 95 |
int faiss_get_distance_compute_blas_database_bs(); |
| 96 |
|
| 97 |
/// Setter of number of results we switch to a reservoir to collect results |
| 98 |
/// rather than a heap |
| 99 |
void faiss_set_distance_compute_min_k_reservoir(int value); |
| 100 |
|
| 101 |
/// Getter of number of results we switch to a reservoir to collect results |
| 102 |
/// rather than a heap |
| 103 |
int faiss_get_distance_compute_min_k_reservoir(); |
| 104 |
|
| 105 |
#ifdef __cplusplus |
| 106 |
} |
| 107 |
#endif |
| 108 |
|
| 109 |
#endif |