scipy/scipy — pull request #3252 by emanuele (2014-01-28 15:51:37+00:00)
Title: Fast sqeuclidean

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.