compute distance matrix the same way kernel matrix is computed