Skip to content

Commit

Permalink
fairring, faiss, fairness (4401366386162573988)
Browse files Browse the repository at this point in the history
Reviewed By: r-barnes

Differential Revision: D49181434

fbshipit-source-id: 0554ec62155b422e4abe9cec709b69587f71dea0
  • Loading branch information
generatedunixname89002005287564 authored and facebook-github-bot committed Sep 14, 2023
1 parent 50be4ea commit d85601d
Show file tree
Hide file tree
Showing 32 changed files with 76 additions and 69 deletions.
6 changes: 3 additions & 3 deletions benchs/bench_hamming_computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <cstdio>
#include <vector>

#include <inttypes.h>
#include <cinttypes>

#include <faiss/impl/FaissAssert.h>
#include <faiss/utils/hamming.h>
Expand All @@ -24,7 +24,7 @@ struct HammingComputerM8 {
const uint64_t* a;
int n;

HammingComputerM8() {}
HammingComputerM8() = default;

HammingComputerM8(const uint8_t* a8, int code_size) {
set(a8, code_size);
Expand Down Expand Up @@ -53,7 +53,7 @@ struct HammingComputerM4 {
const uint32_t* a;
int n;

HammingComputerM4() {}
HammingComputerM4() = default;

HammingComputerM4(const uint8_t* a4, int code_size) {
set(a4, code_size);
Expand Down
2 changes: 1 addition & 1 deletion demos/demo_ivfpq_indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

double elapsed() {
struct timeval tv;
gettimeofday(&tv, NULL);
gettimeofday(&tv, nullptr);
return tv.tv_sec + tv.tv_usec * 1e-6;
}

Expand Down
7 changes: 4 additions & 3 deletions demos/demo_weighted_kmeans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cstdio>
#include <cstdlib>
#include <memory>

#include <faiss/Clustering.h>
#include <faiss/IndexFlat.h>
Expand Down Expand Up @@ -39,13 +40,13 @@ float weighted_kmeans_clustering(

switch (index_num) {
case WKMT_FlatL2:
index.reset(new IndexFlatL2(d));
index = std::make_unique<IndexFlatL2>(d);
break;
case WKMT_FlatIP:
index.reset(new IndexFlatIP(d));
index = std::make_unique<IndexFlatIP>(d);
break;
case WKMT_FlatIP_spherical:
index.reset(new IndexFlatIP(d));
index = std::make_unique<IndexFlatIP>(d);
clus.spherical = true;
break;
case WKMT_HNSW:
Expand Down
2 changes: 1 addition & 1 deletion faiss/AutoTune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ ParameterRange& ParameterSpace::add_range(const std::string& name) {
return pr;
}
}
parameter_ranges.push_back(ParameterRange());
parameter_ranges.emplace_back();
parameter_ranges.back().name = name;
return parameter_ranges.back();
}
Expand Down
2 changes: 1 addition & 1 deletion faiss/Clustering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int split_clusters(
for (size_t ci = 0; ci < k; ci++) {
if (hassign[ci] == 0) { /* need to redefine a centroid */
size_t cj;
for (cj = 0; 1; cj = (cj + 1) % k) {
for (cj = 0; true; cj = (cj + 1) % k) {
/* probability to pick this cluster for split */
float p = (hassign[cj] - 1.0) / (float)(n - k);
float r = rng.rand_float();
Expand Down
2 changes: 1 addition & 1 deletion faiss/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace faiss {

Index::~Index() {}
Index::~Index() = default;

void Index::train(idx_t /*n*/, const float* /*x*/) {
// does nothing by default
Expand Down
4 changes: 2 additions & 2 deletions faiss/Index2Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include <faiss/Index2Layer.h>

#include <faiss/impl/platform_macros.h>
#include <stdint.h>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdint>
#include <cstdio>

#ifdef __SSE3__
Expand Down Expand Up @@ -60,7 +60,7 @@ Index2Layer::Index2Layer() {
code_size = code_size_1 = code_size_2 = 0;
}

Index2Layer::~Index2Layer() {}
Index2Layer::~Index2Layer() = default;

void Index2Layer::train(idx_t n, const float* x) {
if (verbose) {
Expand Down
4 changes: 2 additions & 2 deletions faiss/IndexAdditiveQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct AQDistanceComputerDecompress : FlatCodesDistanceComputer {
return vd(q, tmp.data());
}

virtual ~AQDistanceComputerDecompress() {}
virtual ~AQDistanceComputerDecompress() = default;
};

template <bool is_IP, AdditiveQuantizer::Search_type_t st>
Expand Down Expand Up @@ -107,7 +107,7 @@ struct AQDistanceComputerLUT : FlatCodesDistanceComputer {
return bias + aq.compute_1_distance_LUT<is_IP, st>(code, LUT.data());
}

virtual ~AQDistanceComputerLUT() {}
virtual ~AQDistanceComputerLUT() = default;
};

/************************************************************
Expand Down
4 changes: 2 additions & 2 deletions faiss/IndexAdditiveQuantizerFastScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include <faiss/IndexAdditiveQuantizerFastScan.h>

#include <limits.h>
#include <cassert>
#include <climits>
#include <memory>

#include <omp.h>
Expand Down Expand Up @@ -83,7 +83,7 @@ IndexAdditiveQuantizerFastScan::IndexAdditiveQuantizerFastScan(
pq4_pack_codes(orig_codes, ntotal, M, ntotal2, bbs, M2, codes.get());
}

IndexAdditiveQuantizerFastScan::~IndexAdditiveQuantizerFastScan() {}
IndexAdditiveQuantizerFastScan::~IndexAdditiveQuantizerFastScan() = default;

void IndexAdditiveQuantizerFastScan::train(idx_t n, const float* x_in) {
if (is_trained) {
Expand Down
2 changes: 1 addition & 1 deletion faiss/IndexBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ IndexBinary::IndexBinary(idx_t d, MetricType metric)
FAISS_THROW_IF_NOT(d % 8 == 0);
}

IndexBinary::~IndexBinary() {}
IndexBinary::~IndexBinary() = default;

void IndexBinary::train(idx_t, const uint8_t*) {
// Does nothing by default.
Expand Down
2 changes: 1 addition & 1 deletion faiss/IndexBinaryFromFloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace faiss {

IndexBinaryFromFloat::IndexBinaryFromFloat() {}
IndexBinaryFromFloat::IndexBinaryFromFloat() = default;

IndexBinaryFromFloat::IndexBinaryFromFloat(Index* index)
: IndexBinary(index->d), index(index), own_fields(false) {
Expand Down
2 changes: 1 addition & 1 deletion faiss/IndexBinaryHNSW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <queue>
#include <unordered_set>

#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <cstdint>

#include <faiss/IndexBinaryFlat.h>
#include <faiss/impl/AuxIndexStructures.h>
Expand Down
6 changes: 3 additions & 3 deletions faiss/IndexBinaryIVF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ IndexBinaryIVF::IndexBinaryIVF(IndexBinary* quantizer, size_t d, size_t nlist)
cp.niter = 10;
}

IndexBinaryIVF::IndexBinaryIVF() {}
IndexBinaryIVF::IndexBinaryIVF() = default;

void IndexBinaryIVF::add(idx_t n, const uint8_t* x) {
add_with_ids(n, x, nullptr);
Expand Down Expand Up @@ -436,8 +436,8 @@ void search_knn_hamming_heap(
const idx_t* ids = nullptr;

if (!store_pairs) {
sids.reset(
new InvertedLists::ScopedIds(ivf->invlists, key));
sids = std::make_unique<InvertedLists::ScopedIds>(
ivf->invlists, key);
ids = sids->get();
}

Expand Down
2 changes: 1 addition & 1 deletion faiss/IndexFastScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

#include <faiss/IndexFastScan.h>

#include <limits.h>
#include <cassert>
#include <climits>
#include <memory>

#include <omp.h>
Expand Down
8 changes: 4 additions & 4 deletions faiss/IndexHNSW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#include <queue>
#include <unordered_set>

#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <cstdint>

#include <faiss/Index2Layer.h>
#include <faiss/IndexFlat.h>
Expand Down Expand Up @@ -876,7 +876,7 @@ IndexHNSWFlat::IndexHNSWFlat(int d, int M, MetricType metric)
* IndexHNSWPQ implementation
**************************************************************/

IndexHNSWPQ::IndexHNSWPQ() {}
IndexHNSWPQ::IndexHNSWPQ() = default;

IndexHNSWPQ::IndexHNSWPQ(int d, int pq_m, int M, int pq_nbits)
: IndexHNSW(new IndexPQ(d, pq_m, pq_nbits), M) {
Expand All @@ -903,7 +903,7 @@ IndexHNSWSQ::IndexHNSWSQ(
own_fields = true;
}

IndexHNSWSQ::IndexHNSWSQ() {}
IndexHNSWSQ::IndexHNSWSQ() = default;

/**************************************************************
* IndexHNSW2Level implementation
Expand All @@ -919,7 +919,7 @@ IndexHNSW2Level::IndexHNSW2Level(
is_trained = false;
}

IndexHNSW2Level::IndexHNSW2Level() {}
IndexHNSW2Level::IndexHNSW2Level() = default;

namespace {

Expand Down
2 changes: 1 addition & 1 deletion faiss/IndexIDMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include <faiss/IndexIDMap.h>

#include <stdint.h>
#include <cinttypes>
#include <cstdint>
#include <cstdio>
#include <limits>

Expand Down
8 changes: 5 additions & 3 deletions faiss/IndexIVF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <omp.h>
#include <cstdint>
#include <memory>
#include <mutex>

#include <algorithm>
Expand Down Expand Up @@ -45,7 +46,7 @@ Level1Quantizer::Level1Quantizer(Index* quantizer, size_t nlist)
cp.niter = 10;
}

Level1Quantizer::Level1Quantizer() {}
Level1Quantizer::Level1Quantizer() = default;

Level1Quantizer::~Level1Quantizer() {
if (own_fields) {
Expand Down Expand Up @@ -172,7 +173,7 @@ IndexIVF::IndexIVF(
}
}

IndexIVF::IndexIVF() {}
IndexIVF::IndexIVF() = default;

void IndexIVF::add(idx_t n, const float* x) {
add_with_ids(n, x, nullptr);
Expand Down Expand Up @@ -539,7 +540,8 @@ void IndexIVF::search_preassigned(
const idx_t* ids = nullptr;

if (!store_pairs) {
sids.reset(new InvertedLists::ScopedIds(invlists, key));
sids = std::make_unique<InvertedLists::ScopedIds>(
invlists, key);
ids = sids->get();
}

Expand Down
17 changes: 9 additions & 8 deletions faiss/IndexIVFAdditiveQuantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void IndexIVFAdditiveQuantizer::sa_decode(
}
}

IndexIVFAdditiveQuantizer::~IndexIVFAdditiveQuantizer() {}
IndexIVFAdditiveQuantizer::~IndexIVFAdditiveQuantizer() = default;

/*********************************************
* AQInvertedListScanner
Expand Down Expand Up @@ -157,7 +157,7 @@ struct AQInvertedListScanner : InvertedListScanner {
}
}

~AQInvertedListScanner() {}
~AQInvertedListScanner() = default;
};

template <bool is_IP>
Expand Down Expand Up @@ -188,7 +188,7 @@ struct AQInvertedListScannerDecompress : AQInvertedListScanner {
: fvec_L2sqr(q, b.data(), aq.d);
}

~AQInvertedListScannerDecompress() override {}
~AQInvertedListScannerDecompress() override = default;
};

template <bool is_IP, Search_type_t search_type>
Expand Down Expand Up @@ -231,7 +231,7 @@ struct AQInvertedListScannerLUT : AQInvertedListScanner {
aq.compute_1_distance_LUT<is_IP, search_type>(code, LUT.data());
}

~AQInvertedListScannerLUT() override {}
~AQInvertedListScannerLUT() override = default;
};

} // anonymous namespace
Expand Down Expand Up @@ -310,7 +310,7 @@ IndexIVFResidualQuantizer::IndexIVFResidualQuantizer(
metric,
search_type) {}

IndexIVFResidualQuantizer::~IndexIVFResidualQuantizer() {}
IndexIVFResidualQuantizer::~IndexIVFResidualQuantizer() = default;

/**************************************************************************************
* IndexIVFLocalSearchQuantizer
Expand All @@ -332,7 +332,7 @@ IndexIVFLocalSearchQuantizer::IndexIVFLocalSearchQuantizer(
IndexIVFLocalSearchQuantizer::IndexIVFLocalSearchQuantizer()
: IndexIVFAdditiveQuantizer(&lsq) {}

IndexIVFLocalSearchQuantizer::~IndexIVFLocalSearchQuantizer() {}
IndexIVFLocalSearchQuantizer::~IndexIVFLocalSearchQuantizer() = default;

/**************************************************************************************
* IndexIVFProductResidualQuantizer
Expand All @@ -355,7 +355,7 @@ IndexIVFProductResidualQuantizer::IndexIVFProductResidualQuantizer(
IndexIVFProductResidualQuantizer::IndexIVFProductResidualQuantizer()
: IndexIVFAdditiveQuantizer(&prq) {}

IndexIVFProductResidualQuantizer::~IndexIVFProductResidualQuantizer() {}
IndexIVFProductResidualQuantizer::~IndexIVFProductResidualQuantizer() = default;

/**************************************************************************************
* IndexIVFProductLocalSearchQuantizer
Expand All @@ -378,6 +378,7 @@ IndexIVFProductLocalSearchQuantizer::IndexIVFProductLocalSearchQuantizer(
IndexIVFProductLocalSearchQuantizer::IndexIVFProductLocalSearchQuantizer()
: IndexIVFAdditiveQuantizer(&plsq) {}

IndexIVFProductLocalSearchQuantizer::~IndexIVFProductLocalSearchQuantizer() {}
IndexIVFProductLocalSearchQuantizer::~IndexIVFProductLocalSearchQuantizer() =
default;

} // namespace faiss
3 changes: 2 additions & 1 deletion faiss/IndexIVFAdditiveQuantizerFastScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ IndexIVFAdditiveQuantizerFastScan::IndexIVFAdditiveQuantizerFastScan() {
is_trained = false;
}

IndexIVFAdditiveQuantizerFastScan::~IndexIVFAdditiveQuantizerFastScan() {}
IndexIVFAdditiveQuantizerFastScan::~IndexIVFAdditiveQuantizerFastScan() =
default;

/*********************************************************
* Training
Expand Down
2 changes: 1 addition & 1 deletion faiss/IndexIVFFastScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void IndexIVFFastScan::init_code_packer() {
bil->packer = get_CodePacker();
}

IndexIVFFastScan::~IndexIVFFastScan() {}
IndexIVFFastScan::~IndexIVFFastScan() = default;

/*********************************************************
* Code management functions
Expand Down
2 changes: 1 addition & 1 deletion faiss/IndexIVFPQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

#include <faiss/IndexIVFPQ.h>

#include <stdint.h>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdint>
#include <cstdio>

#include <algorithm>
Expand Down
Loading

0 comments on commit d85601d

Please sign in to comment.