Exemplo n.º 1
0
def test_intersect_6(dtype):
  a = np.array([[0, 2], [1, 3], [2, 4]], dtype=dtype)
  b = np.array([[0, 2], [-2, 3], [6, 4], [2, 4]], dtype=dtype)
  out, la, lb = intersect_new(a, b, axis=0, return_indices=True)
  np.testing.assert_allclose(np.array([[0, 2], [2, 4]]), out)
  np.testing.assert_allclose(la, [0, 2])
  np.testing.assert_allclose(lb, [0, 3])
Exemplo n.º 2
0
def test_intersect_4(dtype):
  a = np.array([0, 1, 2, 3, 4], dtype=dtype)
  b = np.array([0, -1, 4], dtype=dtype)
  out, la, lb = intersect_new(a, b, return_indices=True)
  np.testing.assert_allclose([0, 4], out)
  np.testing.assert_allclose(la, [0, 4])
  np.testing.assert_allclose(lb, [0, 2])
Exemplo n.º 3
0
def test_intersect_1d(dtype):
  a = np.random.randint(-5, 5, 10, dtype=dtype)
  b = np.random.randint(-2, 2, 8, dtype=dtype)
  out, la, lb = intersect_new(a, b, axis=0, return_indices=True)
  out_, la_, lb_ = np.intersect1d(a, b, return_indices=True)
  np.testing.assert_allclose(out, out_)
  np.testing.assert_allclose(la, la_)
  np.testing.assert_allclose(lb, lb_)
Exemplo n.º 4
0
def test_intersect_5(dtype):
  a = np.array([[0, 2], [1, 3], [2, 4]], dtype=dtype)
  b = np.array([[0, 2], [-2, 3], [6, 6]], dtype=dtype)
  out = intersect_new(a, b, axis=0)
  np.testing.assert_allclose(np.array([[0, 2]]), out)
Exemplo n.º 5
0
def test_intersect_raises():
  np.random.seed(10)
  a = np.random.randint(0, 10, (4, 5, 1))
  b = np.random.randint(0, 10, (4, 6))
  with pytest.raises(ValueError, match="array ndims"):
    intersect_new(a, b, axis=0)
  a = np.random.randint(0, 10, (4, 5))
  b = np.random.randint(0, 10, (4, 6))
  with pytest.raises(ValueError, match="array widths"):
    intersect_new(a, b, axis=0)
  c = np.random.randint(0, 10, (3, 7))
  with pytest.raises(ValueError, match="array heights"):
    intersect_new(a, c, axis=1)
  with pytest.raises(NotImplementedError, match="intersection can only"):
    intersect_new(a, c, axis=2)
  d = np.random.randint(0, 10, (3, 7, 3))
  e = np.random.randint(0, 10, (3, 7, 3))
  with pytest.raises(NotImplementedError, match="_intersect_ndarray is only"):
    intersect_new(d, e, axis=1)
  a = np.random.randint(0, 10, (4, 5), dtype=np.int16)
  b = np.random.randint(0, 10, (4, 6), dtype=np.int32)
  with pytest.raises(ValueError, match="array dtypes"):
    intersect_new(a, b, axis=0)
Exemplo n.º 6
0
def test_intersect_3(dtype):
  a = np.array([0, 1, 2, 3, 4], dtype=dtype)
  b = np.array([0, -1, 4], dtype=dtype)
  out = intersect_new(a, b)
  np.testing.assert_allclose([0, 4], out)
Exemplo n.º 7
0
def test_intersect_1(dtype):
  a = np.array([[0, 1, 2], [2, 3, 4]], dtype=dtype)
  b = np.array([[0, -2, 6], [2, 3, 4]], dtype=dtype)
  out = intersect_new(a, b, axis=1)
  np.testing.assert_allclose(np.array([[0], [2]]), out)