Use prepare query mode in dolphinn.
extern "C" {
-static int entry_length = 0;
+static int entry_length;
static int max_number_of_points = 0;
static int r = 0;
+static int dimModifier = 0;
bool configure(const char* var, const char* val) {
- if (strcmp(var, "entry_length") == 0) {
+ if (strcmp(var, "r") == 0) {
char* end;
errno = 0;
long k = strtol(val, &end, 10);
if (errno != 0 || *val == 0 || *end != 0 || k < 0) {
return false;
} else {
- entry_length = k;
+ r = k;
return true;
}
- } else if (strcmp(var, "r") == 0) {
+ } else if (strcmp(var, "modifier") == 0) {
char* end;
errno = 0;
long k = strtol(val, &end, 10);
if (errno != 0 || *val == 0 || *end != 0 || k < 0) {
return false;
} else {
- r = k;
+ dimModifier = k;
return true;
}
} else if (strcmp(var, "numpoints") == 0) {
@@ -52,17 +53,17 @@ bool configure(const char* var, const char* val) {
} else return false;
}
-static std::vector<float>* pointset = nullptr;
+static std::vector<double>* pointset = nullptr;
bool end_configure(void) {
- pointset = new std::vector<float>();
+ pointset = new std::vector<double>();
return true;
}
static size_t entry_count = 0;
-std::vector<float> parseEntry(const char* entry) {
- std::vector<float> e;
+std::vector<double> parseEntry(const char* entry) {
+ std::vector<double> e;
std::string line(entry);
double x;
auto sstr = std::istringstream(line);
@@ -74,19 +75,19 @@ std::vector<float> parseEntry(const char* entry) {
bool train(const char* entry) {
auto parsed_entry = parseEntry(entry);
- if (parsed_entry.size() != entry_length)
- return false;
pointset->insert(pointset->end(), parsed_entry.begin(), parsed_entry.end());
entry_count++;
return true;
}
-static Dolphinn::Hypercube<float, char>* hypercube = nullptr;
+static Dolphinn::Hypercube<double, char>* hypercube = nullptr;
static std::vector<std::vector<std::pair<int,float>>> results_distances(1);
+static std::vector<double> parsed_entry;
static size_t position = 0;
void end_train(void) {
- hypercube = new Dolphinn::Hypercube<float, char>(
+ entry_length = pointset->size() / entry_count;
+ hypercube = new Dolphinn::Hypercube<double, char>(
*pointset,
entry_count,
entry_length,
@@ -95,12 +96,14 @@ void end_train(void) {
r);
}
-size_t query(const char* entry, size_t k) {
- auto parsed_entry = parseEntry(entry);
+bool prepare_query(const char* entry) {
+ parsed_entry = parseEntry(entry);
position = 0;
- if (parsed_entry.size() != entry_length)
- return 0;
results_distances.clear();
+}
+
+
+size_t query(const char* entry, size_t k) {
results_distances[0].resize(k);
hypercube->m_nearest_neighbors_query(
parsed_entry,
