Mercurial > hg > audiodb
comparison query.cpp @ 214:3254b15472f3 refactoring
set_up_query()
Sets up the query data (from mmap()ed file).
author | mas01cr |
---|---|
date | Tue, 04 Dec 2007 09:40:55 +0000 |
parents | 1292c2e37734 |
children | 241bc55a1a4e |
comparison
equal
deleted
inserted
replaced
213:78a144448bda | 214:3254b15472f3 |
---|---|
163 } | 163 } |
164 | 164 |
165 read(dbfid, *data_buffer_p, trackTable[track] * sizeof(double) * dbH->dim); | 165 read(dbfid, *data_buffer_p, trackTable[track] * sizeof(double) * dbH->dim); |
166 } | 166 } |
167 | 167 |
168 void audioDB::trackSequenceQueryNN(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){ | 168 void audioDB::set_up_query(double **qp, double **qnp, unsigned *nvp) { |
169 | 169 *nvp = (statbuf.st_size - sizeof(int)) / (dbH->dim * sizeof(double)); |
170 initTables(dbName, inFile); | 170 |
171 | 171 if(!(dbH->flags & O2_FLAG_L2NORM)) { |
172 // For each input vector, find the closest pointNN matching output vectors and report | |
173 // we use stdout in this stub version | |
174 unsigned numVectors = (statbuf.st_size-sizeof(int))/(sizeof(double)*dbH->dim); | |
175 double* query = (double*)(indata+sizeof(int)); | |
176 double* queryCopy = 0; | |
177 | |
178 if(!(dbH->flags & O2_FLAG_L2NORM) ) | |
179 error("Database must be L2 normed for sequence query","use -L2NORM"); | 172 error("Database must be L2 normed for sequence query","use -L2NORM"); |
180 | 173 } |
181 if(numVectors<sequenceLength) | 174 |
175 if(*nvp < sequenceLength) { | |
182 error("Query shorter than requested sequence length", "maybe use -l"); | 176 error("Query shorter than requested sequence length", "maybe use -l"); |
177 } | |
183 | 178 |
184 if(verbosity>1) { | 179 if(verbosity>1) { |
185 std::cerr << "performing norms ... "; std::cerr.flush(); | 180 std::cerr << "performing norms ... "; std::cerr.flush(); |
186 } | 181 } |
182 | |
183 *qp = new double[*nvp * dbH->dim]; | |
184 memcpy(*qp, indata+sizeof(int), *nvp * dbH->dim * sizeof(double)); | |
185 *qnp = new double[*nvp]; | |
186 unitNorm(*qp, dbH->dim, *nvp, *qnp); | |
187 } | |
188 | |
189 void audioDB::trackSequenceQueryNN(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){ | |
190 | |
191 initTables(dbName, inFile); | |
192 | |
193 unsigned int numVectors; | |
194 double *query, *query_data; | |
195 double *qNorm, *sNorm; | |
196 | |
197 set_up_query(&query, &qNorm, &numVectors); | |
198 query_data = query; | |
199 | |
187 unsigned dbVectors = dbH->length/(sizeof(double)*dbH->dim); | 200 unsigned dbVectors = dbH->length/(sizeof(double)*dbH->dim); |
188 | 201 |
189 // Make a copy of the query | |
190 queryCopy = new double[numVectors*dbH->dim]; | |
191 memcpy(queryCopy, query, numVectors*dbH->dim*sizeof(double)); | |
192 qNorm = new double[numVectors]; | |
193 sNorm = new double[dbVectors]; | 202 sNorm = new double[dbVectors]; |
194 assert(qNorm&&sNorm&&queryCopy&&sequenceLength); | |
195 unitNorm(queryCopy, dbH->dim, numVectors, qNorm); | |
196 query = queryCopy; | |
197 | 203 |
198 // Make norm measurements relative to sequenceLength | 204 // Make norm measurements relative to sequenceLength |
199 unsigned i,j; | 205 unsigned i,j; |
200 | 206 |
201 // Copy the L2 norm values to core to avoid disk random access later on | 207 // Copy the L2 norm values to core to avoid disk random access later on |
554 } | 560 } |
555 | 561 |
556 // Clean up | 562 // Clean up |
557 if(trackOffsetTable) | 563 if(trackOffsetTable) |
558 delete[] trackOffsetTable; | 564 delete[] trackOffsetTable; |
559 if(queryCopy) | 565 if(query_data) |
560 delete[] queryCopy; | 566 delete[] query_data; |
561 if(qNorm) | 567 if(qNorm) |
562 delete[] qNorm; | 568 delete[] qNorm; |
563 if(sNorm) | 569 if(sNorm) |
564 delete[] sNorm; | 570 delete[] sNorm; |
565 if(qPower) | 571 if(qPower) |
580 | 586 |
581 void audioDB::trackSequenceQueryRad(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){ | 587 void audioDB::trackSequenceQueryRad(const char* dbName, const char* inFile, adb__queryResponse *adbQueryResponse){ |
582 | 588 |
583 initTables(dbName, inFile); | 589 initTables(dbName, inFile); |
584 | 590 |
585 // For each input vector, find the closest pointNN matching output vectors and report | 591 unsigned int numVectors; |
586 // we use stdout in this stub version | 592 double *query, *query_data; |
587 unsigned numVectors = (statbuf.st_size-sizeof(int))/(sizeof(double)*dbH->dim); | 593 double *qNorm, *sNorm; |
588 double* query = (double*)(indata+sizeof(int)); | 594 |
589 double* queryCopy = 0; | 595 set_up_query(&query, &qNorm, &numVectors); |
590 | 596 query_data = query; |
591 if(!(dbH->flags & O2_FLAG_L2NORM) ) | 597 |
592 error("Database must be L2 normed for sequence query","use -l2norm"); | |
593 | |
594 if(verbosity>1) { | |
595 std::cerr << "performing norms ... "; std::cerr.flush(); | |
596 } | |
597 unsigned dbVectors = dbH->length/(sizeof(double)*dbH->dim); | 598 unsigned dbVectors = dbH->length/(sizeof(double)*dbH->dim); |
598 | 599 |
599 // Make a copy of the query | |
600 queryCopy = new double[numVectors*dbH->dim]; | |
601 memcpy(queryCopy, query, numVectors*dbH->dim*sizeof(double)); | |
602 qNorm = new double[numVectors]; | |
603 sNorm = new double[dbVectors]; | 600 sNorm = new double[dbVectors]; |
604 assert(qNorm&&sNorm&&queryCopy&&sequenceLength); | |
605 unitNorm(queryCopy, dbH->dim, numVectors, qNorm); | |
606 query = queryCopy; | |
607 | 601 |
608 // Make norm measurements relative to sequenceLength | 602 // Make norm measurements relative to sequenceLength |
609 unsigned i,j; | 603 unsigned i,j; |
610 | 604 |
611 // Copy the L2 norm values to core to avoid disk random access later on | 605 // Copy the L2 norm values to core to avoid disk random access later on |
943 } | 937 } |
944 | 938 |
945 // Clean up | 939 // Clean up |
946 if(trackOffsetTable) | 940 if(trackOffsetTable) |
947 delete[] trackOffsetTable; | 941 delete[] trackOffsetTable; |
948 if(queryCopy) | 942 if(query_data) |
949 delete[] queryCopy; | 943 delete[] query_data; |
950 if(qNorm) | 944 if(qNorm) |
951 delete[] qNorm; | 945 delete[] qNorm; |
952 if(sNorm) | 946 if(sNorm) |
953 delete[] sNorm; | 947 delete[] sNorm; |
954 if(qPower) | 948 if(qPower) |