ソースを参照

fix format

master
Chen Lixiang 1年前
コミット
dfdaa316dc
3個のファイルの変更15行の追加11行の削除
  1. +7
    -3
      README.md
  2. +4
    -4
      src/hnsw.c
  3. +4
    -4
      src/test.c

+ 7
- 3
README.md ファイルの表示

@ -35,17 +35,21 @@
./hnsw_test ../dataset/siftsmall/siftsmall_base.fvecs 10000 ../dataset/siftsmall/siftsmall_query.fvecs 100 ../dataset/siftsmall/siftsmall_groundtruth.ivecs
```
Our test program will report the recall value and time costs of your algorithm.
### 2. Mission Description
You need to implement two functions inside hnsw.h and hnsw.c in HNSW way:
```C
HNSWContext *hnsw_init_context(const char *filename, size_t dim, size_t len);
void hnsw_approximate_knn(HNSWContext *ctx, VecData *q, int *results, int k);
HNSWContext *hnsw_init_context(const char *filename, size_t dim, size_t len); // load data and build graph
void hnsw_approximate_knn(HNSWContext *ctx, VecData *q, int *results, int k); // search KNN results
```
We have implemented data loading and provided a simplest KNN algorithm. But our implementation can only handle small batches of data(SIFTSMALL dataset), please implement a new approximate KNN algorithm based on the HNSW algorithm so that it can handle large batches of data(SIFT dataset).
We have implemented data loading and provided a simplest KNN algorithm. But our implementation can only handle small batches of data(SIFTSMALL dataset), please implement a new approximate KNN algorithm based on the HNSW algorithm so that it can handle large batches of data(SIFT dataset) efficiently.
### 3. Data Download
Please visit http://corpus-texmex.irisa.fr/
TODO: We should provide a script to download datasets automatically

+ 4
- 4
src/hnsw.c ファイルの表示

@ -3,18 +3,18 @@
HNSWContext *hnsw_init_context(const char *filename, size_t dim, size_t len)
{
HNSWContext *ctx = (HNSWContext *) malloc(sizeof(HNSWContext));
HNSWContext *ctx = (HNSWContext *)malloc(sizeof(HNSWContext));
ctx->dim = dim;
ctx->len = len;
ctx->data = (VecData *) malloc(sizeof(VecData) * len);
ctx->data = (VecData *)malloc(sizeof(VecData) * len);
// init file context
FileContext* f_ctx = init_file_context(filename);
FileContext *f_ctx = init_file_context(filename);
for (int i = 0; i < len; i++)
{
ctx->data[i].id = i;
ctx->data[i].vec = (float *) malloc(sizeof(float) * GLOBAL_DIM);
ctx->data[i].vec = (float *)malloc(sizeof(float) * GLOBAL_DIM);
read_vec_data(f_ctx, ctx->data[i].vec);
}

+ 4
- 4
src/test.c ファイルの表示

@ -21,7 +21,7 @@ float cal_recall_value(int *results, int *trueset, int k)
}
}
return ((float) cnt) / ((float) k);
return ((float)cnt) / ((float)k);
}
int main(int argc, char *argv[])
@ -43,10 +43,10 @@ int main(int argc, char *argv[])
// TODO: report time cost here
HNSWContext* ctx = hnsw_init_context(argv[1], GLOBAL_DIM, data_size);
HNSWContext *ctx = hnsw_init_context(argv[1], GLOBAL_DIM, data_size);
printf("HNSW context initialized!\n");
VecData q_vec;
q_vec.vec = (float *) malloc(sizeof(float) * GLOBAL_DIM);
q_vec.vec = (float *)malloc(sizeof(float) * GLOBAL_DIM);
int q_results[100];
int true_results[100];
float total_recall_values = 0.0;
@ -59,7 +59,7 @@ int main(int argc, char *argv[])
}
// report recall value
printf("Recall value: %.4f\n", total_recall_values / ((float) query_size));
printf("Recall value: %.4f\n", total_recall_values / ((float)query_size));
free_file_context(query_file_ctx);
free_file_context(gt_file_ctx);

読み込み中…
キャンセル
保存