function R = mahdist( x, y, cov_inv ) % function K = mahdist( x, y, cov_inv ) % % Fast Mahalanobis distance. Data is specified as column vectors % in matrices x and y. % % The result is: % % R_ij = mahalanobis_distance( x_i, y_j ). % % cov_inv is the inverse of the covariance matrix. % % D. Wingate 10/25/2006 % xcnt = size( x, 2 ); ycnt = size( y, 2 ); sx = cov_inv * x; sy = cov_inv * y; xs = sum( x .* sx, 1 ); % x'*cov_inv*x; row vector ys = sum( y .* sy, 1 ); % y'*cov_inv*y; row vector R = repmat( xs', 1, ycnt ) + repmat( ys, xcnt, 1 ) - 2 * sx'*y;