def cluster_modes(X, n_clusters, pca_dims):
    """Helper function for computing k-means clustering on modes.

    .. warning::

        This is a work in progress and has not been fully validated.

    Parameters
    ----------
    X : ndarray
        Data to cluster, typically modal eigenvectors
    n_clusters : int
        Number of clusters to compute
    pca_dims : int
        Number of PCA components to reduce data to

    Returns
    -------
    ndarray
        Categorical cluster labels
    ndarray
        Inertia for each point

    """
    from sklearn.decomposition import PCA
    from sklearn.cluster import KMeans
    pc = PCA(n_components=pca_dims, whiten=True, copy=True).fit(X)
    km = KMeans(n_clusters=n_clusters)
    clusters = km.fit_predict(pc.components_.T)
    return clusters, km.inertia_
