Skip to content

Commit

Permalink
Enable clang-format + autofix.
Browse files Browse the repository at this point in the history
Summary: Format whole codebase with clang-format.

Reviewed By: mdouze

Differential Revision: D22891341

fbshipit-source-id: 673032b2444d61026d1e2c3fa2c5659f178cf58b
  • Loading branch information
Lucas Hosseini authored and facebook-github-bot committed Feb 25, 2021
1 parent 6d51766 commit e86bf8c
Show file tree
Hide file tree
Showing 346 changed files with 34,376 additions and 34,005 deletions.
20 changes: 9 additions & 11 deletions benchs/bench_6bit_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
* LICENSE file in the root directory of this source tree.
*/


#include <cstdio>
#include <omp.h>
#include <cstdio>

#include <faiss/impl/ScalarQuantizer.h>
#include <faiss/utils/utils.h>
#include <faiss/utils/random.h>
#include <faiss/utils/distances.h>
#include <faiss/utils/random.h>
#include <faiss/utils/utils.h>

using namespace faiss;

int main() {

int d = 128;
int n = 2000;

Expand Down Expand Up @@ -52,13 +50,14 @@ int main() {

size_t ndiff = 0;
for (size_t i = 0; i < codes.size(); i++) {
if (codes[i] != codes2[i]) ndiff++;
if (codes[i] != codes2[i])
ndiff++;
}

printf("ndiff for idempotence: %ld / %ld\n", ndiff, codes.size());

std::unique_ptr<ScalarQuantizer::SQDistanceComputer>
dc(sq.get_distance_computer());
std::unique_ptr<ScalarQuantizer::SQDistanceComputer> dc(
sq.get_distance_computer());
dc->codes = codes.data();
dc->code_size = sq.code_size;
printf("code size: %ld\n", dc->code_size);
Expand All @@ -72,9 +71,8 @@ int main() {
}
}
printf("distances computed in %.3f ms, checksum=%g\n",
getmillisecs() - t0, sum_dis);


getmillisecs() - t0,
sum_dis);

return 0;
}
39 changes: 24 additions & 15 deletions benchs/bench_hamming_computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/


#include <cstdio>
#include <omp.h>
#include <cstdio>
#include <vector>

#include <faiss/impl/FaissAssert.h>
Expand All @@ -17,8 +16,13 @@

using namespace faiss;

