Mercurial > hg > audiodb
changeset 466:11fccb6a3bd5 api-inversion
Almost there!
audioDB::index_query_loop is now set, except for the lsh_in_core and
lsh_exact flags. I think the plan is to zap lsh_in_core entirely, and
add some flags to the qid structure for indexed behaviour.
author | mas01cr |
---|---|
date | Wed, 31 Dec 2008 12:25:22 +0000 |
parents | 1030664df98c |
children | 4dbd7917bf9e |
files | index.cpp query.cpp |
diffstat | 2 files changed, 39 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/index.cpp Tue Dec 30 23:56:57 2008 +0000 +++ b/index.cpp Wed Dec 31 12:25:22 2008 +0000 @@ -575,6 +575,7 @@ } } +// return -1 on error // return 0: if index does not exist // return nqv: if index exists int audioDB::index_query_loop(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate) { @@ -586,10 +587,13 @@ callback_data.adb = adb; callback_data.qstate = qstate; - void (*add_point_func)(void*,Uns32T,Uns32T,float); + void (*add_point_func)(void *, uint32_t, uint32_t, float); - sequenceLength = spec->qid.sequence_length; - normalizedDistance = (spec->params.distance == ADB_DISTANCE_EUCLIDEAN_NORMED); + uint32_t sequence_length = spec->qid.sequence_length; + bool normalized = (spec->params.distance == ADB_DISTANCE_EUCLIDEAN_NORMED); + double radius = spec->refine.radius; + bool use_absolute_threshold = spec->refine.flags & ADB_REFINE_ABSOLUTE_THRESHOLD; + double absolute_threshold = spec->refine.absolute_threshold; // Set the point-reporter callback based on the value of lsh_exact if(lsh_exact) { @@ -603,54 +607,59 @@ return 0; } - char *database = audiodb_index_get_name(adb->path, radius, sequenceLength); + char *database = audiodb_index_get_name(adb->path, radius, sequence_length); if(!database) { - error("failed to get index name", adb->path); + return -1; } if(audiodb_query_spec_qpointers(adb, spec, &query_data, &query, &qpointers)) { - error("failed to set up qpointers"); + delete [] database; + return -1; } - // query vector index - Uns32T Nq = (qpointers.nvectors>O2_MAXTRACKLEN?O2_MAXTRACKLEN:qpointers.nvectors) - sequenceLength + 1; - std::vector<std::vector<float> > *vv = audiodb_index_initialize_shingles(Nq, adb->header->dim, sequenceLength); // allocate memory to copy query vectors to shingles + uint32_t Nq = (qpointers.nvectors > O2_MAXTRACKLEN ? O2_MAXTRACKLEN : qpointers.nvectors) - sequence_length + 1; + std::vector<std::vector<float> > *vv = audiodb_index_initialize_shingles(Nq, adb->header->dim, sequence_length); // Construct shingles from query features - for( Uns32T pointID = 0 ; pointID < Nq ; pointID++ ) - audiodb_index_make_shingle(vv, pointID, query, dbH->dim, sequenceLength); + for(uint32_t pointID = 0; pointID < Nq; pointID++) + audiodb_index_make_shingle(vv, pointID, query, adb->header->dim, sequence_length); // Normalize query vectors - int vcount = audiodb_index_norm_shingles(vv, qpointers.l2norm, qpointers.power, dbH->dim, sequenceLength, radius, normalizedDistance, use_absolute_threshold, absolute_threshold); + int vcount = audiodb_index_norm_shingles(vv, qpointers.l2norm, qpointers.power, adb->header->dim, sequence_length, radius, normalized, use_absolute_threshold, absolute_threshold); if(vcount == -1) { audiodb_index_delete_shingles(vv); - error("failed to norm shingles"); + delete [] database; + return -1; } - Uns32T numVecsAboveThreshold = vcount; + uint32_t numVecsAboveThreshold = vcount; // Nq contains number of inspected points in query file, // numVecsAboveThreshold is number of points with power >= absolute_threshold - double* qpp = qpointers.power; // Keep original qpPtr for possible exact evaluation - if(usingQueryPoint && numVecsAboveThreshold){ - if((qstate->lsh->get_lshHeader()->flags&O2_SERIAL_FILEFORMAT2) || lsh_in_core) - qstate->lsh->retrieve_point((*vv)[0], queryPoint, add_point_func, &callback_data); - else - qstate->lsh->serial_retrieve_point(database, (*vv)[0], queryPoint, add_point_func, &callback_data); - } - else if(numVecsAboveThreshold) - for( Uns32T pointID = 0 ; pointID < Nq; pointID++ ) + double *qpp = qpointers.power; // Keep original qpPtr for possible exact evaluation + if(!(spec->qid.flags & ADB_QUERY_ID_FLAG_EXHAUSTIVE) && numVecsAboveThreshold) { + if((qstate->lsh->get_lshHeader()->flags & O2_SERIAL_FILEFORMAT2) || lsh_in_core) { + qstate->lsh->retrieve_point((*vv)[0], spec->qid.sequence_start, add_point_func, &callback_data); + } else { + qstate->lsh->serial_retrieve_point(database, (*vv)[0], spec->qid.sequence_start, add_point_func, &callback_data); + } + } else if(numVecsAboveThreshold) { + for(uint32_t pointID = 0; pointID < Nq; pointID++) { if(!use_absolute_threshold || (use_absolute_threshold && (*qpp++ >= absolute_threshold))) { - if((qstate->lsh->get_lshHeader()->flags&O2_SERIAL_FILEFORMAT2) || lsh_in_core) { + if((qstate->lsh->get_lshHeader()->flags & O2_SERIAL_FILEFORMAT2) || lsh_in_core) { qstate->lsh->retrieve_point((*vv)[pointID], pointID, add_point_func, &callback_data); } else { qstate->lsh->serial_retrieve_point(database, (*vv)[pointID], pointID, add_point_func, &callback_data); } } + } + } audiodb_index_delete_shingles(vv); - if(lsh_exact) - // Perform exact distance computation on point pairs in exact_evaluation_queue + if(lsh_exact) { + // Perform exact distance computation on point pairs in + // exact_evaluation_queue audiodb_query_queue_loop(adb, spec, qstate, query, &qpointers); + } // Clean up if(query_data)
--- a/query.cpp Tue Dec 30 23:56:57 2008 +0000 +++ b/query.cpp Wed Dec 31 12:25:22 2008 +0000 @@ -228,9 +228,10 @@ // Test for index (again) here if((qspec.refine.flags & ADB_REFINE_RADIUS) && audiodb_index_exists(adb->path, qspec.refine.radius, qspec.qid.sequence_length)){ VERB_LOG(1, "Calling indexed query on database %s, radius=%f, sequence_length=%d\n", adb->path, qspec.refine.radius, qspec.qid.sequence_length); - index_query_loop(adb, &qspec, &qstate); - } - else { + if(index_query_loop(adb, &qspec, &qstate) < 0) { + error("index_query_loop failed"); + } + } else { VERB_LOG(1, "Calling brute-force query on database %s\n", dbName); if(audiodb_query_loop(adb, &qspec, &qstate)) { error("audiodb_query_loop failed");