/
preprocess.cpp
72 lines (54 loc) · 1.59 KB
/
preprocess.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "constants.h"
#include "io.h"
#define DATASOURCE "tests/input.data"
#define DATATARGET "datads3.dat"
#define QUERYSOURCE "tests/exp_query.txt"
#define QUERYTARGET "query3.dat"
#include <sstream>
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
float data[datasize][D];
float query[querysize][D];
IO io;
void create_datafile() {
std::ifstream ifile(DATASOURCE);
// Load the points from the file and dump to data.dat
long long lineCount = 0;
for (std::string line; std::getline(ifile, line) && lineCount < datasize; ++lineCount) {
std::istringstream lineStream(line);
for (int i = 0; i < D; ++i) {
lineStream >> data[lineCount][i];
}
}
ifile.close();
// Write to disk
io.diskwrite_float(DATATARGET, data[0], datasize * D);
}
void create_queryfile() {
std::ifstream ifile(QUERYSOURCE);
// Load the points from the file and dump to data.dat
long long lineCount = 0;
// Temp variables to read unwanted info
int temp;
for (std::string line; std::getline(ifile, line) && lineCount < querysize; ++lineCount) {
std::istringstream lineStream(line);
// Read the query number
lineStream >> temp;
// Read the query point
for (int i = 0; i < D; ++i) {
lineStream >> query[lineCount][i];
}
// Read the value of k
lineStream >> temp;
}
ifile.close();
// Write to disk
io.diskwrite_float(QUERYTARGET, query[0], querysize * D);
}
int main() {
create_datafile();
// create_queryfile();
return 0;
}