def test_pair_isin(): src = np.asarray([[0, 1], [1, 1], [2, 1], [3, 1], [4, 1]], dtype=np.int) pairs = np.asarray([[1, 1], [3, 1], [1, 2], [5, 1]], dtype=int) out = pair_isin(src, pairs) assert np.all(out == [True, True, True, False])
def test_pair_isin_one_pair(): src = np.asarray( [[0, 1], [1, 2], [2, 5], [5, 8], [8, 7], [7, 6], [6, 3], [3, 0]], dtype=np.int ) pairs = np.asarray([[4, 8]], dtype=int) out = pair_isin(src, pairs) assert tuple(out) == tuple([False])
def test_pair_isin_with_out_keyword(): src = np.asarray([[0, 1], [1, 1], [2, 1], [3, 1], [4, 1]], dtype=np.int) pairs = np.asarray([[1, 1], [3, 1], [1, 2], [5, 1]], dtype=int) out = np.empty(len(pairs), dtype=bool) rtn = pair_isin(src, pairs, out=out) assert rtn is out assert np.all(out == [True, True, True, False])
def test_pair_isin_1(): src = np.asarray( [[0, 1], [1, 2], [2, 5], [5, 8], [8, 7], [7, 6], [6, 3], [3, 0]], dtype=np.int ) pairs = np.asarray( [ [5, 2], [5, 4], [5, 8], [1, 2], [1, 4], [1, 0], [1, 3], [2, 4], [0, 6], [0, 3], [7, 3], [7, 4], [7, 6], [7, 8], [3, 6], [3, 4], [4, 8], ], dtype=int, ) out = pair_isin(src, pairs, sorter=np.argsort(src[:, 0])) assert tuple(out) == tuple( [ True, False, True, True, False, True, False, False, False, True, False, False, True, True, True, False, False, ] )