def _generic_matrix_calc(fn, trees, normalise, min_overlap=4, overlap_fail_value=0, show_progress=True):
    """(fn, trees, normalise)

    Calculates all pairwise distances between trees given in the parameter 'trees'.

    Distance functions:
        eucdist_matrix
        geodist_matrix
        rfdist_matrix
        wrfdist_matrix

    These wrap the leafset-checking functions. If the faster non-leafset-checking functions are needed, do this:
    scipy.spatial.distance(['getDistance'(t1.phylotree, t2.phylotree, normalise)
                                for (t1, t2) in itertools.combinations(trees, 2)])
    for your choice of 'getDistance' out of:
        getEuclideanDistance
        getGeodesicDistance
        getRobinsonFouldsDistance
        getWeightedRobinsonFouldsDistance

    :param trees: list or tuple, or some other iterable container type containing Tree objects
    :param normalise: boolean
    :param min_overlap: int
    :return: numpy.array
    """
    jobs = itertools.combinations(trees, 2)
    results = []
    if show_progress:
        pbar = setup_progressbar('Calculating tree distances', 0.5 * len(trees) * (len(trees) - 1))
        pbar.start()
    for i, (t1, t2) in enumerate(jobs):
        results.append(_generic_distance_calc(fn, t1, t2, normalise, min_overlap, overlap_fail_value))
        if show_progress:
            pbar.update(i)
    if show_progress:
        pbar.finish()
    return scipy.spatial.distance.squareform(results)
(fn, trees, normalise)

    Calculates all pairwise distances between trees given in the parameter 'trees'.

    Distance functions:
        eucdist_matrix
        geodist_matrix
        rfdist_matrix
        wrfdist_matrix

    These wrap the leafset-checking functions. If the faster non-leafset-checking functions are needed, do this:
    scipy.spatial.distance(['getDistance'(t1.phylotree, t2.phylotree, normalise)
                                for (t1, t2) in itertools.combinations(trees, 2)])
    for your choice of 'getDistance' out of:
        getEuclideanDistance
        getGeodesicDistance
        getRobinsonFouldsDistance
        getWeightedRobinsonFouldsDistance

    :param trees: list or tuple, or some other iterable container type containing Tree objects
    :param normalise: boolean
    :param min_overlap: int
    :return: numpy.array