code: def kmeans_inference(data, clusters, hard=True, bandwidth=1.0):
      """
      Computes cluster assignments for a k-means clustering.
      """
      assert clusters.size(1) == data.size(
          1
      ), "cluster dimensionality does not match data dimensionality"
  
      # compute all pairwise distances:
      d2_sum = data.pow(2.0).sum(1, keepdim=True)
      c2_sum = clusters.pow(2.0).sum(1, keepdim=True)
      distances = (
          data.matmul(clusters.t())
          .mul(-2.0)
          .add_(d2_sum)
          .add_(c2_sum.t())
      )
  
      # compute assignments and return:
      if hard:
          assignments = distances.argmin(1)
          return assignments
      else:
          similarities = distances.mul_(-1.0 / (2.0 * bandwidth)).exp_()
          return similarities
  
file_path: CrypTen/examples/util.py
imports: import logging
  import os
  import numpy
  import numpy.linalg
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: kmeans_inference(data, clusters, hard, bandwidth) and returns: assignments, similarities