code: def compute_inertial(points, weights, clusters, centroids) -> float:
      """Compute the inertia (k-means loss, i.e. weighted sum of squared differences)"""
      assert len(points) == len(weights) == len(clusters)
      assert all(0 <= k < len(centroids) for k in clusters)
      return sum(
          w * (x - centroids[k]) ** 2
          for x, w, k in zip(points, weights, clusters)
      )
  
file_path: coremltools/deps/kmeans1d/tests/test_kmeans1d.py
imports: import unittest
  from kmeans1d import cluster
label_desc: Use image node_id 2 for calling a global function with example usage: compute_inertial(points, weights, clusters, centroids) and returns: sum