template<class T>
void hamming_cpt_test(int code_size, uint8_t* data1, uint8_t* data2, int n, int* rst) {
template <class T>
void hamming_cpt_test(
int code_size,
uint8_t* data1,
uint8_t* data2,
int n,
int* rst) {
T computer(data1, code_size);
for (int i = 0; i < n; i++) {
rst[i] = computer.hamming(data2);
Expand All @@ -35,11 +39,11 @@ int main() {
byte_rand(x.data(), n, 12345);

int nrun = 100;
for(size_t cs: code_size) {
for (size_t cs : code_size) {
printf("benchmark with code_size=%zd n=%zd nrun=%d\n", cs, n, nrun);

double tot_t1 = 0, tot_t2 = 0, tot_t3 = 0;
#pragma omp parallel reduction(+: tot_t1, tot_t2, tot_t3)
#pragma omp parallel reduction(+ : tot_t1, tot_t2, tot_t3)
{
std::vector<int> rst_m4(n);
std::vector<int> rst_m8(n);
Expand All @@ -51,34 +55,39 @@ int main() {
t0 = getmillisecs();

// new implem from Zilliz
hamming_cpt_test<HammingComputerDefault>(cs, x.data(), x.data(), n, rst_default.data());
hamming_cpt_test<HammingComputerDefault>(
cs, x.data(), x.data(), n, rst_default.data());
t1 = getmillisecs();

// M8
hamming_cpt_test<HammingComputerM8>(cs, x.data(), x.data(), n, rst_m8.data());
hamming_cpt_test<HammingComputerM8>(
cs, x.data(), x.data(), n, rst_m8.data());
t2 = getmillisecs();

// M4
hamming_cpt_test<HammingComputerM4>(cs, x.data(), x.data(), n, rst_m4.data());
t3= getmillisecs();
hamming_cpt_test<HammingComputerM4>(
cs, x.data(), x.data(), n, rst_m4.data());
t3 = getmillisecs();

tot_t1 += t1 - t0;
tot_t2 += t2 - t1;
tot_t3 += t3 - t2;
}

for (int i=0;i<n;i++){
for (int i = 0; i < n; i++) {
FAISS_THROW_IF_NOT_FMT(
(rst_m4[i] == rst_m8[i] && rst_m4[i] == rst_default[i]),
"wrong result i=%d, m4 %d m8 %d default %d",
i, rst_m4[i], rst_m8[i], rst_default[i]);
(rst_m4[i] == rst_m8[i] && rst_m4[i] == rst_default[i]),
"wrong result i=%d, m4 %d m8 %d default %d",
i,
rst_m4[i],
rst_m8[i],
rst_default[i]);
}
}

printf("Hamming_Dft implem: %.3f ms\n", tot_t1 / nrun);
printf("Hamming_M8 implem: %.3f ms\n", tot_t2 / nrun);
printf("Hamming_M4 implem: %.3f ms\n", tot_t3 / nrun);

}
return 0;
}
56 changes: 30 additions & 26 deletions benchs/bench_heap_replace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
* LICENSE file in the root directory of this source tree.
*/


#include <cstdio>
#include <omp.h>
#include <cstdio>

#include <faiss/utils/utils.h>
#include <faiss/utils/random.h>
#include <faiss/utils/Heap.h>
#include <faiss/impl/FaissAssert.h>
#include <faiss/utils/Heap.h>
#include <faiss/utils/random.h>
#include <faiss/utils/utils.h>

using namespace faiss;

void addn_default(
size_t n, size_t k,
const float *x, int64_t *heap_ids, float * heap_val)
{
size_t n,
size_t k,
const float* x,
int64_t* heap_ids,
float* heap_val) {
for (size_t i = 0; i < k; i++) {
minheap_push(i + 1, heap_val, heap_ids, x[i], i);
}
Expand All @@ -35,9 +36,11 @@ void addn_default(
}

void addn_replace(
size_t n, size_t k,
const float *x, int64_t *heap_ids, float * heap_val)
{
size_t n,
size_t k,
const float* x,
int64_t* heap_ids,
float* heap_val) {
for (size_t i = 0; i < k; i++) {
minheap_push(i + 1, heap_val, heap_ids, x[i], i);
}
Expand All @@ -52,19 +55,19 @@ void addn_replace(
}

void addn_func(
size_t n, size_t k,
const float *x, int64_t *heap_ids, float * heap_val)
{
size_t n,
size_t k,
const float* x,
int64_t* heap_ids,
float* heap_val) {
minheap_heapify(k, heap_val, heap_ids);

minheap_addn(k, heap_val, heap_ids, x, nullptr, n);

minheap_reorder(k, heap_val, heap_ids);
}


int main() {

size_t n = 10 * 1000 * 1000;

std::vector<size_t> ks({20, 50, 100, 200, 500, 1000, 2000, 5000});
Expand All @@ -73,14 +76,13 @@ int main() {
float_randn(x.data(), n, 12345);

int nrun = 100;
for(size_t k: ks) {
for (size_t k : ks) {
printf("benchmark with k=%zd n=%zd nrun=%d\n", k, n, nrun);
FAISS_THROW_IF_NOT(k < n);

double tot_t1 = 0, tot_t2 = 0, tot_t3 = 0;
#pragma omp parallel reduction(+: tot_t1, tot_t2, tot_t3)
#pragma omp parallel reduction(+ : tot_t1, tot_t2, tot_t3)
{

std::vector<float> heap_dis(k);
std::vector<float> heap_dis_2(k);
std::vector<float> heap_dis_3(k);
Expand All @@ -91,7 +93,6 @@ int main() {

#pragma omp for
for (int run = 0; run < nrun; run++) {

double t0, t1, t2, t3;

t0 = getmillisecs();
Expand All @@ -101,7 +102,8 @@ int main() {
t1 = getmillisecs();

// new implem from Zilliz
addn_replace(n, k, x.data(), heap_ids_2.data(), heap_dis_2.data());
addn_replace(
n, k, x.data(), heap_ids_2.data(), heap_dis_2.data());
t2 = getmillisecs();

// with addn
Expand All @@ -115,10 +117,13 @@ int main() {

for (size_t i = 0; i < k; i++) {
FAISS_THROW_IF_NOT_FMT(
heap_ids[i] == heap_ids_2[i],
"i=%ld (%ld, %g) != (%ld, %g)",
i, size_t(heap_ids[i]), heap_dis[i],
size_t(heap_ids_2[i]), heap_dis_2[i]);
heap_ids[i] == heap_ids_2[i],
"i=%ld (%ld, %g) != (%ld, %g)",
i,
size_t(heap_ids[i]),
heap_dis[i],
size_t(heap_ids_2[i]),
heap_dis_2[i]);
FAISS_THROW_IF_NOT(heap_dis[i] == heap_dis_2[i]);
}

Expand All @@ -130,7 +135,6 @@ int main() {
printf("default implem: %.3f ms\n", tot_t1 / nrun);
printf("replace implem: %.3f ms\n", tot_t2 / nrun);
printf("addn implem: %.3f ms\n", tot_t3 / nrun);

}
return 0;
}
69 changes: 50 additions & 19 deletions c_api/AutoTune_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// Copyright 2004-present Facebook. All Rights Reserved.
// -*- c++ -*-

#include <cstring>
#include <faiss/AutoTune.h>
#include "AutoTune_c.h"
#include <faiss/AutoTune.h>
#include <cstring>
#include "macros_impl.h"

using faiss::Index;
Expand All @@ -21,7 +21,10 @@ const char* faiss_ParameterRange_name(const FaissParameterRange* range) {
return reinterpret_cast<const ParameterRange*>(range)->name.c_str();
}

void faiss_ParameterRange_values(FaissParameterRange* range, double** p_values, size_t* p_size) {
void faiss_ParameterRange_values(
FaissParameterRange* range,
double** p_values,
size_t* p_size) {
auto& values = reinterpret_cast<ParameterRange*>(range)->values;
*p_values = values.data();
*p_size = values.size();
Expand All @@ -31,7 +34,8 @@ int faiss_ParameterSpace_new(FaissParameterSpace** space) {
try {
auto new_space = new ParameterSpace();
*space = reinterpret_cast<FaissParameterSpace*>(new_space);
} CATCH_AND_HANDLE
}
CATCH_AND_HANDLE
}

DEFINE_DESTRUCTOR(ParameterSpace)
Expand All @@ -40,44 +44,71 @@ size_t faiss_ParameterSpace_n_combinations(const FaissParameterSpace* space) {
return reinterpret_cast<const ParameterSpace*>(space)->n_combinations();
}

int faiss_ParameterSpace_combination_name(const FaissParameterSpace* space, size_t cno, char* char_buffer, size_t size) {
int faiss_ParameterSpace_combination_name(
const FaissParameterSpace* space,
size_t cno,
char* char_buffer,
size_t size) {
try {
auto rep = reinterpret_cast<const ParameterSpace*>(space)->combination_name(cno);
auto rep = reinterpret_cast<const ParameterSpace*>(space)
->combination_name(cno);
strncpy(char_buffer, rep.c_str(), size);
} CATCH_AND_HANDLE
}
CATCH_AND_HANDLE
}

int faiss_ParameterSpace_set_index_parameters(const FaissParameterSpace* space, FaissIndex* cindex, const char* param_string) {
int faiss_ParameterSpace_set_index_parameters(
const FaissParameterSpace* space,
FaissIndex* cindex,
const char* param_string) {
try {
auto index = reinterpret_cast<Index*>(cindex);
reinterpret_cast<const ParameterSpace*>(space)->set_index_parameters(index, param_string);
} CATCH_AND_HANDLE
reinterpret_cast<const ParameterSpace*>(space)->set_index_parameters(
index, param_string);
}
CATCH_AND_HANDLE
}

/// set a combination of parameters on an index
int faiss_ParameterSpace_set_index_parameters_cno(const FaissParameterSpace* space, FaissIndex* cindex, size_t cno) {
int faiss_ParameterSpace_set_index_parameters_cno(
const FaissParameterSpace* space,
FaissIndex* cindex,
size_t cno) {
try {
auto index = reinterpret_cast<Index*>(cindex);
reinterpret_cast<const ParameterSpace*>(space)->set_index_parameters(index, cno);
} CATCH_AND_HANDLE
reinterpret_cast<const ParameterSpace*>(space)->set_index_parameters(
index, cno);
}
CATCH_AND_HANDLE
}

int faiss_ParameterSpace_set_index_parameter(const FaissParameterSpace* space, FaissIndex* cindex, const char * name, double value) {
int faiss_ParameterSpace_set_index_parameter(
const FaissParameterSpace* space,
FaissIndex* cindex,
const char* name,
double value) {
try {
auto index = reinterpret_cast<Index*>(cindex);
reinterpret_cast<const ParameterSpace*>(space)->set_index_parameter(index, name, value);
} CATCH_AND_HANDLE
reinterpret_cast<const ParameterSpace*>(space)->set_index_parameter(
index, name, value);
}
CATCH_AND_HANDLE
}

void faiss_ParameterSpace_display(const FaissParameterSpace* space) {
reinterpret_cast<const ParameterSpace*>(space)->display();
}

int faiss_ParameterSpace_add_range(FaissParameterSpace* space, const char* name, FaissParameterRange** p_range) {
int faiss_ParameterSpace_add_range(
FaissParameterSpace* space,
const char* name,
FaissParameterRange** p_range) {
try {
ParameterRange& range = reinterpret_cast<ParameterSpace*>(space)->add_range(name);
ParameterRange& range =
reinterpret_cast<ParameterSpace*>(space)->add_range(name);
if (p_range) {
*p_range = reinterpret_cast<FaissParameterRange*>(&range);
}
} CATCH_AND_HANDLE
}
CATCH_AND_HANDLE
}
Loading

0 comments on commit e86bf8c

Please sign in to comment.