code: def test_nearest_neighbors_execution(setup):
      rs = np.random.RandomState(0)
      raw_X = rs.rand(10, 5)
      raw_Y = rs.rand(8, 5)
  
      X = mt.tensor(raw_X, chunk_size=7)
      Y = mt.tensor(raw_Y, chunk_size=(5, 3))
  
      for algo in ["brute", "ball_tree", "kd_tree", "auto"]:
          for metric in ["minkowski", "manhattan"]:
              nn = NearestNeighbors(
                  n_neighbors=3, algorithm=algo, metric=metric
              )
              nn.fit(X)
  
              ret = nn.kneighbors(Y)
  
              snn = SkNearestNeighbors(
                  n_neighbors=3, algorithm=algo, metric=metric
              )
              snn.fit(raw_X)
              expected = snn.kneighbors(raw_Y)
  
              result = [r.fetch() for r in ret]
              np.testing.assert_almost_equal(result[0], expected[0])
              np.testing.assert_almost_equal(result[1], expected[1])
  
              if nn._tree is not None:
                  assert isinstance(nn._tree.fetch(), type(snn._tree))
  
              # test return_distance=False
              ret = nn.kneighbors(Y, return_distance=False)
  
              result = ret.fetch()
              np.testing.assert_almost_equal(result, expected[1])
  
              # test y is x
              ret = nn.kneighbors()
  
              expected = snn.kneighbors()
  
              result = [r.fetch() for r in ret]
              np.testing.assert_almost_equal(result[0], expected[0])
              np.testing.assert_almost_equal(result[1], expected[1])
  
              # test y is x, and return_distance=False
              ret = nn.kneighbors(return_distance=False)
  
              result = ret.fetch()
              np.testing.assert_almost_equal(result, expected[1])
  
      # test callable metric
      metric = lambda u, v: np.sqrt(((u - v) ** 2).sum())
      for algo in ["brute", "ball_tree"]:
          nn = NearestNeighbors(
              n_neighbors=3, algorithm=algo, metric=metric
          )
          nn.fit(X)
  
          ret = nn.kneighbors(Y)
  
          snn = SkNearestNeighbors(
              n_neighbors=3, algorithm=algo, metric=metric
          )
          snn.fit(raw_X)
          expected = snn.kneighbors(raw_Y)
  
          result = [r.fetch() for r in ret]
          np.testing.assert_almost_equal(result[0], expected[0])
          np.testing.assert_almost_equal(result[1], expected[1])
  
      # test sparse
      raw_sparse_x = sps.random(
          10, 5, density=0.5, format="csr", random_state=rs
      )
      raw_sparse_y = sps.random(
          8, 5, density=0.4, format="csr", random_state=rs
      )
  
      X = mt.tensor(raw_sparse_x, chunk_size=7)
      Y = mt.tensor(raw_sparse_y, chunk_size=5)
  
      nn = NearestNeighbors(n_neighbors=3)
      nn.fit(X)
  
      ret = nn.kneighbors(Y)
  
      snn = SkNearestNeighbors(n_neighbors=3)
      snn.fit(raw_sparse_x)
      expected = snn.kneighbors(raw_sparse_y)
  
      result = [r.fetch() for r in ret]
      np.testing.assert_almost_equal(result[0], expected[0])
      np.testing.assert_almost_equal(result[1], expected[1])
  
      # test input with unknown shape
      X = mt.tensor(raw_X, chunk_size=7)
      X = X[X[:, 0] > 0.1]
      Y = mt.tensor(raw_Y, chunk_size=(5, 3))
      Y = Y[Y[:, 0] > 0.1]
  
      nn = NearestNeighbors(n_neighbors=3)
      nn.fit(X)
  
      ret = nn.kneighbors(Y)
  
      x2 = raw_X[raw_X[:, 0] > 0.1]
      y2 = raw_Y[raw_Y[:, 0] > 0.1]
      snn = SkNearestNeighbors(n_neighbors=3)
      snn.fit(x2)
      expected = snn.kneighbors(y2)
  
      result = ret.fetch()
      assert nn._fit_method == snn._fit_method
      np.testing.assert_almost_equal(result[0], expected[0])
      np.testing.assert_almost_equal(result[1], expected[1])
  
      # test fit a sklearn tree
      nn = NearestNeighbors(n_neighbors=3)
      nn.fit(snn._tree)
  
      ret = nn.kneighbors(Y)
      result = ret.fetch()
      assert nn._fit_method == snn._fit_method
      np.testing.assert_almost_equal(result[0], expected[0])
      np.testing.assert_almost_equal(result[1], expected[1])
  
file_path: mars/mars/learn/neighbors/tests/test_nearest_neighbors.py
imports: import numpy
  import scipy.sparse
  import pytest
  from ....None import tensor
  from ....core import tile
  from ....lib.sparse import SparseNDArray
  from ....tests.core import require_cupy
  from ....utils import lazy_import
  from ...proxima.core import proxima
  from ..None import NearestNeighbors
label_desc: Use image node_id 2 for calling a global function with example usage: test_nearest_neighbors_execution(setup) without return types