comparison index.cpp @ 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
comparison
equal deleted inserted replaced
465:1030664df98c 466:11fccb6a3bd5
573 PointPair p(trackID, qpos, spos); 573 PointPair p(trackID, qpos, spos);
574 qstate->exact_evaluation_queue->push(p); 574 qstate->exact_evaluation_queue->push(p);
575 } 575 }
576 } 576 }
577 577
578 // return -1 on error
578 // return 0: if index does not exist 579 // return 0: if index does not exist
579 // return nqv: if index exists 580 // return nqv: if index exists
580 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) {
581 582
582 double *query = 0, *query_data = 0; 583 double *query = 0, *query_data = 0;
584 585
585 adb_qcallback_t callback_data; 586 adb_qcallback_t callback_data;
586 callback_data.adb = adb; 587 callback_data.adb = adb;
587 callback_data.qstate = qstate; 588 callback_data.qstate = qstate;
588 589
589 void (*add_point_func)(void*,Uns32T,Uns32T,float); 590 void (*add_point_func)(void *, uint32_t, uint32_t, float);
590 591
591 sequenceLength = spec->qid.sequence_length; 592 uint32_t sequence_length = spec->qid.sequence_length;
592 normalizedDistance = (spec->params.distance == ADB_DISTANCE_EUCLIDEAN_NORMED); 593 bool normalized = (spec->params.distance == ADB_DISTANCE_EUCLIDEAN_NORMED);
594 double radius = spec->refine.radius;
595 bool use_absolute_threshold = spec->refine.flags & ADB_REFINE_ABSOLUTE_THRESHOLD;
596 double absolute_threshold = spec->refine.absolute_threshold;
593 597
594 // Set the point-reporter callback based on the value of lsh_exact 598 // Set the point-reporter callback based on the value of lsh_exact
595 if(lsh_exact) { 599 if(lsh_exact) {
596 qstate->exact_evaluation_queue = new std::priority_queue<PointPair>; 600 qstate->exact_evaluation_queue = new std::priority_queue<PointPair>;
597 add_point_func = &audiodb_index_add_point_exact; 601 add_point_func = &audiodb_index_add_point_exact;
601 605
602 if(!audiodb_index_init_query(adb, spec, qstate, lsh_in_core)) { 606 if(!audiodb_index_init_query(adb, spec, qstate, lsh_in_core)) {
603 return 0; 607 return 0;
604 } 608 }
605 609
606 char *database = audiodb_index_get_name(adb->path, radius, sequenceLength); 610 char *database = audiodb_index_get_name(adb->path, radius, sequence_length);
607 if(!database) { 611 if(!database) {
608 error("failed to get index name", adb->path); 612 return -1;
609 } 613 }
610 614
611 if(audiodb_query_spec_qpointers(adb, spec, &query_data, &query, &qpointers)) { 615 if(audiodb_query_spec_qpointers(adb, spec, &query_data, &query, &qpointers)) {
612 error("failed to set up qpointers"); 616 delete [] database;
613 } 617 return -1;
614 618 }
615 // query vector index 619
616 Uns32T Nq = (qpointers.nvectors>O2_MAXTRACKLEN?O2_MAXTRACKLEN:qpointers.nvectors) - sequenceLength + 1; 620 uint32_t Nq = (qpointers.nvectors > O2_MAXTRACKLEN ? O2_MAXTRACKLEN : qpointers.nvectors) - sequence_length + 1;
617 std::vector<std::vector<float> > *vv = audiodb_index_initialize_shingles(Nq, adb->header->dim, sequenceLength); // allocate memory to copy query vectors to shingles 621 std::vector<std::vector<float> > *vv = audiodb_index_initialize_shingles(Nq, adb->header->dim, sequence_length);
618 622
619 // Construct shingles from query features 623 // Construct shingles from query features
620 for( Uns32T pointID = 0 ; pointID < Nq ; pointID++ ) 624 for(uint32_t pointID = 0; pointID < Nq; pointID++)
621 audiodb_index_make_shingle(vv, pointID, query, dbH->dim, sequenceLength); 625 audiodb_index_make_shingle(vv, pointID, query, adb->header->dim, sequence_length);
622 626
623 // Normalize query vectors 627 // Normalize query vectors
624 int vcount = audiodb_index_norm_shingles(vv, qpointers.l2norm, qpointers.power, dbH->dim, sequenceLength, radius, normalizedDistance, use_absolute_threshold, absolute_threshold); 628 int vcount = audiodb_index_norm_shingles(vv, qpointers.l2norm, qpointers.power, adb->header->dim, sequence_length, radius, normalized, use_absolute_threshold, absolute_threshold);
625 if(vcount == -1) { 629 if(vcount == -1) {
626 audiodb_index_delete_shingles(vv); 630 audiodb_index_delete_shingles(vv);
627 error("failed to norm shingles"); 631 delete [] database;
628 } 632 return -1;
629 Uns32T numVecsAboveThreshold = vcount; 633 }
634 uint32_t numVecsAboveThreshold = vcount;
630 635
631 // Nq contains number of inspected points in query file, 636 // Nq contains number of inspected points in query file,
632 // numVecsAboveThreshold is number of points with power >= absolute_threshold 637 // numVecsAboveThreshold is number of points with power >= absolute_threshold
633 double* qpp = qpointers.power; // Keep original qpPtr for possible exact evaluation 638 double *qpp = qpointers.power; // Keep original qpPtr for possible exact evaluation
634 if(usingQueryPoint && numVecsAboveThreshold){ 639 if(!(spec->qid.flags & ADB_QUERY_ID_FLAG_EXHAUSTIVE) && numVecsAboveThreshold) {
635 if((qstate->lsh->get_lshHeader()->flags&O2_SERIAL_FILEFORMAT2) || lsh_in_core) 640 if((qstate->lsh->get_lshHeader()->flags & O2_SERIAL_FILEFORMAT2) || lsh_in_core) {
636 qstate->lsh->retrieve_point((*vv)[0], queryPoint, add_point_func, &callback_data); 641 qstate->lsh->retrieve_point((*vv)[0], spec->qid.sequence_start, add_point_func, &callback_data);
637 else 642 } else {
638 qstate->lsh->serial_retrieve_point(database, (*vv)[0], queryPoint, add_point_func, &callback_data); 643 qstate->lsh->serial_retrieve_point(database, (*vv)[0], spec->qid.sequence_start, add_point_func, &callback_data);
639 } 644 }
640 else if(numVecsAboveThreshold) 645 } else if(numVecsAboveThreshold) {
641 for( Uns32T pointID = 0 ; pointID < Nq; pointID++ ) 646 for(uint32_t pointID = 0; pointID < Nq; pointID++) {
642 if(!use_absolute_threshold || (use_absolute_threshold && (*qpp++ >= absolute_threshold))) { 647 if(!use_absolute_threshold || (use_absolute_threshold && (*qpp++ >= absolute_threshold))) {
643 if((qstate->lsh->get_lshHeader()->flags&O2_SERIAL_FILEFORMAT2) || lsh_in_core) { 648 if((qstate->lsh->get_lshHeader()->flags & O2_SERIAL_FILEFORMAT2) || lsh_in_core) {
644 qstate->lsh->retrieve_point((*vv)[pointID], pointID, add_point_func, &callback_data); 649 qstate->lsh->retrieve_point((*vv)[pointID], pointID, add_point_func, &callback_data);
645 } else { 650 } else {
646 qstate->lsh->serial_retrieve_point(database, (*vv)[pointID], pointID, add_point_func, &callback_data); 651 qstate->lsh->serial_retrieve_point(database, (*vv)[pointID], pointID, add_point_func, &callback_data);
647 } 652 }
648 } 653 }
654 }
655 }
649 audiodb_index_delete_shingles(vv); 656 audiodb_index_delete_shingles(vv);
650 657
651 if(lsh_exact) 658 if(lsh_exact) {
652 // Perform exact distance computation on point pairs in exact_evaluation_queue 659 // Perform exact distance computation on point pairs in
660 // exact_evaluation_queue
653 audiodb_query_queue_loop(adb, spec, qstate, query, &qpointers); 661 audiodb_query_queue_loop(adb, spec, qstate, query, &qpointers);
662 }
654 663
655 // Clean up 664 // Clean up
656 if(query_data) 665 if(query_data)
657 delete[] query_data; 666 delete[] query_data;
658 if(qpointers.l2norm_data) 667 if(qpointers.l2norm_data)