def is_in_bijection(a, b):
    """
    Test if a bijection exists between the elements of :attr:`a` and the elements of :attr:`b`.

    Given two numpy arrays :attr:`a` and :attr:`b` returns ``True`` if

        - :attr:`a` and :attr:`b` have same size
        - there exists a bijective function :math:`f` such that, for all :math:`i`, :math:`a(i) = f(b(i))`

    Note that input arrays are flattened.

    :param a: an nd array
    :param b: an nd array
    :return: ``True`` if a bijection exists and ``False`` otherwise
    """
    aa = a.flatten()
    bb = b.flatten()
    if aa.size != bb.size:
        return False
    equiv1 = {}
    equiv2 = {}
    for i in range(aa.size):
        v1 = aa[i]
        v2 = bb[i]
        if v1 in equiv1:
            if equiv1[v1] != v2:
                return False
        else:
            equiv1[v1] = v2
        if v2 in equiv2:
            if equiv2[v2] != v1:
                return False
        else:
            equiv2[v2] = v1
    return True
