Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Fast sqeuclidean #3252
Current scipy.spatial.distance.cdist() and scipy.spatial.distance.pdist() have a very slow implementation for metric='sqeuclidean' (see issue #3251). The current scipy implementation consists of computing the distances with metric='euclidean' (which involves sqrt()) and then - literally - "*_2". Since both sqrt() and *_2 are useless for 'sqeuclidean' and expensive, this PR means to enhance the speed of computation by avoiding useless computations. This PR adds low-level C functions for 'sqeuclidean' computation, adds the wrappers and the necessary Python code to call them from pdist() and cdist(). Note that there is no change in the API or in the docs. The improved cdist() and pdist() of this PR - when metric='sqeuclidean' - are at least 2x faster than current scipy's ones.