def x_c_dist(params: _torch.Tensor, clusters: _torch.Tensor) -> _torch.Tensor:
        """
        Calculate the distance between weights and clusters.
        """
        clusters = clusters.contiguous()

        if _torch.finfo(params.dtype).bits > _torch.finfo(clusters.dtype).bits:
            return _torch.cdist(params.to(clusters.dtype), clusters).square()
        else:
            return _torch.cdist(params, clusters.to(params.dtype)).square()

        Calculate the distance between weights and clusters.
        
coremltools/optimize/torch/palettization/_efficient_kmeans.py