-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Description
Now we've already had F.pdist, which computes pairwise distances between each pair in a single set of vectors.
However, in retrieval problems, we often need to compute the pairwise distances between each pair consisting one sample from a probe/query set and another sample from a gallery/database set, in order to evaluate the performances of a retrieval model.
Specifically, if the database tensor has size N-by-D and the query M-by-D, the tensor returned by a cdist function should have size N-by-M where the (i, j)-th element is the distance between the i-th sample from the database and the j-th sample from the query.
Currently, a plausible way (ok, I use this method because I had no idea about GPU programming to achieve better performance) to do this evaluation is:
- transform the tensor to a numpy array: query_np = query.cpu().numpy(), database_np = database.cpu().numpy()
- using cdist provided by scipy: dist_matrix = cdist(query_np, database_np)
which is really far from elegent and could not utilize GPU power and thus inefficient. So, could we develop some efficient cdist function which can use GPU, and hopefully act like cdist in scipy?