Skip to content

Commit f0e5ffd

Browse files
authored
Merge pull request #81 from AntonisZks/Antonis_workstation
Project Structure Reorganization and Separate Compilation
2 parents 4782522 + d09c0df commit f0e5ffd

38 files changed

+2188
-1304
lines changed

.github/workflows/unit_tests.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ jobs:
2121
with:
2222
node-version: 16.18
2323

24-
- name: Compile Code and Run Unit Tests
24+
- name: Compile Code
2525
run:
26-
make test
26+
make all
27+
28+
- name : Run Unit Tests
29+
run:
30+
make run_tests
2731

2832
- name: Clean up workspace
2933
run:

Makefile

Lines changed: 77 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,96 +9,103 @@ OBJ_DIR = build
99
EXE_DIR = bin
1010
TST_DIR = tests
1111

12-
# make all builds everything
13-
all: code test
12+
# Locate all the .cpp files in the src directory
13+
SRC_FILES := $(shell find $(SRC_DIR) -name '*.cpp')
14+
OBJS := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRC_FILES))
1415

15-
# Compile only the main code
16-
code: build bin $(EXE_DIR)/main $(EXE_DIR)/main2
16+
# Define the test executables
17+
UNIT_TEST_SRCS := $(wildcard $(TST_DIR)/*.cc)
18+
UNIT_TESTS := $(patsubst $(TST_DIR)/%.cc, $(EXE_DIR)/%, $(UNIT_TEST_SRCS))
1719

18-
# Compile all test executables
19-
test: build bin $(EXE_DIR)/graph_node_test $(EXE_DIR)/graph_test $(EXE_DIR)/test_distance $(EXE_DIR)/test_data_vectors $(EXE_DIR)/test_recall
20-
@echo "Running all tests:"
21-
$(EXE_DIR)/graph_node_test
22-
$(EXE_DIR)/graph_test
23-
$(EXE_DIR)/test_distance
24-
$(EXE_DIR)/test_data_vectors
25-
$(EXE_DIR)/test_recall
20+
# Define the application executables
21+
TARGET_SIMPLE_VAMANA = $(EXE_DIR)/simple_vamana
22+
TARGET_FILTERED_VAMANA = $(EXE_DIR)/filtered_vamana
2623

27-
# Run tests with valgrind
28-
valgrind: test
29-
valgrind --leak-check=full $(EXE_DIR)/graph_node_test
30-
valgrind --leak-check=full $(EXE_DIR)/graph_test
31-
valgrind --leak-check=full $(EXE_DIR)/test_distance
32-
valgrind --leak-check=full $(EXE_DIR)/test_data_vectors
33-
valgrind --leak-check=full $(EXE_DIR)/test_recall
24+
# Default targets
25+
all: app tests
3426

35-
# Define the rule for the main executable
36-
$(EXE_DIR)/main: $(OBJ_DIR)/main.o $(OBJ_DIR)/read_vectors.o $(OBJ_DIR)/distance_functions.o
37-
$(CC) $(FLAGS) -o $(EXE_DIR)/main $(OBJ_DIR)/main.o $(OBJ_DIR)/read_vectors.o $(OBJ_DIR)/distance_functions.o
27+
app: $(TARGET_SIMPLE_VAMANA) $(TARGET_FILTERED_VAMANA)
28+
tests: $(UNIT_TESTS)
3829

39-
$(OBJ_DIR)/main.o: main.cpp $(INC_DIR)/DataStructures/Graph/graph.h $(INC_DIR)/read_data.h $(INC_DIR)/DataStructures/DataVector/DataVector.h
40-
$(CC) $(FLAGS) -o $(OBJ_DIR)/main.o -c main.cpp
30+
# Compile the first executable and its dependencies (objects)
31+
$(TARGET_SIMPLE_VAMANA): $(OBJS) $(OBJ_DIR)/simple_vamana_main.o
32+
@mkdir -p $(EXE_DIR)
33+
$(CC) $(FLAGS) $(OBJS) $(OBJ_DIR)/simple_vamana_main.o -o $@
4134

42-
$(EXE_DIR)/main2: $(OBJ_DIR)/main2.o $(OBJ_DIR)/read_vectors.o $(OBJ_DIR)/distance_functions.o
43-
$(CC) $(FLAGS) -o $(EXE_DIR)/main2 $(OBJ_DIR)/main2.o $(OBJ_DIR)/read_vectors.o $(OBJ_DIR)/distance_functions.o
35+
$(OBJ_DIR)/simple_vamana_main.o: app/simple_vamana_main.cpp
36+
@mkdir -p $(OBJ_DIR)
37+
$(CC) $(FLAGS) -c $< -o $@
4438

45-
$(OBJ_DIR)/main2.o: main2.cpp $(INC_DIR)/DataStructures/Graph/graph.h $(INC_DIR)/read_data.h $(INC_DIR)/DataStructures/DataVector/DataVector.h
46-
$(CC) $(FLAGS) -o $(OBJ_DIR)/main2.o -c main2.cpp
39+
# Compile the second executable and its dependencies (objects)
40+
$(TARGET_FILTERED_VAMANA): $(OBJS) $(OBJ_DIR)/filtered_vamana_main.o
41+
@mkdir -p $(EXE_DIR)
42+
$(CC) $(FLAGS) $(OBJS) $(OBJ_DIR)/filtered_vamana_main.o -o $@
4743

48-
# Rule to create read_vectors.o
49-
$(OBJ_DIR)/read_vectors.o: $(SRC_DIR)/read_vectors.cpp $(INC_DIR)/read_data.h $(INC_DIR)/DataStructures/DataVector/DataVector.h
50-
$(CC) $(FLAGS) -o $(OBJ_DIR)/read_vectors.o -c $(SRC_DIR)/read_vectors.cpp
44+
$(OBJ_DIR)/filtered_vamana_main.o: app/filtered_vamana_main.cpp
45+
@mkdir -p $(OBJ_DIR)
46+
$(CC) $(FLAGS) -c $< -o $@
5147

52-
# Rule to create distance_functions.o
53-
$(OBJ_DIR)/distance_functions.o: $(SRC_DIR)/distance_functions.cpp $(INC_DIR)/distance.h
54-
$(CC) $(FLAGS) -o $(OBJ_DIR)/distance_functions.o -c $(SRC_DIR)/distance_functions.cpp
48+
# Compile the objects in the src directory
49+
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
50+
@mkdir -p $(dir $@)
51+
$(CC) $(FLAGS) -c $< -o $@
5552

56-
# Test executables and object file rules
53+
# Compile the test executables and their dependencies
54+
$(EXE_DIR)/%: $(OBJ_DIR)/%.o $(OBJS)
55+
@mkdir -p $(EXE_DIR)
56+
$(CC) $(FLAGS) $< $(OBJS) -o $@
5757

58-
# Build graph_node_test executable
59-
$(EXE_DIR)/graph_node_test: $(OBJ_DIR)/graph_node_test.o
60-
$(CC) $(FLAGS) -o $(EXE_DIR)/graph_node_test $(OBJ_DIR)/graph_node_test.o
58+
$(OBJ_DIR)/%.o: $(TST_DIR)/%.cc
59+
@mkdir -p $(OBJ_DIR)
60+
$(CC) $(FLAGS) -c $< -o $@
6161

62-
$(OBJ_DIR)/graph_node_test.o: $(TST_DIR)/graph_node_test.cc $(INC_DIR)/acutest.h $(INC_DIR)/DataStructures/Graph/graph_node.h
63-
$(CC) $(FLAGS) -o $(OBJ_DIR)/graph_node_test.o -c $(TST_DIR)/graph_node_test.cc
62+
# Clean the object files
63+
clean:
64+
rm -rf $(OBJ_DIR) $(EXE_DIR)
6465

65-
# Build graph_test executable
66-
$(EXE_DIR)/graph_test: $(OBJ_DIR)/graph_test.o
67-
$(CC) $(FLAGS) -o $(EXE_DIR)/graph_test $(OBJ_DIR)/graph_test.o
66+
# Dependency generation
67+
DEPFLAGS = -MMD -MP
68+
FLAGS += $(DEPFLAGS)
6869

69-
$(OBJ_DIR)/graph_test.o: $(TST_DIR)/graph_test.cc $(INC_DIR)/acutest.h $(INC_DIR)/DataStructures/Graph/graph.h
70-
$(CC) $(FLAGS) -o $(OBJ_DIR)/graph_test.o -c $(TST_DIR)/graph_test.cc
70+
-include $(OBJS:.o=.d)
71+
-include $(OBJ_DIR)/simple_vamana_main.d
72+
-include $(OBJ_DIR)/filtered_vamana_main.d
7173

72-
# Build test_distance executable
73-
$(EXE_DIR)/test_distance: $(OBJ_DIR)/test_distance.o $(OBJ_DIR)/distance_functions.o
74-
$(CC) $(FLAGS) -o $(EXE_DIR)/test_distance $(OBJ_DIR)/test_distance.o $(OBJ_DIR)/distance_functions.o
7574

76-
$(OBJ_DIR)/test_distance.o: $(TST_DIR)/test_distance.cc $(INC_DIR)/acutest.h $(INC_DIR)/distance.h
77-
$(CC) $(FLAGS) -o $(OBJ_DIR)/test_distance.o -c $(TST_DIR)/test_distance.cc
7875

79-
# Build test_data_vectors executable
80-
$(EXE_DIR)/test_data_vectors: $(OBJ_DIR)/test_data_vectors.o $(OBJ_DIR)/read_vectors.o
81-
$(CC) $(FLAGS) -o $(EXE_DIR)/test_data_vectors $(OBJ_DIR)/test_data_vectors.o $(OBJ_DIR)/read_vectors.o
76+
# Execution Rules
8277

83-
$(OBJ_DIR)/test_data_vectors.o: $(TST_DIR)/test_data_vectors.cc $(INC_DIR)/acutest.h $(INC_DIR)/read_data.h
84-
$(CC) $(FLAGS) -o $(OBJ_DIR)/test_data_vectors.o -c $(TST_DIR)/test_data_vectors.cc
78+
create_simple_vamana:
79+
./bin/simple_vamana --create -base-file 'data/siftsmall/siftsmall_base.fvecs' -L 20 -R 14 -alpha 1.0 -save 'index.bin'
8580

86-
# Build test_recall executable
87-
$(EXE_DIR)/test_recall: $(OBJ_DIR)/test_recall.o
88-
$(CC) $(FLAGS) -o $(EXE_DIR)/test_recall $(OBJ_DIR)/test_recall.o
81+
create_simple_vamana_valgrind:
82+
valgrind --leak-check=full ./bin/simple_vamana --create -base-file 'data/siftsmall/siftsmall_base.fvecs' -L 10 -R 14 -alpha 1.0 -save 'index.bin'
8983

90-
$(OBJ_DIR)/test_recall.o: $(TST_DIR)/test_recall.cc $(INC_DIR)/acutest.h $(INC_DIR)/Evaluation/recall.h
91-
$(CC) $(FLAGS) -o $(OBJ_DIR)/test_recall.o -c $(TST_DIR)/test_recall.cc
9284

93-
# Directories creation
94-
build:
95-
mkdir -p $(OBJ_DIR)
85+
test_simple_vamana:
86+
./bin/simple_vamana --test -load 'index.bin' -k 100 -L 120 -gt-file 'data/siftsmall/siftsmall_groundtruth.ivecs' -query-file 'data/siftsmall/siftsmall_query.fvecs' -query 0
9687

97-
bin:
98-
mkdir -p $(EXE_DIR)
88+
test_simple_vamana_valgrind:
89+
valgrind --leak-check=full ./bin/simple_vamana --test -load 'index.bin' -k 100 -L 10 -gt-file 'data/siftsmall/siftsmall_groundtruth.ivecs' -query-file 'data/siftsmall/siftsmall_query.fvecs' -query 0
9990

100-
# Clean command to clean the workspace
101-
.PHONY: clean
102-
clean:
103-
rm -r -f $(EXE_DIR)
104-
rm -r -f $(OBJ_DIR)
91+
92+
create_filtered_vamana:
93+
./bin/filtered_vamana
94+
95+
create_filtered_vamana_valgrind:
96+
./bin/filtered_vamana
97+
98+
99+
run_tests:
100+
./bin/graph_node_test
101+
./bin/graph_test
102+
./bin/test_distance
103+
./bin/test_data_vectors
104+
./bin/test_recall
105+
106+
run_tests_valgrind:
107+
valgrind --leak-check=full ./bin/graph_node_test
108+
valgrind --leak-check=full ./bin/graph_test
109+
valgrind --leak-check=full ./bin/test_distance
110+
valgrind --leak-check=full ./bin/test_data_vectors
111+
valgrind --leak-check=full ./bin/test_recall

main2.cpp renamed to app/filtered_vamana_main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <iostream>
22
#include <vector>
33
#include <algorithm>
4-
#include "include/DataStructures/DataVector/BQDataVectors.h"
5-
#include "include/read_data.h"
6-
#include "include/distance.h"
4+
#include "../include/BQDataVectors.h"
5+
#include "../include/read_data.h"
6+
#include "../include/distance.h"
77
#include <fstream>
88

99
/**

main.cpp renamed to app/simple_vamana_main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include <string>
66
#include <cstdlib>
77
#include <ctime>
8-
#include "include/DataStructures/DataVector/DataVector.h"
9-
#include "include/Algorithms/VamanaIndex.h"
10-
#include "include/read_data.h"
11-
#include "include/DataStructures/DataVector/BQDataVectors.h"
8+
#include "../include/DataVector.h"
9+
#include "../include/VamanaIndex.h"
10+
#include "../include/read_data.h"
11+
#include "../include/BQDataVectors.h"
1212

1313
using ParametersMap = std::map<std::string, std::string>;
1414
using BaseVectors = std::vector<DataVector<float>>;

include/Algorithms/RobustPrune.h

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)