def cluster_dist_reduce(D_chunk, start, labels, label_freqs):
    clust_dists = np.zeros((len(D_chunk), len(label_freqs)), dtype=D_chunk.dtype)
    for i in range(len(D_chunk)):
        clust_dists[i] += np.bincount(labels, weights=D_chunk[i], minlength=len(label_freqs))
    intra_index = (np.arange(len(D_chunk)), labels[start:(start + len(D_chunk))])
    intra_clust_dists = clust_dists[intra_index]
    clust_dists[intra_index] = np.inf
    clust_dists /= label_freqs
    inter_clust_dists = clust_dists.min(axis=1)
    return (intra_clust_dists, inter_clust_dists)
def cluster_dist_reduce(D_chunk, start, labels, label_freqs):
    clust_dists = np.zeros((len(D_chunk), len(label_freqs)), dtype=D_chunk.dtype)
    for i in range(len(D_chunk)):
        clust_dists[i] += np.bincount(labels, weights=D_chunk[i], minlength=len(label_freqs))
    intra_index = (np.arange(len(D_chunk)), labels[start:(start + len(D_chunk))])
    intra_clust_dists = clust_dists[intra_index]
    clust_dists[intra_index] = np.inf
    clust_dists /= label_freqs
    inter_clust_dists = clust_dists.min(axis=1)
    return (intra_clust_dists, inter_clust_dists)