Mercurial > hg > audiodb
comparison index.cpp @ 468:4dbd7917bf9e api-inversion
YAY!
audioDB::index_query_loop is now disentangled. Hardwired lsh_in_core to
true, and invented a new QID flag for !lsh_exact. All tests continue to
pass.
The plans now:
- extract the audiodb_query_spec() function from inside audioDB::query,
and move audioDB::query (and the timestamps function) to audioDB.cpp;
- write libtests/0036 and libtests/0037 in terms of audiodb_query_spec();
- rewrite all the other libtests in terms of audiodb_query_spec();
- delete audiodb_query() [ and maybe rename audiodb_query_spec(), I
dunno];
- implement example bindings (probably to Lisp, because that's what I
know best);
- see if anyone other than me can work out how the API works. If not,
provide documentation;
- revise API in the light of user feedback.
author | mas01cr |
---|---|
date | Wed, 31 Dec 2008 15:44:12 +0000 |
parents | 11fccb6a3bd5 |
children | b2fd8113d8bc |
comparison
equal
deleted
inserted
replaced
466:11fccb6a3bd5 | 468:4dbd7917bf9e |
---|---|
576 } | 576 } |
577 | 577 |
578 // return -1 on error | 578 // return -1 on error |
579 // return 0: if index does not exist | 579 // return 0: if index does not exist |
580 // return nqv: if index exists | 580 // return nqv: if index exists |
581 int audioDB::index_query_loop(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate) { | 581 int audiodb_index_query_loop(adb_t *adb, adb_query_spec_t *spec, adb_qstate_internal_t *qstate) { |
582 | 582 |
583 double *query = 0, *query_data = 0; | 583 double *query = 0, *query_data = 0; |
584 adb_qpointers_internal_t qpointers = {0}; | 584 adb_qpointers_internal_t qpointers = {0}; |
585 | 585 |
586 adb_qcallback_t callback_data; | 586 adb_qcallback_t callback_data; |
593 bool normalized = (spec->params.distance == ADB_DISTANCE_EUCLIDEAN_NORMED); | 593 bool normalized = (spec->params.distance == ADB_DISTANCE_EUCLIDEAN_NORMED); |
594 double radius = spec->refine.radius; | 594 double radius = spec->refine.radius; |
595 bool use_absolute_threshold = spec->refine.flags & ADB_REFINE_ABSOLUTE_THRESHOLD; | 595 bool use_absolute_threshold = spec->refine.flags & ADB_REFINE_ABSOLUTE_THRESHOLD; |
596 double absolute_threshold = spec->refine.absolute_threshold; | 596 double absolute_threshold = spec->refine.absolute_threshold; |
597 | 597 |
598 // Set the point-reporter callback based on the value of lsh_exact | 598 if(spec->qid.flags & ADB_QID_FLAG_ALLOW_FALSE_POSITIVES) { |
599 if(lsh_exact) { | 599 add_point_func = &audiodb_index_add_point_approximate; |
600 } else { | |
600 qstate->exact_evaluation_queue = new std::priority_queue<PointPair>; | 601 qstate->exact_evaluation_queue = new std::priority_queue<PointPair>; |
601 add_point_func = &audiodb_index_add_point_exact; | 602 add_point_func = &audiodb_index_add_point_exact; |
602 } else { | 603 } |
603 add_point_func = &audiodb_index_add_point_approximate; | 604 |
604 } | 605 /* FIXME: this hardwired lsh_in_core is here to allow for a |
606 * transition period while the need for the argument is worked | |
607 * through. Hopefully it will disappear again eventually. */ | |
608 bool lsh_in_core = true; | |
605 | 609 |
606 if(!audiodb_index_init_query(adb, spec, qstate, lsh_in_core)) { | 610 if(!audiodb_index_init_query(adb, spec, qstate, lsh_in_core)) { |
607 return 0; | 611 return 0; |
608 } | 612 } |
609 | 613 |
619 | 623 |
620 uint32_t Nq = (qpointers.nvectors > O2_MAXTRACKLEN ? O2_MAXTRACKLEN : qpointers.nvectors) - sequence_length + 1; | 624 uint32_t Nq = (qpointers.nvectors > O2_MAXTRACKLEN ? O2_MAXTRACKLEN : qpointers.nvectors) - sequence_length + 1; |
621 std::vector<std::vector<float> > *vv = audiodb_index_initialize_shingles(Nq, adb->header->dim, sequence_length); | 625 std::vector<std::vector<float> > *vv = audiodb_index_initialize_shingles(Nq, adb->header->dim, sequence_length); |
622 | 626 |
623 // Construct shingles from query features | 627 // Construct shingles from query features |
624 for(uint32_t pointID = 0; pointID < Nq; pointID++) | 628 for(uint32_t pointID = 0; pointID < Nq; pointID++) { |
625 audiodb_index_make_shingle(vv, pointID, query, adb->header->dim, sequence_length); | 629 audiodb_index_make_shingle(vv, pointID, query, adb->header->dim, sequence_length); |
630 } | |
626 | 631 |
627 // Normalize query vectors | 632 // Normalize query vectors |
628 int vcount = audiodb_index_norm_shingles(vv, qpointers.l2norm, qpointers.power, adb->header->dim, sequence_length, radius, normalized, use_absolute_threshold, absolute_threshold); | 633 int vcount = audiodb_index_norm_shingles(vv, qpointers.l2norm, qpointers.power, adb->header->dim, sequence_length, radius, normalized, use_absolute_threshold, absolute_threshold); |
629 if(vcount == -1) { | 634 if(vcount == -1) { |
630 audiodb_index_delete_shingles(vv); | 635 audiodb_index_delete_shingles(vv); |
634 uint32_t numVecsAboveThreshold = vcount; | 639 uint32_t numVecsAboveThreshold = vcount; |
635 | 640 |
636 // Nq contains number of inspected points in query file, | 641 // Nq contains number of inspected points in query file, |
637 // numVecsAboveThreshold is number of points with power >= absolute_threshold | 642 // numVecsAboveThreshold is number of points with power >= absolute_threshold |
638 double *qpp = qpointers.power; // Keep original qpPtr for possible exact evaluation | 643 double *qpp = qpointers.power; // Keep original qpPtr for possible exact evaluation |
639 if(!(spec->qid.flags & ADB_QUERY_ID_FLAG_EXHAUSTIVE) && numVecsAboveThreshold) { | 644 if(!(spec->qid.flags & ADB_QID_FLAG_EXHAUSTIVE) && numVecsAboveThreshold) { |
640 if((qstate->lsh->get_lshHeader()->flags & O2_SERIAL_FILEFORMAT2) || lsh_in_core) { | 645 if((qstate->lsh->get_lshHeader()->flags & O2_SERIAL_FILEFORMAT2) || lsh_in_core) { |
641 qstate->lsh->retrieve_point((*vv)[0], spec->qid.sequence_start, add_point_func, &callback_data); | 646 qstate->lsh->retrieve_point((*vv)[0], spec->qid.sequence_start, add_point_func, &callback_data); |
642 } else { | 647 } else { |
643 qstate->lsh->serial_retrieve_point(database, (*vv)[0], spec->qid.sequence_start, add_point_func, &callback_data); | 648 qstate->lsh->serial_retrieve_point(database, (*vv)[0], spec->qid.sequence_start, add_point_func, &callback_data); |
644 } | 649 } |
653 } | 658 } |
654 } | 659 } |
655 } | 660 } |
656 audiodb_index_delete_shingles(vv); | 661 audiodb_index_delete_shingles(vv); |
657 | 662 |
658 if(lsh_exact) { | 663 if(!(spec->qid.flags & ADB_QID_FLAG_ALLOW_FALSE_POSITIVES)) { |
659 // Perform exact distance computation on point pairs in | |
660 // exact_evaluation_queue | |
661 audiodb_query_queue_loop(adb, spec, qstate, query, &qpointers); | 664 audiodb_query_queue_loop(adb, spec, qstate, query, &qpointers); |
662 } | 665 } |
663 | 666 |
664 // Clean up | 667 // Clean up |
665 if(query_data) | 668 if(query_data) |