changeset 538:02e0a9ecfd0f multiprobeLSH

Added back single-query point I/O behaviour from pre API-inversion. Thus only those query vectors required are loaded when using query-from-file. Tests 0006 and 0007 fail silently with this change.
author mas01mc
date Fri, 06 Feb 2009 21:08:35 +0000
parents eb5dd50dd7d1
children 06ed85832c3b
files audioDB-internals.h audioDB.cpp
diffstat 2 files changed, 27 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/audioDB-internals.h	Tue Feb 03 02:04:06 2009 +0000
+++ b/audioDB-internals.h	Fri Feb 06 21:08:35 2009 +0000
@@ -272,14 +272,11 @@
 }
 
 static inline uint32_t audiodb_index_to_track_id(adb_t *adb, uint32_t lshid){
-  std::vector<off_t>::iterator it_b = (*adb->track_offsets).begin();
-  std::vector<off_t>::iterator it_e = (*adb->track_offsets).end();  
-  off_t test_id = lshid*adb->header->dim*sizeof(double);
-  std::vector<off_t>::iterator point_p = std::lower_bound(it_b, it_e, test_id);
-  if(*point_p == test_id)
-    return point_p - it_b; // lshid is first point in found track  
-  else    
-    return point_p - it_b - 1; // lshid is a point in the previous track  
+  off_t offset = lshid*adb->header->dim*sizeof(double);
+  std::vector<off_t>::iterator b = (*adb->track_offsets).begin();
+  std::vector<off_t>::iterator e = (*adb->track_offsets).end();  
+  std::vector<off_t>::iterator p = std::upper_bound(b, e, offset);
+  return p - b - 1; 
 }
 
 static inline uint32_t audiodb_index_to_track_pos(adb_t *adb, uint32_t track_id, uint32_t lshid) {
--- a/audioDB.cpp	Tue Feb 03 02:04:06 2009 +0000
+++ b/audioDB.cpp	Fri Feb 06 21:08:35 2009 +0000
@@ -737,7 +737,7 @@
     }
   } while(!filesIn->eof());
 
-  VERB_LOG(0, "%s %s %u vectors %ju bytes.\n", COM_BATCHINSERT, dbName, totalVectors, (intmax_t) (totalVectors * dbH->dim * sizeof(double)));
+  VERB_LOG(0, "%s %s %u vectors %ju bytes.\n", COM_BATCHINSERT, dbName, totalVectors, (intmax_t) (totalVectors * adb->header->dim * sizeof(double)));
 
   delete [] thisPowerFileName;
   if(key && (key != inFile)) {
@@ -831,10 +831,19 @@
     }
     fstat(fd, &st);
     read(fd, &datum.dim, sizeof(uint32_t));
-    datum.nvectors = (st.st_size - sizeof(uint32_t)) / (datum.dim * sizeof(double));
-    datum.data = (double *) malloc(st.st_size - sizeof(uint32_t));
-    read(fd, datum.data, st.st_size - sizeof(uint32_t));
-    close(fd);
+    if(usingQueryPoint){
+      datum.nvectors = sequenceLength;
+      datum.data = (double *) malloc(datum.nvectors*datum.dim*sizeof(double));
+      lseek(fd, queryPoint*sizeof(double)*datum.dim, SEEK_CUR);
+      read(fd, datum.data, datum.nvectors*datum.dim*sizeof(double));
+      close(fd);
+    }
+    else{
+      datum.nvectors = (st.st_size - sizeof(uint32_t)) / (datum.dim * sizeof(double));
+      datum.data = (double *) malloc(st.st_size - sizeof(uint32_t));
+      read(fd, datum.data, st.st_size - sizeof(uint32_t));
+      close(fd);
+    }
     if(usingPower) {
       uint32_t one;
       fd = open(powerFileName, O_RDONLY);
@@ -846,8 +855,10 @@
         error("malformed power file dimensionality", powerFileName);
       }
       datum.power = (double *) malloc(datum.nvectors * sizeof(double));
+      if(usingQueryPoint)
+	lseek(fd, queryPoint*sizeof(double), SEEK_CUR);
       if(read(fd, datum.power, datum.nvectors * sizeof(double)) != (ssize_t) (datum.nvectors * sizeof(double))) {
-        error("malformed power file", powerFileName);
+	error("malformed power file", powerFileName);
       }
       close(fd);
     }
@@ -862,7 +873,10 @@
   qspec.qid.flags = 0;
   qspec.qid.flags |= usingQueryPoint ? 0 : ADB_QID_FLAG_EXHAUSTIVE;
   qspec.qid.flags |= lsh_exact ? 0 : ADB_QID_FLAG_ALLOW_FALSE_POSITIVES;
-  qspec.qid.sequence_start = queryPoint;
+  if(usingQueryPoint)
+    qspec.qid.sequence_start = 0;
+  else
+    qspec.qid.sequence_start = queryPoint;
 
   switch(queryType) {
   case O2_POINT_QUERY:
@@ -912,7 +926,7 @@
     if(!(qspec.refine.flags & ADB_REFINE_RADIUS)) {
       error("query-type not yet supported");
     } else {
-      reporter = new trackSequenceQueryRadNNReporterOneToOne(pointNN,trackNN, dbH->numFiles);
+      reporter = new trackSequenceQueryRadNNReporterOneToOne(pointNN,trackNN, adb->header->numFiles);
     }
     break;
   default: