def diff(X1, X2=None):
    """
    Compute the pairwise differences between input data contained in X1 and X2.
    If X2 is None then compute the differences between X1 and itself.
    """
    X2 = X1 if (X2 is None) else X2
    return X1[:, None, :] - X2[None, :, :]