51 void getArgs(
int argc,
char **argv);
63 for (
int i = 0; i <
dim; i++) {
64 if(!(in >> p[i]))
return false;
72 for (
int i = 1; i <
dim; i++) {
78 int main(
int argc,
char **argv)
96 cout <<
"Data Points:\n";
108 cout <<
"Query point: ";
118 cout <<
"\tNN:\tIndex\tDistance\n";
119 for (
int i = 0; i <
k; i++) {
120 dists[i] = sqrt(dists[i]);
121 cout <<
"\t" << i <<
"\t" << nnIdx[i] <<
"\t" << dists[i] <<
"\n";
136 void getArgs(
int argc,
char **argv)
138 static ifstream dataStream;
139 static ifstream queryStream;
143 <<
" ann_sample [-d dim] [-max m] [-nn k] [-e eps] [-df data]"
146 <<
" dim dimension of the space (default = 2)\n"
147 <<
" m maximum number of data points (default = 1000)\n"
148 <<
" k number of nearest neighbors per query (default 1)\n"
149 <<
" eps the error bound (default = 0.0)\n"
150 <<
" data name of file containing data points\n"
151 <<
" query name of file containing query points\n\n"
152 <<
" Results are sent to the standard output.\n"
154 <<
" To run this demo use:\n"
155 <<
" ann_sample -df data.pts -qf query.pts\n";
160 if (!strcmp(argv[i],
"-d")) {
161 dim = atoi(argv[++i]);
163 else if (!strcmp(argv[i],
"-max")) {
166 else if (!strcmp(argv[i],
"-nn")) {
169 else if (!strcmp(argv[i],
"-e")) {
170 sscanf(argv[++i],
"%lf", &
eps);
172 else if (!strcmp(argv[i],
"-df")) {
173 dataStream.open(argv[++i], ios::in);
175 cerr <<
"Cannot open data file\n";
180 else if (!strcmp(argv[i],
"-qf")) {
181 queryStream.open(argv[++i], ios::in);
183 cerr <<
"Cannot open query file\n";
189 cerr <<
"Unrecognized option.\n";
195 cerr <<
"-df and -qf options must be specified\n";
void annkSearch(ANNpoint q, int k, ANNidxArray nn_idx, ANNdistArray dd, double eps=0.0)
void getArgs(int argc, char **argv)
bool readPt(istream &in, ANNpoint p)
main(int argc, char **argv)
DLL_API ANNpoint annAllocPt(int dim, ANNcoord c=0)
void printPt(ostream &out, ANNpoint p)
DLL_API ANNpointArray annAllocPts(int n, int dim)