def recarrayequalspairs(X,Y,weak=True):
    """
    Indices of elements in a sorted numpy recarray (or ndarray with 
    structured dtype) equal to those in another.

    Record array version of func:`tabular.fast.equalspairs`, but slightly 
    different because the concept of being sorted is less well-defined for a 
    record array.

    Given numpy recarray `X` and sorted numpy recarray `Y`, determine the 
    indices in Y equal to indices in X.

    Returns `[A,B,s]` where `s` is a permutation of `Y` such that for::

            Y = X[s]

    we have::

            Y[A[i]:B[i]] = Y[Y == X[i]]

    `A[i] = B[i] = 0` if `X[i]` is not in `Y`.

    **Parameters**

            **X** :  numpy recarray

                    Numpy recarray to compare to the sorted numpy recarray `Y`.

            **Y** :  numpy recarray

                    Sorted numpy recarray.  Determine the indices of elements 
                    of `Y` equal to those in numpy array `X`.

    **Returns**

            **A** :  numpy array

                    List of indices in `Y`, `len(A) = len(Y)`.

            **B** :  numpy array

                    List of indices in `Y`, `len(B) = len(Y)`.

            **s** :  numpy array

                    Permutation of `Y`.

    **See Also:**

            :func:`tabular.fast.recarrayequalspairs`

    """
    if (weak and set(X.dtype.names) != set(Y.dtype.names)) or \
       (not weak and X.dtype.names != Y.dtype.names):
        return [np.zeros((len(X),),int),np.zeros((len(X),),int),None]
    else:
        if X.dtype.names != Y.dtype.names:
            Y = np.rec.fromarrays([Y[a] for a in X.dtype.names], 
                                  names= X.dtype.names)
        NewX = np.array([str(l) for l in X])
        NewY = np.array([str(l) for l in Y])
        s = NewY.argsort()  ; NewY.sort()
        [A,B] = equalspairs(NewX,NewY)
        return [A,B,s]