Mercurial > hg > audiodb
comparison index.cpp @ 437:9a065b8db769 api-inversion
Hey, who let audioDB::set_up_query into the room?
audioDB::set_up_query and audioDB::set_up_db both do all sorts of
horrible pointer manipulation. Define a structure to contain all the
pointers, rather than having the hideous argument lists full of double
**, and use it in audioDB::set_up_query and
audioDB::set_up_query_from_key. (Those two functions are desperately
close to becoming one function, incidentally, or possibly even no
functions given the existence of adb_datum_t...)
author | mas01cr |
---|---|
date | Wed, 24 Dec 2008 10:56:07 +0000 |
parents | e43f8a7aca93 |
children | 4fe90fd568fc |
comparison
equal
deleted
inserted
replaced
436:e43f8a7aca93 | 437:9a065b8db769 |
---|---|
576 | 576 |
577 // return 0: if index does not exist | 577 // return 0: if index does not exist |
578 // return nqv: if index exists | 578 // return nqv: if index exists |
579 int audioDB::index_query_loop(adb_query_spec_t *spec, const char* dbName, Uns32T queryIndex) { | 579 int audioDB::index_query_loop(adb_query_spec_t *spec, const char* dbName, Uns32T queryIndex) { |
580 | 580 |
581 unsigned int numVectors = 0; | |
582 double *query = 0, *query_data = 0; | 581 double *query = 0, *query_data = 0; |
583 double *qNorm = 0, *qnPtr = 0, *qPower = 0, *qpPtr = 0; | 582 adb_qpointers_internal_t qpointers = {0}; |
584 double meanQdur = 0; | 583 |
585 void (*add_point_func)(void*,Uns32T,Uns32T,float); | 584 void (*add_point_func)(void*,Uns32T,Uns32T,float); |
586 | 585 |
587 sequenceLength = spec->qid.sequence_length; | 586 sequenceLength = spec->qid.sequence_length; |
588 normalizedDistance = (spec->params.distance == ADB_DISTANCE_EUCLIDEAN_NORMED); | 587 normalizedDistance = (spec->params.distance == ADB_DISTANCE_EUCLIDEAN_NORMED); |
589 | 588 |
599 return 0; | 598 return 0; |
600 | 599 |
601 char* database = index_get_name(dbName, radius, sequenceLength); | 600 char* database = index_get_name(dbName, radius, sequenceLength); |
602 | 601 |
603 if(query_from_key) | 602 if(query_from_key) |
604 set_up_query_from_key(spec, &query_data, &query, &qNorm, &qnPtr, &qPower, &qpPtr, &meanQdur, &numVectors, queryIndex); | 603 set_up_query_from_key(spec, &query_data, &query, &qpointers, queryIndex); |
605 else | 604 else |
606 set_up_query(spec, &query_data, &query, &qNorm, &qnPtr, &qPower, &qpPtr, &meanQdur, &numVectors); // get query vectors | 605 set_up_query(spec, &query_data, &query, &qpointers); |
607 | 606 |
608 VERB_LOG(1, "retrieving tracks..."); | 607 VERB_LOG(1, "retrieving tracks..."); |
609 | 608 |
610 gettimeofday(&tv1, NULL); | 609 gettimeofday(&tv1, NULL); |
611 // query vector index | 610 // query vector index |
612 Uns32T Nq = (numVectors>O2_MAXTRACKLEN?O2_MAXTRACKLEN:numVectors) - sequenceLength + 1; | 611 Uns32T Nq = (qpointers.nvectors>O2_MAXTRACKLEN?O2_MAXTRACKLEN:qpointers.nvectors) - sequenceLength + 1; |
613 vv = index_initialize_shingles(Nq); // allocate memory to copy query vectors to shingles | 612 vv = index_initialize_shingles(Nq); // allocate memory to copy query vectors to shingles |
614 VERB_LOG(1, "Nq=%d", Nq); | 613 VERB_LOG(1, "Nq=%d", Nq); |
615 // Construct shingles from query features | 614 // Construct shingles from query features |
616 for( Uns32T pointID = 0 ; pointID < Nq ; pointID++ ) | 615 for( Uns32T pointID = 0 ; pointID < Nq ; pointID++ ) |
617 index_make_shingle(vv, pointID, query, dbH->dim, sequenceLength); | 616 index_make_shingle(vv, pointID, query, dbH->dim, sequenceLength); |
618 | 617 |
619 // Normalize query vectors | 618 // Normalize query vectors |
620 Uns32T numVecsAboveThreshold = index_norm_shingles( vv, qnPtr, qpPtr ); | 619 Uns32T numVecsAboveThreshold = index_norm_shingles( vv, qpointers.l2norm, qpointers.power ); |
621 VERB_LOG(1, "Nq'=%d\n", numVecsAboveThreshold); | 620 VERB_LOG(1, "Nq'=%d\n", numVecsAboveThreshold); |
622 | 621 |
623 // Nq contains number of inspected points in query file, | 622 // Nq contains number of inspected points in query file, |
624 // numVecsAboveThreshold is number of points with power >= absolute_threshold | 623 // numVecsAboveThreshold is number of points with power >= absolute_threshold |
625 double* qpp = qpPtr; // Keep original qpPtr for possible exact evaluation | 624 double* qpp = qpointers.power; // Keep original qpPtr for possible exact evaluation |
626 if(usingQueryPoint && numVecsAboveThreshold){ | 625 if(usingQueryPoint && numVecsAboveThreshold){ |
627 if((lsh->get_lshHeader()->flags&O2_SERIAL_FILEFORMAT2) || lsh_in_core) | 626 if((lsh->get_lshHeader()->flags&O2_SERIAL_FILEFORMAT2) || lsh_in_core) |
628 lsh->retrieve_point((*vv)[0], queryPoint, add_point_func, (void*)this); | 627 lsh->retrieve_point((*vv)[0], queryPoint, add_point_func, (void*)this); |
629 else | 628 else |
630 lsh->serial_retrieve_point(database, (*vv)[0], queryPoint, add_point_func, (void*)this); | 629 lsh->serial_retrieve_point(database, (*vv)[0], queryPoint, add_point_func, (void*)this); |
639 } | 638 } |
640 } | 639 } |
641 | 640 |
642 if(lsh_exact) | 641 if(lsh_exact) |
643 // Perform exact distance computation on point pairs in exact_evaluation_queue | 642 // Perform exact distance computation on point pairs in exact_evaluation_queue |
644 query_loop_points(spec, query, qnPtr, qpPtr, meanQdur, numVectors); | 643 query_loop_points(spec, query, &qpointers); |
645 | 644 |
646 gettimeofday(&tv2,NULL); | 645 gettimeofday(&tv2,NULL); |
647 VERB_LOG(1,"elapsed time: %ld msec\n", | 646 VERB_LOG(1,"elapsed time: %ld msec\n", |
648 (tv2.tv_sec*1000 + tv2.tv_usec/1000) - | 647 (tv2.tv_sec*1000 + tv2.tv_usec/1000) - |
649 (tv1.tv_sec*1000 + tv1.tv_usec/1000)) | 648 (tv1.tv_sec*1000 + tv1.tv_usec/1000)) |
652 close(lshfid); | 651 close(lshfid); |
653 | 652 |
654 // Clean up | 653 // Clean up |
655 if(query_data) | 654 if(query_data) |
656 delete[] query_data; | 655 delete[] query_data; |
657 if(qNorm) | 656 if(qpointers.l2norm_data) |
658 delete[] qNorm; | 657 delete[] qpointers.l2norm_data; |
659 if(qPower) | 658 if(qpointers.power_data) |
660 delete[] qPower; | 659 delete[] qpointers.power_data; |
660 if(qpointers.mean_duration) | |
661 delete[] qpointers.mean_duration; | |
661 if(database) | 662 if(database) |
662 delete[] database; | 663 delete[] database; |
663 | 664 |
664 return Nq; | 665 return Nq; |
665 } | 666 } |