

def _mahalanobis_distance(self, samples, subtract_mean, square_root):
    if subtract_mean:
        n_samples = samples.shape[0]
        samples = (samples - np.tile(self.mean_vector[(..., None)], n_samples).T)
    if self.sparse:
        tmp = self.precision.dot(samples.T)
        d = samples.dot(tmp)
        d = np.diag(d)
    else:
        d = np.einsum('ij,ij->i', np.dot(samples, self.precision), samples)
    if (d.shape[0] == 1):
        d = d[0]
    if square_root:
        return np.sqrt(d)
    else:
        return d

dataset/ETHPy150Open menpo/menpo/menpo/model/gmrf.py GMRFVectorModel._mahalanobis_distance/original