def joint_sfs_folded(ac1, ac2, n1=None, n2=None):
    """Compute the joint folded site frequency spectrum between two
    populations.

    Parameters
    ----------
    ac1 : array_like, int, shape (n_variants, 2)
        Allele counts for the first population.
    ac2 : array_like, int, shape (n_variants, 2)
        Allele counts for the second population.
    n1, n2 : int, optional
        The total number of chromosomes called in each population.

    Returns
    -------
    joint_sfs_folded : ndarray, int, shape (n1//2 + 1, n2//2 + 1)
        Array where the (i, j)th element is the number of variant sites with a
        minor allele count of i in the first population and j in the second
        population.

    """

    # check inputs
    ac1, n1 = _check_ac_n(ac1, n1)
    ac2, n2 = _check_ac_n(ac2, n2)

    # compute minor allele counts
    mac1 = np.amin(ac1, axis=1)
    mac2 = np.amin(ac2, axis=1)

    # compute site frequency spectrum
    x = n1//2 + 1
    y = n2//2 + 1
    tmp = (mac1 * y + mac2).astype(int, copy=False)
    s = np.bincount(tmp)
    s.resize(x, y)
    return s
Compute the joint folded site frequency spectrum between two
    populations.

    Parameters
    ----------
    ac1 : array_like, int, shape (n_variants, 2)
        Allele counts for the first population.
    ac2 : array_like, int, shape (n_variants, 2)
        Allele counts for the second population.
    n1, n2 : int, optional
        The total number of chromosomes called in each population.

    Returns
    -------
    joint_sfs_folded : ndarray, int, shape (n1//2 + 1, n2//2 + 1)
        Array where the (i, j)th element is the number of variant sites with a
        minor allele count of i in the first population and j in the second
        population.