MatrixDistance generic