def setdiff1d( arr1, arr2, assume_unique=False ): if not len(arr1) or not len(arr2): return arr1 if not assume_unique: arr1 = unique( arr1 ) arr2 = unique( arr2 ) i = len(arr2) // 2 index = bisect( arr1, arr2[i] ) left = setdiff1d( arr1[:index+1-(index >= 0 and arr1[index] == arr2[i])], arr2[:i], assume_unique=True ) right = setdiff1d( arr1[index+1:], arr2[i+1:], assume_unique=True ) return hstack([left,right])
def bisect_sorted( array, items, matching=False ): if not len(items): return empty( 0, dtype=int ) if not len(array): return empty( 0, dtype=int ) if matching else fastrepeat( -1, len(items) ) i = len(items) // 2 index = bisect( array, items[i] ) left = bisect_sorted( array[:index+1], items[:i], matching ) right = index + bisect_sorted( array[index:], items[i+1:], matching ) return hstack([left,index,right]) if not matching or index >= 0 and array[index] == items[i] \ else left if not right \ else right if not left \ else hstack([left,right])