Allow algorithms to include an additional, untimed query preparation step
Algorithms that require an unusual unserialisation process for query points
should have some way of doing that before the timing begins to give a more
realistic view of their performance
@@ -19,6 +19,10 @@ from ann_benchmarks.algorithms.definitions import get_algorithms, get_definition
def run_algo(X_train, queries, library, algo, distance, results_fn,
run_count=3, force_single=False):
try:
+ prepared_queries = False
+ if hasattr(algo, "supports_prepared_queries"):
+ prepared_queries = algo.supports_prepared_queries()
+
t0 = time.time()
if algo != 'bf':
algo.fit(X_train)
@@ -29,6 +33,12 @@ def run_algo(X_train, queries, library, algo, distance, results_fn,
for i in xrange(run_count):
def single_query(t):
v, _, _ = t
+ if prepared_queries:
+ algo.prepare_query(v, 10)
+ start = time.time()
+ found = algo.run_prepared_query()
+ total = (time.time() - start)
+ else:
start = time.time()
found = algo.query(v, 10)
total = (time.time() - start)
