code: def setCompare(a, b,
                 aKey=None, bKey=None,
                 leftMinusRight=False, rightMinusLeft=False):
    
    aKey = aKey if aKey is not None else a
    bKey = bKey if bKey is not None else b
  
    aWithinBMask = np.in1d(aKey, bKey)
  
    if rightMinusLeft:
      bWithinAMask = np.in1d(bKey, aKey)
  
      if leftMinusRight:
        return (a[aWithinBMask],
                a[~aWithinBMask],
                b[bWithinAMask])
      else:
        return (a[aWithinBMask],
                b[~bWithinAMask])
    elif leftMinusRight:
      return (a[aWithinBMask],
              a[~aWithinBMask])
    else:
      return a[aWithinBMask]
docs: Compute the intersection and differences between two arrays, comparing
    elements by their key.
  
    @param a (numpy array)
    The left set to compare.
  
    @param b (numpy array)
    The right set to compare.
  
    @param aKey (numpy array or None)
    If specified, elements in "a" are compared by their corresponding entry in
    "aKey".
  
    @param bKey (numpy array or None)
    If specified, elements in "b" are compared by their corresponding entry in
    "bKey".
  
    @param leftMinusRight
    If True, also calculate the set difference (a - b)
  
    @param rightMinusLeft
    If True, also calculate the set difference (b - a)
  
    @return (numpy array or tuple)
    Always returns the intersection of "a" and "b". The elements of this
    intersection are values from "a" (which may be different from the values of
    "b" or "aKey").
  
    If leftMinusRight or rightMinusLeft are True, it returns a tuple:
    - intersection (numpy array)
      See above
    - leftMinusRight (numpy array)
      The elements in a that are not in b
    - rightMinusLeft (numpy array)
      The elements in b that are not in a