mirror of
https://github.com/facebookresearch/faiss.git
synced 2026-10-12 02:13:36 +00:00
Implement remove_ids in IndexPQ (#407)
* Implement remove_ids in IndexPQ * Update IndexPQ.cpp
This commit is contained in:
+22
@@ -21,6 +21,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "FaissAssert.h"
|
||||
#include "AuxIndexStructures.h"
|
||||
#include "hamming.h"
|
||||
|
||||
namespace faiss {
|
||||
@@ -84,6 +85,27 @@ void IndexPQ::add (idx_t n, const float *x)
|
||||
}
|
||||
|
||||
|
||||
long IndexPQ::remove_ids (const IDSelector & sel)
|
||||
{
|
||||
idx_t j = 0;
|
||||
for (idx_t i = 0; i < ntotal; i++) {
|
||||
if (sel.is_member (i)) {
|
||||
// should be removed
|
||||
} else {
|
||||
if (i > j) {
|
||||
memmove (&codes[pq.code_size * j], &codes[pq.code_size * i], pq.code_size);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
long nremove = ntotal - j;
|
||||
if (nremove > 0) {
|
||||
ntotal = j;
|
||||
codes.resize (ntotal * pq.code_size);
|
||||
}
|
||||
return nremove;
|
||||
}
|
||||
|
||||
|
||||
void IndexPQ::reset()
|
||||
{
|
||||
|
||||
@@ -83,6 +83,11 @@ struct IndexPQ: Index {
|
||||
|
||||
Search_type_t search_type;
|
||||
|
||||
/** remove some ids. NB that Because of the structure of the
|
||||
* indexing structre, the semantics of this operation are
|
||||
* different from the usual ones: the new ids are shifted */
|
||||
long remove_ids(const IDSelector& sel) override;
|
||||
|
||||
// just encode the sign of the components, instead of using the PQ encoder
|
||||
// used only for the queries
|
||||
bool encode_signs;
|
||||
|
||||
Reference in New Issue
Block a user