First off: thanks for this library, I'm finding it very useful! I've been using your implementation of thin plate spine transforms and was looking into ways to speed it up. In my case, the bottle neck appears to be lmk_util.distance_matrix() which is called in K_matrix(). Looking at distance_matrix(), I was wondering if you could just use scipy.spatial.distance.cdist instead?
def distance_matrix(X,Y):
"""For (p1,k)-shaped X and (p2,k)-shaped Y, returns the (p1,p2) matrix
where the element at [i,j] is the distance between X[i,:] and Y[j,:].
"""
return script.spatial.distance.cdist(X, Y)
Benchmarking this with X (16840, 3) and Y (26, 3), I get ~10s with the current and ~10ms with a scipy implementation of distance_matrix.
Hi there, apologies for the delay.. and thanks for looking into that! I'd left that nested loop in there for too long! It uses cdist now.. Thanks again for that suggestion.
Hi!
First off: thanks for this library, I'm finding it very useful! I've been using your implementation of thin plate spine transforms and was looking into ways to speed it up. In my case, the bottle neck appears to be
lmk_util.distance_matrix()
which is called inK_matrix()
. Looking atdistance_matrix()
, I was wondering if you could just usescipy.spatial.distance.cdist
instead?Benchmarking this with
X (16840, 3)
andY (26, 3)
, I get ~10s with the current and ~10ms with a scipy implementation ofdistance_matrix
.Best, Philipp