Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*~
37 changes: 29 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
CXX ?= g++
CXXFLAGS ?= -Wall -O3 -ffast-math -funroll-loops
CXX ?= g++ #CXX will always be set!
CXXFLAGS ?= -O3 -ffast-math -funroll-loops

all: test
CXXFLAGS+=-std=c++14 -Wall

Cover_Tree_Point.o: Cover_Tree_Point.h Cover_Tree_Point.cc
$(CXX) -c $(CXXFLAGS) Cover_Tree_Point.cc
TEST_SRCS = $(wildcard test_*.cpp)
TEST_APPS = $(TEST_SRCS:%.cpp=%)

test: test.cc Cover_Tree.h Cover_Tree_Point.o Cover_Tree_Point.h Cover_Tree_Point.cc
$(CXX) test.cc $(CXXFLAGS) -o test Cover_Tree_Point.o
all: tests

catch.o : catch.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $^

test_clear_method: test_clear_method.o Cover_Tree_Point.o catch.o
$(CXX) $(CXXFLAGS) -o $@ $^

test_tree: test_tree.o Cover_Tree_Point.o catch.o
$(CXX) $(CXXFLAGS) -o $@ $^

bench_tree: bench_tree.o Cover_Tree_Point.o catch.o
$(CXX) $(CXXFLAGS) -o $@ $^

tests: $(TEST_APPS)

test_run: $(TEST_APPS)
@$(foreach item,$(TEST_APPS),echo $(item);./$(item);)

benchmark_run:
@./bench_tree

clean:
rm *.o test
rm *.o test_*

.PRECIOUS: catch.o
61 changes: 61 additions & 0 deletions bench_tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "catch.hpp"

#include "cover_tree.hpp"
#include "example_point.hpp"
#include <vector>
#include <random>


TEST_CASE( "bigtest" ) {
std::size_t numDimensions = 50;
std::size_t numNodes = 3000;

std::mt19937 gen(1307);
std::uniform_real_distribution<> dis(0,1.);

std::vector<example_point> points;
std::vector<double> a(numDimensions,0);

BENCHMARK("random-create-vector"){
for(unsigned int i=0;i<numNodes;i++) {
for(unsigned int j=0;j<numDimensions;j++) {
a[j] = (dis(gen));
}
points.push_back(example_point(a,'a'));
}
}

CoverTree<example_point> insert_me;
BENCHMARK("inserts"){
for(const auto& p : points) {
insert_me.insert(p);
}
}
REQUIRE(insert_me.isValidTree());
REQUIRE(insert_me.size() != 0);
REQUIRE(insert_me.size() == points.size());


CoverTree<example_point> cTree(points);

REQUIRE(cTree.isValidTree());

BENCHMARK("nearest-neighbor"){
for(int i=0;i<2000;i++) {
for(unsigned int j=0;j<numDimensions;j++) {
a[j] = (dis(gen));
}
cTree.kNearestNeighbors(example_point(a,'a'),1);
}
}
REQUIRE(cTree.isValidTree());

BENCHMARK("remove-all"){
for(unsigned int i=0; i<numNodes; i++) {
cTree.remove(points[i]);
}
}

REQUIRE(cTree.isValidTree());

}
2 changes: 1 addition & 1 deletion Cover_Tree_Point.cc → c++03/Cover_Tree_Point.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ double CoverTreePoint::distance(const CoverTreePoint& p) const {
const vector<double>& vec=p.getVec();
double dist=0;
size_t lim = vec.size();
for(int i=0; i<lim;i++) {
for(size_t i=0; i<lim;i++) {
double d = vec[i]-_vec[i];
dist+=d*d;
}
Expand Down
File renamed without changes.
17 changes: 17 additions & 0 deletions c++03/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CXX ?= g++ #CXX will always be set!
CXXFLAGS ?= -O3 -ffast-math -funroll-loops

CXXFLAGS+=-Wall

all: test

Cover_Tree_Point.o: Cover_Tree_Point.h Cover_Tree_Point.cc
$(CXX) -c $(CXXFLAGS) Cover_Tree_Point.cc

test: test.cc Cover_Tree.h Cover_Tree_Point.o Cover_Tree_Point.h Cover_Tree_Point.cc
$(CXX) test.cc $(CXXFLAGS) -o test Cover_Tree_Point.o

clean:
rm *.o test

.PRECIOUS: catch.o
File renamed without changes.
2 changes: 2 additions & 0 deletions catch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
Loading