mirror of
https://github.com/facebookresearch/faiss.git
synced 2026-10-12 02:13:36 +00:00
Fix typos in core library (root + impl/) (#4670)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4670 Fixed typos in comments, documentation, and code across the core library files and impl/ directory: Core library (root): - Fixed variable/function name typos - Fixed logic errors (duplicate condition checks) - Fixed comment typos in Index headers and implementation files impl/ directory: - Fixed 61 typos across implementation files - Fixed critical logic error in lattice_Zn.cpp (wrong array index) - Fixed typos in HNSW, NNDescent, PolysemousTraining, and other impl files All changes are in comments/documentation except for critical bug fixes. No functional changes to working code. Reviewed By: mnorris11 Differential Revision: D86571368 fbshipit-source-id: 8a9293b8524293d2f3335186bdffb0921a74a1e8
This commit is contained in:
committed by
meta-codesync[bot]
parent
d94c33065a
commit
ff1a2d4f6e
@@ -212,7 +212,7 @@ void compute_centroids(
|
||||
* It works by slightly changing the centroids to make 2 clusters from
|
||||
* a single one. Takes the same arguments as compute_centroids.
|
||||
*
|
||||
* @return nb of spliting operations (larger is worse)
|
||||
* @return nb of splitting operations (larger is worse)
|
||||
*/
|
||||
int split_clusters(
|
||||
size_t d,
|
||||
@@ -242,7 +242,7 @@ int split_clusters(
|
||||
centroids + cj * d,
|
||||
sizeof(*centroids) * d);
|
||||
|
||||
/* small symmetric pertubation */
|
||||
/* small symmetric perturbation */
|
||||
for (size_t j = 0; j < d; j++) {
|
||||
if (j % 2 == 0) {
|
||||
centroids[ci * d + j] *= 1 + EPS;
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ struct ClusteringIterationStats {
|
||||
* points to the centroids. Therefore, at each iteration the centroids
|
||||
* are added to the index.
|
||||
*
|
||||
* On output, the centoids table is set to the latest version
|
||||
* On output, the centroids table is set to the latest version
|
||||
* of the centroids and they are also added to the index. If the
|
||||
* centroids table it is not empty on input, it is also used for
|
||||
* initialization.
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ void check_compatible_for_merge(const Index* index0, const Index* index1) {
|
||||
ivf0->check_compatible_for_merge(*ivf1);
|
||||
}
|
||||
|
||||
// TODO: check as thoroughfully for other index types
|
||||
// TODO: check as thoroughly for other index types
|
||||
}
|
||||
|
||||
const IndexIVF* try_extract_index_ivf(const Index* index) {
|
||||
|
||||
+4
-4
@@ -78,7 +78,7 @@ inline size_t get_numeric_type_size(NumericType numeric_type) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Parent class for the optional search paramenters.
|
||||
/** Parent class for the optional search parameters.
|
||||
*
|
||||
* Sub-classes with additional search parameters should inherit this class.
|
||||
* Ownership of the object fields is always to the caller.
|
||||
@@ -258,7 +258,7 @@ struct Index {
|
||||
*
|
||||
* this function may not be defined for some indexes
|
||||
* @param key id of the vector to reconstruct
|
||||
* @param recons reconstucted vector (size d)
|
||||
* @param recons reconstructed vector (size d)
|
||||
*/
|
||||
virtual void reconstruct(idx_t key, float* recons) const;
|
||||
|
||||
@@ -268,7 +268,7 @@ struct Index {
|
||||
* this function may not be defined for some indexes
|
||||
* @param n number of vectors to reconstruct
|
||||
* @param keys ids of the vectors to reconstruct (size n)
|
||||
* @param recons reconstucted vector (size n * d)
|
||||
* @param recons reconstructed vector (size n * d)
|
||||
*/
|
||||
virtual void reconstruct_batch(idx_t n, const idx_t* keys, float* recons)
|
||||
const;
|
||||
@@ -278,7 +278,7 @@ struct Index {
|
||||
* this function may not be defined for some indexes
|
||||
* @param i0 index of the first vector in the sequence
|
||||
* @param ni number of vectors in the sequence
|
||||
* @param recons reconstucted vector (size ni * d)
|
||||
* @param recons reconstructed vector (size ni * d)
|
||||
*/
|
||||
virtual void reconstruct_n(idx_t i0, idx_t ni, float* recons) const;
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ void Index2Layer::train(idx_t n, const float* x) {
|
||||
|
||||
std::unique_ptr<const float[]> del_x(x_in == x ? nullptr : x);
|
||||
|
||||
std::vector<idx_t> assign(n); // assignement to coarse centroids
|
||||
std::vector<idx_t> assign(n); // assignment to coarse centroids
|
||||
q1.quantizer->assign(n, x, assign.data());
|
||||
std::vector<float> residuals(n * d);
|
||||
for (idx_t i = 0; i < n; i++) {
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ struct IndexIVFPQ;
|
||||
/** Same as an IndexIVFPQ without the inverted lists: codes are stored
|
||||
* sequentially
|
||||
*
|
||||
* The class is mainly inteded to store encoded vectors that can be
|
||||
* The class is mainly intended to store encoded vectors that can be
|
||||
* accessed randomly, the search function is not implemented.
|
||||
*/
|
||||
struct Index2Layer : IndexFlatCodes {
|
||||
|
||||
+2
-2
@@ -172,14 +172,14 @@ struct IndexBinary {
|
||||
*
|
||||
* This function may not be defined for some indexes.
|
||||
* @param key id of the vector to reconstruct
|
||||
* @param recons reconstucted vector (size d / 8)
|
||||
* @param recons reconstructed vector (size d / 8)
|
||||
*/
|
||||
virtual void reconstruct(idx_t key, uint8_t* recons) const;
|
||||
|
||||
/** Reconstruct vectors i0 to i0 + ni - 1.
|
||||
*
|
||||
* This function may not be defined for some indexes.
|
||||
* @param recons reconstucted vectors (size ni * d / 8)
|
||||
* @param recons reconstructed vectors (size ni * d / 8)
|
||||
*/
|
||||
virtual void reconstruct_n(idx_t i0, idx_t ni, uint8_t* recons) const;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ struct IndexBinaryHNSW : IndexBinary {
|
||||
|
||||
// When set to true, all neighbors in level 0 are filled up
|
||||
// to the maximum size allowed (2 * M). This option is used by
|
||||
// IndexBinaryHHNSW to create a full base layer graph that is
|
||||
// IndexBinaryHNSW to create a full base layer graph that is
|
||||
// used when GpuIndexBinaryCagra::copyFrom(IndexBinaryHNSW*) is called.
|
||||
bool keep_max_size_level0 = false;
|
||||
|
||||
|
||||
@@ -66,10 +66,10 @@ struct IndexBinaryHash : IndexBinary {
|
||||
};
|
||||
|
||||
struct IndexBinaryHashStats {
|
||||
size_t nq; // nb of queries run
|
||||
size_t n0; // nb of empty lists
|
||||
size_t nlist; // nb of non-empty inverted lists scanned
|
||||
size_t ndis; // nb of distancs computed
|
||||
size_t nq; // nb of queries run
|
||||
size_t n0; // nb of empty lists
|
||||
size_t nlist; // nb of non-empty inverted lists scanned
|
||||
size_t ndis{}; // nb of distances computed
|
||||
|
||||
IndexBinaryHashStats() {
|
||||
reset();
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ struct IndexHNSW : Index {
|
||||
|
||||
// When set to true, all neighbors in level 0 are filled up
|
||||
// to the maximum size allowed (2 * M). This option is used by
|
||||
// IndexHHNSWCagra to create a full base layer graph that is
|
||||
// IndexHNSWCagra to create a full base layer graph that is
|
||||
// used when GpuIndexCagra::copyFrom(IndexHNSWCagra*) is invoked.
|
||||
bool keep_max_size_level0 = false;
|
||||
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ struct IndexIDMapTemplate : IndexT {
|
||||
using distance_t = typename IndexT::distance_t;
|
||||
|
||||
IndexT* index = nullptr; ///! the sub-index
|
||||
bool own_fields = false; ///! whether pointers are deleted in destructo
|
||||
bool own_fields = false; ///! whether pointers are deleted in destructor
|
||||
std::vector<idx_t> id_map;
|
||||
|
||||
explicit IndexIDMapTemplate(IndexT* index);
|
||||
|
||||
+1
-1
@@ -506,7 +506,7 @@ void IndexIVF::search_preassigned(
|
||||
};
|
||||
|
||||
// single list scan using the current scanner (with query
|
||||
// set porperly) and storing results in simi and idxi
|
||||
// set properly) and storing results in simi and idxi
|
||||
auto scan_one_list = [&](idx_t key,
|
||||
float coarse_dis_i,
|
||||
float* simi,
|
||||
|
||||
+2
-2
@@ -160,7 +160,7 @@ struct IndexIVFInterface : Level1Quantizer {
|
||||
* index maps to a list (aka inverted list or posting list), where the
|
||||
* id of the vector is stored.
|
||||
*
|
||||
* The inverted list object is required only after trainng. If none is
|
||||
* The inverted list object is required only after training. If none is
|
||||
* set externally, an ArrayInvertedLists is used automatically.
|
||||
*
|
||||
* At search time, the vector to be searched is also quantized, and
|
||||
@@ -171,7 +171,7 @@ struct IndexIVFInterface : Level1Quantizer {
|
||||
* lists are visited.
|
||||
*
|
||||
* Sub-classes implement a post-filtering of the index that refines
|
||||
* the distance estimation from the query to databse vectors.
|
||||
* the distance estimation from the query to database vectors.
|
||||
*/
|
||||
struct IndexIVF : Index, IndexIVFInterface {
|
||||
/// Access to the actual data
|
||||
|
||||
+1
-1
@@ -113,7 +113,7 @@ struct IndexIVFPQ : IndexIVF {
|
||||
*/
|
||||
size_t find_duplicates(idx_t* ids, size_t* lims) const;
|
||||
|
||||
// map a vector to a binary code knowning the index
|
||||
// map a vector to a binary code knowing the index
|
||||
void encode(idx_t key, const float* x, uint8_t* code) const;
|
||||
|
||||
/** Encode multiple vectors
|
||||
|
||||
@@ -331,7 +331,7 @@ void IndexIVFSpectralHash::replace_vt(VectorTransform* vt_in, bool own) {
|
||||
/*
|
||||
Check that the encoder is a single vector transform followed by a LSH
|
||||
that just does thresholding.
|
||||
If this is not the case, the linear transform + threhsolds of the IndexLSH
|
||||
If this is not the case, the linear transform + thresholds of the IndexLSH
|
||||
should be merged into the VectorTransform (which is feasible).
|
||||
*/
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ struct IndexIVFSpectralHash : IndexIVF {
|
||||
*/
|
||||
void replace_vt(VectorTransform* vt, bool own = false);
|
||||
|
||||
/** convenience function to get the VT from an index constucted by an
|
||||
/** convenience function to get the VT from an index constructed by an
|
||||
* index_factory (should end in "LSH") */
|
||||
void replace_vt(IndexPreTransform* index, bool own = false);
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ void IndexNNDescent::add(idx_t n, const float* x) {
|
||||
|
||||
if (ntotal != 0) {
|
||||
fprintf(stderr,
|
||||
"WARNING NNDescent doest not support dynamic insertions,"
|
||||
"WARNING NNDescent does not support dynamic insertions,"
|
||||
"multiple insertions would lead to re-building the index");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -261,7 +261,7 @@ void IndexNSG::check_knn_graph(const idx_t* knn_graph, idx_t n, int K) const {
|
||||
}
|
||||
FAISS_THROW_IF_NOT_MSG(
|
||||
total_count < n / 10,
|
||||
"There are too much invalid entries in the knn graph. "
|
||||
"There are too many invalid entries in the knn graph. "
|
||||
"It may be an invalid knn graph.");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -164,7 +164,7 @@ struct MultiIndexQuantizer : Index {
|
||||
// block size used in MultiIndexQuantizer::search
|
||||
FAISS_API extern int multi_index_quantizer_search_bs;
|
||||
|
||||
/** MultiIndexQuantizer where the PQ assignmnet is performed by sub-indexes
|
||||
/** MultiIndexQuantizer where the PQ assignment is performed by sub-indexes
|
||||
*/
|
||||
struct MultiIndexQuantizer2 : MultiIndexQuantizer {
|
||||
/// M Indexes on d / M dimensions
|
||||
|
||||
@@ -264,7 +264,7 @@ void IndexShardsTemplate<IndexT>::search(
|
||||
}
|
||||
}
|
||||
|
||||
// explicit instanciations
|
||||
// explicit instantiations
|
||||
template struct IndexShardsTemplate<Index>;
|
||||
template struct IndexShardsTemplate<IndexBinary>;
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ MatrixStats::MatrixStats(size_t n, size_t d, const float* x) : n(n), d(d) {
|
||||
if (d > 1024) {
|
||||
do_comment(
|
||||
"indexing this many dimensions is hard, "
|
||||
"please consider dimensionality reducution (with PCAMatrix)\n");
|
||||
"please consider dimensionality reduction (with PCAMatrix)\n");
|
||||
}
|
||||
|
||||
hash_value = hash_bytes((const uint8_t*)x, n * d * sizeof(*x));
|
||||
@@ -125,7 +125,7 @@ MatrixStats::MatrixStats(size_t n, size_t d, const float* x) : n(n), d(d) {
|
||||
}
|
||||
}
|
||||
|
||||
// invalid vecor stats
|
||||
// invalid vector stats
|
||||
if (n_valid == n) {
|
||||
do_comment("no NaN or Infs in data\n");
|
||||
} else {
|
||||
@@ -229,7 +229,7 @@ MatrixStats::MatrixStats(size_t n, size_t d, const float* x) : n(n), d(d) {
|
||||
} else {
|
||||
do_comment(
|
||||
"%zd dimensions are too large "
|
||||
"wrt. their variance, may loose precision "
|
||||
"wrt. their variance, may lose precision "
|
||||
"in IndexFlatL2 (use CenteringTransform)\n",
|
||||
n_dangerous_range);
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ struct OPQMatrix : LinearTransform {
|
||||
void train(idx_t n, const float* x) override;
|
||||
};
|
||||
|
||||
/** remap dimensions for intput vectors, possibly inserting 0s
|
||||
/** remap dimensions for input vectors, possibly inserting 0s
|
||||
* strictly speaking this is also a linear transform but we don't want
|
||||
* to compute it with matrix multiplies */
|
||||
struct RemapDimensionsTransform : VectorTransform {
|
||||
|
||||
@@ -154,7 +154,7 @@ IndexNSG* clone_IndexNSG(const IndexNSG* insg) {
|
||||
TRYCLONE(IndexNSGPQ, insg)
|
||||
TRYCLONE(IndexNSGSQ, insg)
|
||||
TRYCLONE(IndexNSG, insg) {
|
||||
FAISS_THROW_MSG("clone not supported for this type of IndexNNDescent");
|
||||
FAISS_THROW_MSG("clone not supported for this type of IndexNSG");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -404,7 +404,7 @@ void AdditiveQuantizer::compute_LUT(
|
||||
namespace {
|
||||
|
||||
/* compute inner products of one query with all centroids, given a look-up
|
||||
* table of all inner producst with codebook entries */
|
||||
* table of all inner products with codebook entries */
|
||||
void compute_inner_prod_with_LUT(
|
||||
const AdditiveQuantizer& aq,
|
||||
const float* LUT,
|
||||
|
||||
@@ -86,7 +86,7 @@ void BufferList::append_buffer() {
|
||||
wp = 0;
|
||||
}
|
||||
|
||||
/// copy elemnts ofs:ofs+n-1 seen as linear data in the buffers to
|
||||
/// copy elements ofs:ofs+n-1 seen as linear data in the buffers to
|
||||
/// tables dest_ids, dest_dis
|
||||
void BufferList::copy_range(
|
||||
size_t ofs,
|
||||
|
||||
@@ -80,7 +80,7 @@ struct BufferList {
|
||||
/// add one result, possibly appending a new buffer if needed
|
||||
void add(idx_t id, float dis);
|
||||
|
||||
/// copy elemnts ofs:ofs+n-1 seen as linear data in the buffers to
|
||||
/// copy elements ofs:ofs+n-1 seen as linear data in the buffers to
|
||||
/// tables dest_ids, dest_dis
|
||||
void copy_range(size_t ofs, size_t n, idx_t* dest_ids, float* dest_dis);
|
||||
};
|
||||
|
||||
@@ -38,14 +38,14 @@ struct CodePacker {
|
||||
// code_size
|
||||
) const = 0;
|
||||
|
||||
// pack all code in a block
|
||||
// pack all codes in a block
|
||||
virtual void pack_all(
|
||||
const uint8_t* flat_codes, // codes to write to the block, size
|
||||
// (nvec * code_size)
|
||||
uint8_t* block // block to write to (size block_size)
|
||||
) const;
|
||||
|
||||
// unpack all code in a block
|
||||
// unpack all codes in a block
|
||||
virtual void unpack_all(
|
||||
const uint8_t* block, // block to read from (size block_size)
|
||||
uint8_t* flat_codes // where to write the resulting codes size (nvec
|
||||
|
||||
@@ -60,7 +60,7 @@ struct DistanceComputer {
|
||||
};
|
||||
|
||||
/* Wrap the distance computer into one that negates the
|
||||
distances. This makes supporting INNER_PRODUCE search easier */
|
||||
distances. This makes supporting INNER_PRODUCT search easier */
|
||||
|
||||
struct NegativeDistanceComputer : DistanceComputer {
|
||||
/// owned by this
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ HNSW::HNSW(int M) : rng(12345) {
|
||||
|
||||
int HNSW::random_level() {
|
||||
double f = rng.rand_float();
|
||||
// could be a bit faster with bissection
|
||||
// could be a bit faster with bisection
|
||||
for (int level = 0; level < assign_probas.size(); level++) {
|
||||
if (f < assign_probas[level]) {
|
||||
return level;
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ namespace faiss {
|
||||
* Yu. A. Malkov, D. A. Yashunin, arXiv 2017
|
||||
*
|
||||
* This implementation is heavily influenced by the NMSlib
|
||||
* implementation by Yury Malkov and Leonid Boystov
|
||||
* implementation by Yury Malkov and Leonid Boytsov
|
||||
* (https://github.com/searchivarius/nmslib)
|
||||
*
|
||||
* The HNSW object stores only the neighbor link structure, see
|
||||
@@ -61,7 +61,7 @@ struct HNSW {
|
||||
|
||||
typedef std::pair<float, storage_idx_t> Node;
|
||||
|
||||
/** Heap structure that allows fast
|
||||
/** Heap structure that allows fast access and updates.
|
||||
*/
|
||||
struct MinimaxHeap {
|
||||
int n;
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
// LU decomoposition of a general matrix
|
||||
// LU decomposition of a general matrix
|
||||
void sgetrf_(
|
||||
FINTEGER* m,
|
||||
FINTEGER* n,
|
||||
@@ -65,7 +65,7 @@ int sgemm_(
|
||||
float* c,
|
||||
FINTEGER* ldc);
|
||||
|
||||
// LU decomoposition of a general matrix
|
||||
// LU decomposition of a general matrix
|
||||
void dgetrf_(
|
||||
FINTEGER* m,
|
||||
FINTEGER* n,
|
||||
@@ -189,7 +189,7 @@ void LocalSearchQuantizer::train(size_t n, const float* x) {
|
||||
std::vector<int32_t> codes(n * M); // [n, M]
|
||||
random_int32(codes, 0, K - 1, gen);
|
||||
|
||||
// compute standard derivations of each dimension
|
||||
// compute standard deviations of each dimension
|
||||
std::vector<float> stddev(d, 0);
|
||||
|
||||
#pragma omp parallel for
|
||||
@@ -487,7 +487,7 @@ void LocalSearchQuantizer::update_codebooks(
|
||||
* L = (X - \sum cj)^2, j = 1, ..., M
|
||||
* L = X^2 - 2X * \sum cj + (\sum cj)^2
|
||||
*
|
||||
* X^2 is negligable since it is the same for all possible value
|
||||
* X^2 is negligible since it is the same for all possible value
|
||||
* k of the m-th subcode.
|
||||
*
|
||||
* 2X * \sum cj is the unary term
|
||||
|
||||
@@ -63,7 +63,7 @@ struct DummyScaler {
|
||||
};
|
||||
|
||||
/// consumes 2x4 bits to encode a norm as a scalar additive quantizer
|
||||
/// the norm is scaled because its range if larger than other components
|
||||
/// the norm is scaled because its range is larger than other components
|
||||
struct NormTableScaler {
|
||||
static constexpr int nscale = 2;
|
||||
int scale_int;
|
||||
|
||||
@@ -177,7 +177,7 @@ void NNDescent::join(DistanceComputer& qdis) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sample neighbors for each node to peform local join later
|
||||
/// Sample neighbors for each node to perform local join later
|
||||
/// Store them in nn_new and nn_old
|
||||
void NNDescent::update() {
|
||||
// Step 1.
|
||||
|
||||
@@ -117,7 +117,7 @@ struct NNDescent {
|
||||
/// Perform local join on each node
|
||||
void join(DistanceComputer& qdis);
|
||||
|
||||
/// Sample new neighbors for each node to peform local join later
|
||||
/// Sample new neighbors for each node to perform local join later
|
||||
void update();
|
||||
|
||||
/// Sample a small number of points to evaluate the quality of KNNG built
|
||||
|
||||
+1
-1
@@ -621,7 +621,7 @@ int NSG::attach_unlinked(
|
||||
}
|
||||
}
|
||||
|
||||
// randomly choice annother node
|
||||
// randomly choice another node
|
||||
if (!found) {
|
||||
do {
|
||||
node = rng.rand_int(ntotal);
|
||||
|
||||
@@ -178,7 +178,7 @@ struct ReproduceWithHammingObjective : PermutationObjective {
|
||||
return x * x;
|
||||
}
|
||||
|
||||
// weihgting of distances: it is more important to reproduce small
|
||||
// weighting of distances: it is more important to reproduce small
|
||||
// distances well
|
||||
double dis_weight(double x) const {
|
||||
return exp(-dis_weight_factor * x);
|
||||
@@ -295,7 +295,7 @@ struct ReproduceWithHammingObjective : PermutationObjective {
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// weihgting of distances: it is more important to reproduce small
|
||||
// weighting of distances: it is more important to reproduce small
|
||||
// distances well
|
||||
double ReproduceDistancesObjective::dis_weight(double x) const {
|
||||
return exp(-dis_weight_factor * x);
|
||||
@@ -636,7 +636,7 @@ struct Score3Computer : PermutationObjective {
|
||||
return accu;
|
||||
}
|
||||
|
||||
/// PermutationObjective implementeation (just negates the scores
|
||||
/// PermutationObjective implementation (just negates the scores
|
||||
/// for minimization)
|
||||
|
||||
double compute_cost(const int* perm) const override {
|
||||
@@ -689,7 +689,7 @@ struct RankingScore2 : Score3Computer<float, double> {
|
||||
/// count nb of i, j in a x b st. i < j
|
||||
/// a and b should be sorted on input
|
||||
/// they are the ranks of j and k respectively.
|
||||
/// specific version for diff-of-rank weighting, cannot optimized
|
||||
/// specific version for diff-of-rank weighting, cannot optimize
|
||||
/// with a cumulative table
|
||||
double accum_gt_weight_diff(
|
||||
const std::vector<int>& a,
|
||||
@@ -985,7 +985,7 @@ size_t PolysemousTraining::memory_usage_per_thread(
|
||||
return n * n * n * sizeof(float);
|
||||
}
|
||||
|
||||
FAISS_THROW_MSG("Invalid optmization type");
|
||||
FAISS_THROW_MSG("Invalid optimization type");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ void ProductAdditiveQuantizer::compute_unpacked_codes(
|
||||
int32_t* unpacked_codes,
|
||||
size_t n,
|
||||
const float* centroids) const {
|
||||
/// TODO: actuallly we do not need to unpack and pack
|
||||
/// TODO: actually we do not need to unpack and pack
|
||||
size_t offset_d = 0, offset_m = 0;
|
||||
std::vector<float> xsub;
|
||||
std::vector<uint8_t> codes;
|
||||
|
||||
@@ -26,11 +26,11 @@ namespace faiss {
|
||||
* The classes below are intended to be used as template arguments
|
||||
* they handle results for batches of queries (size nq).
|
||||
* They can be called in two ways:
|
||||
* - by instanciating a SingleResultHandler that tracks results for a single
|
||||
* - by instantiating a SingleResultHandler that tracks results for a single
|
||||
* query
|
||||
* - with begin_multiple/add_results/end_multiple calls where a whole block of
|
||||
* results is submitted
|
||||
* All classes are templated on C which to define wheter the min or the max of
|
||||
* All classes are templated on C which to define whether the min or the max of
|
||||
* results is to be kept, and on sel, so that the codepaths for with / without
|
||||
* selector can be separated at compile time.
|
||||
*****************************************************************/
|
||||
@@ -306,7 +306,7 @@ struct HeapBlockResultHandler : TopkBlockResultHandler<C, use_sel> {
|
||||
*
|
||||
* A reservoir is a result array of size capacity > n (number of requested
|
||||
* results) all results below a threshold are stored in an arbitrary order.
|
||||
*When the capacity is reached, a new threshold is chosen by partitionning
|
||||
*When the capacity is reached, a new threshold is chosen by partitioning
|
||||
*the distance array.
|
||||
*****************************************************************/
|
||||
|
||||
|
||||
@@ -321,7 +321,7 @@ struct Codec6bit {
|
||||
static FAISS_ALWAYS_INLINE __m256
|
||||
decode_8_components(const uint8_t* code, int i) {
|
||||
// // Faster code for Intel CPUs or AMD Zen3+, just keeping it here
|
||||
// // for the reference, maybe, it becomes used oned day.
|
||||
// // for the reference, maybe, it becomes used one day.
|
||||
// const uint16_t* data16 = (const uint16_t*)(code + (i >> 2) * 3);
|
||||
// const uint32_t* data32 = (const uint32_t*)data16;
|
||||
// const uint64_t val = *data32 + ((uint64_t)data16[2] << 32);
|
||||
|
||||
@@ -71,9 +71,10 @@ namespace faiss {
|
||||
**************************************************************/
|
||||
|
||||
// This is a baseline functionality for reading mmapped and zerocopied vector.
|
||||
// * if `beforeknown_size` is defined, then a size of the vector won't be read.
|
||||
// * if `beforeknown_size` is defined, then a size of the vector won't be
|
||||
// read.
|
||||
// * if `size_multiplier` is defined, then a size will be multiplied by it.
|
||||
// * returns true is the case was handled; ownerwise, false
|
||||
// * returns true is the case was handled; otherwise, false
|
||||
template <typename VectorT>
|
||||
bool read_vector_base(
|
||||
VectorT& target,
|
||||
@@ -184,7 +185,7 @@ void read_vector(VectorT& target, IOReader* f) {
|
||||
// a replacement for READXBVECTOR
|
||||
template <typename VectorT>
|
||||
void read_xb_vector(VectorT& target, IOReader* f) {
|
||||
// size is not known beforehand, nultiply the size 4x
|
||||
// size is not known beforehand, multiply the size 4x
|
||||
if (read_vector_base<VectorT>(target, f, std::nullopt, 4)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
* or deprecated fields), the fourcc can be replaced. New code should
|
||||
* be able to read the old fourcc and fill in new classes.
|
||||
*
|
||||
* TODO: in this file, the read functions that encouter errors may
|
||||
* TODO: in this file, the read functions that encounter errors may
|
||||
* leak memory.
|
||||
**************************************************************/
|
||||
|
||||
@@ -886,7 +886,7 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
||||
} else if (
|
||||
const IndexRowwiseMinMax* imm =
|
||||
dynamic_cast<const IndexRowwiseMinMax*>(idx)) {
|
||||
// IndexRowwiseMinmaxFloat
|
||||
// IndexRowwiseMinMaxFloat
|
||||
uint32_t h = fourcc("IRMf");
|
||||
WRITE1(h);
|
||||
write_index_header(imm, f);
|
||||
@@ -894,7 +894,7 @@ void write_index(const Index* idx, IOWriter* f, int io_flags) {
|
||||
} else if (
|
||||
const IndexRowwiseMinMaxFP16* imm_2 =
|
||||
dynamic_cast<const IndexRowwiseMinMaxFP16*>(idx)) {
|
||||
// IndexRowwiseMinmaxHalf
|
||||
// IndexRowwiseMinMaxHalf
|
||||
uint32_t h = fourcc("IRMh");
|
||||
WRITE1(h);
|
||||
write_index_header(imm_2, f);
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ FileIOReader::FileIOReader(const char* fname) {
|
||||
FileIOReader::~FileIOReader() {
|
||||
if (need_close) {
|
||||
int ret = fclose(f);
|
||||
if (ret != 0) { // we cannot raise and exception in the destructor
|
||||
if (ret != 0) { // we cannot raise an exception in the destructor
|
||||
fprintf(stderr,
|
||||
"file %s close error: %s",
|
||||
name.c_str(),
|
||||
@@ -109,7 +109,7 @@ FileIOWriter::~FileIOWriter() {
|
||||
if (need_close) {
|
||||
int ret = fclose(f);
|
||||
if (ret != 0) {
|
||||
// we cannot raise and exception in the destructor
|
||||
// we cannot raise an exception in the destructor
|
||||
fprintf(stderr,
|
||||
"file %s close error: %s",
|
||||
name.c_str(),
|
||||
|
||||
@@ -141,7 +141,7 @@ void smawk(
|
||||
namespace {
|
||||
|
||||
class CostCalculator {
|
||||
// The reuslt would be inaccurate if we use float
|
||||
// The result would be inaccurate if we use float
|
||||
std::vector<double> cumsum;
|
||||
std::vector<double> cumsum2;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ void smawk(
|
||||
* @param n input array length
|
||||
* @param nclusters number of clusters
|
||||
* @param centroids output centroids, size nclusters
|
||||
* @return imbalancce factor
|
||||
* @return imbalance factor
|
||||
*/
|
||||
double kmeans1d(const float* x, size_t n, size_t nclusters, float* centroids);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ struct ZnSphereSearch {
|
||||
int dimS, r2;
|
||||
int natom;
|
||||
|
||||
/// size dim * ntatom
|
||||
/// size dim * natom
|
||||
std::vector<float> voc;
|
||||
|
||||
ZnSphereSearch(int dim, int r2);
|
||||
@@ -138,7 +138,7 @@ struct ZnSphereCodec : ZnSphereSearch, EnumeratedVectors {
|
||||
*
|
||||
* Uses a recursive decomposition on the dimensions to encode
|
||||
* centroids found by the ZnSphereSearch. The codes are *not*
|
||||
* compatible with the ones of ZnSpehreCodec
|
||||
* compatible with the ones of ZnSphereCodec
|
||||
*/
|
||||
struct ZnSphereCodecRec : EnumeratedVectors {
|
||||
int r2;
|
||||
|
||||
@@ -34,7 +34,7 @@ struct SIMDResultHandler;
|
||||
* @param ntotal number of input codes
|
||||
* @param nb output number of codes (ntotal rounded up to a multiple of
|
||||
* bbs)
|
||||
* @param nsq number of sub-quantizers (=M rounded up to a muliple of 2)
|
||||
* @param nsq number of sub-quantizers (=M rounded up to a multiple of 2)
|
||||
* @param bbs size of database blocks (multiple of 32)
|
||||
* @param blocks output array, size nb * nsq / 2.
|
||||
* @param code_stride optional stride between consecutive codes (0 = use
|
||||
@@ -110,7 +110,7 @@ struct CodePackerPQ4 : CodePacker {
|
||||
/** Pack Look-up table for consumption by the kernel.
|
||||
*
|
||||
* @param nq number of queries
|
||||
* @param nsq number of sub-quantizers (muliple of 2)
|
||||
* @param nsq number of sub-quantizers (multiple of 2)
|
||||
* @param src input array, size (nq, 16)
|
||||
* @param dest output array, size (nq, 16)
|
||||
*/
|
||||
@@ -121,7 +121,7 @@ void pq4_pack_LUT(int nq, int nsq, const uint8_t* src, uint8_t* dest);
|
||||
* @param nq number of queries
|
||||
* @param nb number of database elements
|
||||
* @param bbs size of database blocks (multiple of 32)
|
||||
* @param nsq number of sub-quantizers (muliple of 2)
|
||||
* @param nsq number of sub-quantizers (multiple of 2)
|
||||
* @param codes packed codes array
|
||||
* @param LUT packed look-up table
|
||||
* @param scaler scaler to scale the encoded norm
|
||||
@@ -160,7 +160,7 @@ int pq4_preferred_qbs(int nq);
|
||||
*
|
||||
* @param qbs 4-bit encoded number of query blocks, the total number of
|
||||
* queries handled (nq) is deduced from it
|
||||
* @param nsq number of sub-quantizers (muliple of 2)
|
||||
* @param nsq number of sub-quantizers (multiple of 2)
|
||||
* @param src input array, size (nq, 16)
|
||||
* @param dest output array, size (nq, 16)
|
||||
* @return nq
|
||||
@@ -179,11 +179,11 @@ int pq4_pack_LUT_qbs_q_map(
|
||||
/** Run accumulation loop.
|
||||
*
|
||||
* @param qbs 4-bit encoded number of queries
|
||||
* @param nb number of database codes (mutliple of bbs)
|
||||
* @param nb number of database codes (multiple of bbs)
|
||||
* @param nsq number of sub-quantizers
|
||||
* @param codes encoded database vectors (packed)
|
||||
* @param LUT look-up table (packed)
|
||||
* @param res call-back for the resutls
|
||||
* @param res call-back for the results
|
||||
* @param scaler scaler to scale the encoded norm
|
||||
*/
|
||||
void pq4_accumulate_loop_qbs(
|
||||
|
||||
@@ -781,7 +781,7 @@ void accumulate_to_mem(
|
||||
}
|
||||
|
||||
int pq4_preferred_qbs(int n) {
|
||||
// from timmings in P141901742, P141902828
|
||||
// from timings in P141901742, P141902828
|
||||
static int map[12] = {
|
||||
0, 1, 2, 3, 0x13, 0x23, 0x33, 0x223, 0x233, 0x333, 0x2233, 0x2333};
|
||||
if (n <= 11) {
|
||||
|
||||
@@ -98,7 +98,7 @@ FAISS_API extern bool simd_result_handlers_accept_virtual;
|
||||
|
||||
namespace simd_result_handlers {
|
||||
|
||||
/** Dummy structure that just computes a chqecksum on results
|
||||
/** Dummy structure that just computes a checksum on results
|
||||
* (to avoid the computation to be optimized away) */
|
||||
struct DummyResultHandler : SIMDResultHandler {
|
||||
size_t cs = 0;
|
||||
@@ -770,7 +770,7 @@ void dispatch_SIMDResultHandler_fixedCW(
|
||||
} else { // generic handler -- will not be inlined
|
||||
FAISS_THROW_IF_NOT_FMT(
|
||||
simd_result_handlers_accept_virtual,
|
||||
"Running vitrual handler for %s",
|
||||
"Running virtual handler for %s",
|
||||
typeid(res).name());
|
||||
consumer.template f<SIMDResultHandler>(res, args...);
|
||||
}
|
||||
@@ -801,7 +801,7 @@ void dispatch_SIMDResultHandler(
|
||||
} else { // generic path
|
||||
FAISS_THROW_IF_NOT_FMT(
|
||||
simd_result_handlers_accept_virtual,
|
||||
"Running vitrual handler for %s",
|
||||
"Running virtual handler for %s",
|
||||
typeid(res).name());
|
||||
consumer.template f<SIMDResultHandler>(res, args...);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
namespace faiss {
|
||||
|
||||
/** Build and index with the sequence of processing steps described in
|
||||
/** Build an index with the sequence of processing steps described in
|
||||
* the string. */
|
||||
Index* index_factory(
|
||||
int d,
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* object that abstracts the medium.
|
||||
*
|
||||
* The read functions return objects that should be deallocated with
|
||||
* delete. All references within these objectes are owned by the
|
||||
* delete. All references within these objects are owned by the
|
||||
* object.
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user