Browse Source

fix format

master
Chen Lixiang 1 year ago
parent
commit
72b74fd017
4 changed files with 16 additions and 13 deletions
  1. +3
    -1
      README.md
  2. +0
    -1
      inc/hnsw.h
  3. +11
    -9
      inc/utils.h
  4. +2
    -2
      src/test.c

+ 3
- 1
README.md View File

@ -57,7 +57,6 @@ Benchmark started......
Recall value: 1.0000
```
## 2. 开发任务
主要任务为基于 HNSW 算法实现 `src/hnsw.h``src/hnsw.c` 中的两个函数:
@ -71,6 +70,9 @@ void hnsw_approximate_knn(HNSWContext *ctx, VecData *q, int *results, int k); //
我们已经在 `hnsw_init_context` 中实现了源数据的导入,另外在 `hnsw_approximate_knn` 中实现了一个简单的 KNN 算法以供参考。目前的实现仅能通过 SIFT SMALL 数据集的测试。
由于 HNSW 的实现需要例如优先队列、集合这样的数据结构辅助,你也可以引入 C++ STL 以提高你的编码效率。
## 3. 数据集下载
SIFT 数据集可以在以下网站中下载: http://corpus-texmex.irisa.fr/

+ 0
- 1
inc/hnsw.h View File

@ -20,7 +20,6 @@ typedef struct HNSWContext
// you can declare some help functions here, and implement them in 'hnsw.c'
// public functions here
// Please do not modify these function signatures!
// To simply our program, we do not consider reclaiming memory space here.

+ 11
- 9
inc/utils.h View File

@ -4,20 +4,22 @@
#define GLOBAL_DIM 128
typedef struct {
typedef struct
{
int id;
float* vec;
float *vec;
} VecData;
typedef struct {
FILE* stream;
typedef struct
{
FILE *stream;
char *filename;
int offset;
} FileContext;
float vec_dist(VecData x, VecData y);
FileContext* init_file_context(const char *filename);
void read_4bytes(FileContext* ctx, void* dst);
void read_vec_data(FileContext* ctx, void* dst);
void read_id_data(FileContext* ctx, void* dst, size_t n);
void free_file_context(FileContext* ctx);
FileContext *init_file_context(const char *filename);
void read_4bytes(FileContext *ctx, void *dst);
void read_vec_data(FileContext *ctx, void *dst);
void read_id_data(FileContext *ctx, void *dst, size_t n);
void free_file_context(FileContext *ctx);

+ 2
- 2
src/test.c View File

@ -46,7 +46,7 @@ int main(int argc, char *argv[])
HNSWContext *ctx = hnsw_init_context(argv[1], GLOBAL_DIM, data_size);
end = clock();
printf("HNSW Context Initialied OK!\n");
printf("HNSW initialization cost: %.4f seconds\n", ((float) (end - start)) / CLOCKS_PER_SEC);
printf("HNSW initialization cost: %.4f seconds\n", ((float)(end - start)) / CLOCKS_PER_SEC);
VecData q_vec;
q_vec.vec = (float *)malloc(sizeof(float) * GLOBAL_DIM);
int q_results[K];
@ -62,7 +62,7 @@ int main(int argc, char *argv[])
start = clock();
hnsw_approximate_knn(ctx, &q_vec, q_results, K);
end = clock();
query_cost += ((float) (end - start)) / CLOCKS_PER_SEC;
query_cost += ((float)(end - start)) / CLOCKS_PER_SEC;
total_recall_values += cal_recall_value(q_results, true_results, K);
}

Loading…
Cancel
Save