Mercurial > hg > audiodb
comparison query.cpp @ 589:9119f2fa3efe
Header file rearrangement
Make it so that lshlib.h is slightly more like a header file to include
to use the LSH ("class G") class, and slightly less a header file for
developing that class, by removing all the #includes and moving them to
the one-file lshlib.cpp instead.
Make audioDB-internals.h slightly more of a project header file, by
including there all the headers we actually need.
Remove some assert()s (which do nothing) and some Uns32Ts (-> uint32_t)
author | mas01cr |
---|---|
date | Tue, 11 Aug 2009 21:42:13 +0000 |
parents | 633614461994 |
children | 6ad0a6e67d4c |
comparison
equal
deleted
inserted
replaced
588:638e1647b199 | 589:9119f2fa3efe |
---|---|
102 free(rs->results); | 102 free(rs->results); |
103 free(rs); | 103 free(rs); |
104 return 0; | 104 return 0; |
105 } | 105 } |
106 | 106 |
107 /* FIXME: we should check the return values from allocation */ | |
107 static void audiodb_initialize_arrays(adb_t *adb, const adb_query_spec_t *spec, int track, unsigned int numVectors, double *query, double *data_buffer, double **D, double **DD) { | 108 static void audiodb_initialize_arrays(adb_t *adb, const adb_query_spec_t *spec, int track, unsigned int numVectors, double *query, double *data_buffer, double **D, double **DD) { |
108 unsigned int j, k, l, w; | 109 unsigned int j, k, l, w; |
109 double *dp, *qp, *sp; | 110 double *dp, *qp, *sp; |
110 | 111 |
111 const unsigned HOP_SIZE = spec->refine.hopsize; | 112 const unsigned HOP_SIZE = spec->refine.hopsize; |
112 const unsigned wL = spec->qid.sequence_length; | 113 const unsigned wL = spec->qid.sequence_length; |
113 | 114 |
114 for(j = 0; j < numVectors; j++) { | 115 for(j = 0; j < numVectors; j++) { |
115 // Sum products matrix | 116 // Sum products matrix |
116 D[j] = new double[(*adb->track_lengths)[track]]; | 117 D[j] = new double[(*adb->track_lengths)[track]]; |
117 assert(D[j]); | |
118 // Matched filter matrix | 118 // Matched filter matrix |
119 DD[j]=new double[(*adb->track_lengths)[track]]; | 119 DD[j]=new double[(*adb->track_lengths)[track]]; |
120 assert(DD[j]); | |
121 } | 120 } |
122 | 121 |
123 // Dot product | 122 // Dot product |
124 for(j = 0; j < numVectors; j++) | 123 for(j = 0; j < numVectors; j++) |
125 for(k = 0; k < (*adb->track_lengths)[track]; k++){ | 124 for(k = 0; k < (*adb->track_lengths)[track]; k++){ |
445 * don't overlap, so we will use exhaustive dot product evaluation | 444 * don't overlap, so we will use exhaustive dot product evaluation |
446 * (instead of memoization of partial sums, as in query_loop()). | 445 * (instead of memoization of partial sums, as in query_loop()). |
447 */ | 446 */ |
448 double dist; | 447 double dist; |
449 double *dbdata = 0, *dbdata_pointer; | 448 double *dbdata = 0, *dbdata_pointer; |
450 Uns32T currentTrack = 0x80000000; // KLUDGE: Initialize with a value outside of track index range | 449 uint32_t currentTrack = 0x80000000; // KLUDGE: Initialize with a value outside of track index range |
451 Uns32T npairs = qstate->exact_evaluation_queue->size(); | 450 uint32_t npairs = qstate->exact_evaluation_queue->size(); |
452 while(npairs--) { | 451 while(npairs--) { |
453 PointPair pp = qstate->exact_evaluation_queue->top(); | 452 PointPair pp = qstate->exact_evaluation_queue->top(); |
454 if(currentTrack != pp.trackID) { | 453 if(currentTrack != pp.trackID) { |
455 maybe_delete_array(dbdata); | 454 maybe_delete_array(dbdata); |
456 maybe_delete_array(dbpointers.l2norm_data); | 455 maybe_delete_array(dbpointers.l2norm_data); |
467 audiodb_really_free_datum(&d); | 466 audiodb_really_free_datum(&d); |
468 return 1; | 467 return 1; |
469 } | 468 } |
470 audiodb_really_free_datum(&d); | 469 audiodb_really_free_datum(&d); |
471 } | 470 } |
472 Uns32T qPos = (spec->qid.flags & ADB_QID_FLAG_EXHAUSTIVE) ? pp.qpos : 0; | 471 uint32_t qPos = (spec->qid.flags & ADB_QID_FLAG_EXHAUSTIVE) ? pp.qpos : 0; |
473 Uns32T sPos = pp.spos; // index into l2norm table | 472 uint32_t sPos = pp.spos; // index into l2norm table |
474 // Test power thresholds before computing distance | 473 // Test power thresholds before computing distance |
475 if( ( (!power_refine) || audiodb_powers_acceptable(&spec->refine, qpointers->power[qPos], dbpointers.power[sPos])) && | 474 if( ( (!power_refine) || audiodb_powers_acceptable(&spec->refine, qpointers->power[qPos], dbpointers.power[sPos])) && |
476 ( qPos<qpointers->nvectors-sequence_length+1 && sPos<(*adb->track_lengths)[pp.trackID]-sequence_length+1 ) ){ | 475 ( qPos<qpointers->nvectors-sequence_length+1 && sPos<(*adb->track_lengths)[pp.trackID]-sequence_length+1 ) ){ |
477 // Compute distance | 476 // Compute distance |
478 dist = audiodb_dot_product(query + qPos*adb->header->dim, dbdata + sPos*adb->header->dim, adb->header->dim*sequence_length); | 477 dist = audiodb_dot_product(query + qPos*adb->header->dim, dbdata + sPos*adb->header->dim, adb->header->dim*sequence_length); |