Initial commit
This commit is contained in:
101
packages/leann-backend-hnsw/third_party/faiss/c_api/utils/distances_c.cpp
vendored
Normal file
101
packages/leann-backend-hnsw/third_party/faiss/c_api/utils/distances_c.cpp
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// -*- c++ -*-
|
||||
|
||||
#include "distances_c.h"
|
||||
#include <faiss/utils/distances.h>
|
||||
#include <cstdio>
|
||||
|
||||
void faiss_pairwise_L2sqr(
|
||||
int64_t d,
|
||||
int64_t nq,
|
||||
const float* xq,
|
||||
int64_t nb,
|
||||
const float* xb,
|
||||
float* dis,
|
||||
int64_t ldq,
|
||||
int64_t ldb,
|
||||
int64_t ldd) {
|
||||
faiss::pairwise_L2sqr(d, nq, xq, nb, xb, dis, ldq, ldb, ldd);
|
||||
}
|
||||
|
||||
void faiss_pairwise_L2sqr_with_defaults(
|
||||
int64_t d,
|
||||
int64_t nq,
|
||||
const float* xq,
|
||||
int64_t nb,
|
||||
const float* xb,
|
||||
float* dis) {
|
||||
faiss::pairwise_L2sqr(d, nq, xq, nb, xb, dis);
|
||||
}
|
||||
|
||||
void faiss_fvec_inner_products_ny(
|
||||
float* ip,
|
||||
const float* x,
|
||||
const float* y,
|
||||
size_t d,
|
||||
size_t ny) {
|
||||
faiss::fvec_inner_products_ny(ip, x, y, d, ny);
|
||||
}
|
||||
|
||||
void faiss_fvec_L2sqr_ny(
|
||||
float* dis,
|
||||
const float* x,
|
||||
const float* y,
|
||||
size_t d,
|
||||
size_t ny) {
|
||||
faiss::fvec_L2sqr_ny(dis, x, y, d, ny);
|
||||
}
|
||||
|
||||
float faiss_fvec_norm_L2sqr(const float* x, size_t d) {
|
||||
return faiss::fvec_norm_L2sqr(x, d);
|
||||
}
|
||||
|
||||
void faiss_fvec_norms_L2(float* norms, const float* x, size_t d, size_t nx) {
|
||||
faiss::fvec_norms_L2(norms, x, d, nx);
|
||||
}
|
||||
|
||||
void faiss_fvec_norms_L2sqr(float* norms, const float* x, size_t d, size_t nx) {
|
||||
faiss::fvec_norms_L2sqr(norms, x, d, nx);
|
||||
}
|
||||
|
||||
void faiss_fvec_renorm_L2(size_t d, size_t nx, float* x) {
|
||||
faiss::fvec_renorm_L2(d, nx, x);
|
||||
}
|
||||
|
||||
void faiss_set_distance_compute_blas_threshold(int value) {
|
||||
faiss::distance_compute_blas_threshold = value;
|
||||
}
|
||||
|
||||
int faiss_get_distance_compute_blas_threshold() {
|
||||
return faiss::distance_compute_blas_threshold;
|
||||
}
|
||||
|
||||
void faiss_set_distance_compute_blas_query_bs(int value) {
|
||||
faiss::distance_compute_blas_query_bs = value;
|
||||
}
|
||||
|
||||
int faiss_get_distance_compute_blas_query_bs() {
|
||||
return faiss::distance_compute_blas_query_bs;
|
||||
}
|
||||
|
||||
void faiss_set_distance_compute_blas_database_bs(int value) {
|
||||
faiss::distance_compute_blas_database_bs = value;
|
||||
}
|
||||
|
||||
int faiss_get_distance_compute_blas_database_bs() {
|
||||
return faiss::distance_compute_blas_database_bs;
|
||||
}
|
||||
|
||||
void faiss_set_distance_compute_min_k_reservoir(int value) {
|
||||
faiss::distance_compute_min_k_reservoir = value;
|
||||
}
|
||||
|
||||
int faiss_get_distance_compute_min_k_reservoir() {
|
||||
return faiss::distance_compute_min_k_reservoir;
|
||||
}
|
||||
109
packages/leann-backend-hnsw/third_party/faiss/c_api/utils/distances_c.h
vendored
Normal file
109
packages/leann-backend-hnsw/third_party/faiss/c_api/utils/distances_c.h
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// -*- c -*-
|
||||
|
||||
#ifndef FAISS_DISTANCES_C_H
|
||||
#define FAISS_DISTANCES_C_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************************************************
|
||||
* Optimized distance/norm/inner prod computations
|
||||
*********************************************************/
|
||||
|
||||
/// Compute pairwise distances between sets of vectors
|
||||
void faiss_pairwise_L2sqr(
|
||||
int64_t d,
|
||||
int64_t nq,
|
||||
const float* xq,
|
||||
int64_t nb,
|
||||
const float* xb,
|
||||
float* dis,
|
||||
int64_t ldq,
|
||||
int64_t ldb,
|
||||
int64_t ldd);
|
||||
|
||||
/// Compute pairwise distances between sets of vectors
|
||||
/// arguments from "faiss_pairwise_L2sqr"
|
||||
/// ldq equal -1 by default
|
||||
/// ldb equal -1 by default
|
||||
/// ldd equal -1 by default
|
||||
void faiss_pairwise_L2sqr_with_defaults(
|
||||
int64_t d,
|
||||
int64_t nq,
|
||||
const float* xq,
|
||||
int64_t nb,
|
||||
const float* xb,
|
||||
float* dis);
|
||||
|
||||
/// compute the inner product between nx vectors x and one y
|
||||
void faiss_fvec_inner_products_ny(
|
||||
float* ip, /* output inner product */
|
||||
const float* x,
|
||||
const float* y,
|
||||
size_t d,
|
||||
size_t ny);
|
||||
|
||||
/// compute ny square L2 distance between x and a set of contiguous y vectors
|
||||
void faiss_fvec_L2sqr_ny(
|
||||
float* dis,
|
||||
const float* x,
|
||||
const float* y,
|
||||
size_t d,
|
||||
size_t ny);
|
||||
|
||||
/// squared norm of a vector
|
||||
float faiss_fvec_norm_L2sqr(const float* x, size_t d);
|
||||
|
||||
/// compute the L2 norms for a set of vectors
|
||||
void faiss_fvec_norms_L2(float* norms, const float* x, size_t d, size_t nx);
|
||||
|
||||
/// same as fvec_norms_L2, but computes squared norms
|
||||
void faiss_fvec_norms_L2sqr(float* norms, const float* x, size_t d, size_t nx);
|
||||
|
||||
/// L2-renormalize a set of vector. Nothing done if the vector is 0-normed
|
||||
void faiss_fvec_renorm_L2(size_t d, size_t nx, float* x);
|
||||
|
||||
/// Setter of threshold value on nx above which we switch to BLAS to compute
|
||||
/// distances
|
||||
void faiss_set_distance_compute_blas_threshold(int value);
|
||||
|
||||
/// Getter of threshold value on nx above which we switch to BLAS to compute
|
||||
/// distances
|
||||
int faiss_get_distance_compute_blas_threshold();
|
||||
|
||||
/// Setter of block sizes value for BLAS distance computations
|
||||
void faiss_set_distance_compute_blas_query_bs(int value);
|
||||
|
||||
/// Getter of block sizes value for BLAS distance computations
|
||||
int faiss_get_distance_compute_blas_query_bs();
|
||||
|
||||
/// Setter of block sizes value for BLAS distance computations
|
||||
void faiss_set_distance_compute_blas_database_bs(int value);
|
||||
|
||||
/// Getter of block sizes value for BLAS distance computations
|
||||
int faiss_get_distance_compute_blas_database_bs();
|
||||
|
||||
/// Setter of number of results we switch to a reservoir to collect results
|
||||
/// rather than a heap
|
||||
void faiss_set_distance_compute_min_k_reservoir(int value);
|
||||
|
||||
/// Getter of number of results we switch to a reservoir to collect results
|
||||
/// rather than a heap
|
||||
int faiss_get_distance_compute_min_k_reservoir();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
15
packages/leann-backend-hnsw/third_party/faiss/c_api/utils/utils_c.cpp
vendored
Normal file
15
packages/leann-backend-hnsw/third_party/faiss/c_api/utils/utils_c.cpp
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// -*- c++ -*-
|
||||
|
||||
#include "utils_c.h"
|
||||
#include <faiss/Index.h>
|
||||
|
||||
const char* faiss_get_version() {
|
||||
return VERSION_STRING;
|
||||
}
|
||||
26
packages/leann-backend-hnsw/third_party/faiss/c_api/utils/utils_c.h
vendored
Normal file
26
packages/leann-backend-hnsw/third_party/faiss/c_api/utils/utils_c.h
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// -*- c -*-
|
||||
|
||||
#ifndef FAISS_UTILS_C_H
|
||||
#define FAISS_UTILS_C_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char* faiss_get_version();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user