Cosine and Mahalanobis distance

This PR implements Cosine and Mahalanobis distances.