Cosine and Mahalanobis distance

This PR implements Cosine and Mahalanobis distances.
@kortschak good suggestion, I didn't think of this.