code: def test_nearest_neighbors(setup):
      rs = np.random.RandomState(0)
      raw_X = rs.rand(10, 5)
      raw_Y = rs.rand(8, 5)
  
      X = mt.tensor(raw_X)
      Y = mt.tensor(raw_Y)
  
      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_sparse = mt.tensor(raw_sparse_x)
      Y_sparse = mt.tensor(raw_sparse_y)
  
      metric_func = lambda u, v: np.sqrt(((u - v) ** 2).sum())
  
      _ = NearestNeighbors(
          algorithm="auto", metric="precomputed", metric_params={}
      )
  
      with pytest.raises(ValueError):
          _ = NearestNeighbors(algorithm="unknown")
  
      with pytest.raises(ValueError):
          _ = NearestNeighbors(algorithm="kd_tree", metric=metric_func)
  
      with pytest.raises(ValueError):
          _ = NearestNeighbors(algorithm="auto", metric="unknown")
  
      with pytest.warns(SyntaxWarning):
          NearestNeighbors(metric_params={"p": 1})
  
      with pytest.raises(ValueError):
          _ = NearestNeighbors(metric="wminkowski", p=0)
  
      with pytest.raises(ValueError):
          _ = NearestNeighbors(
              algorithm="auto", metric="minkowski", p=0
          )
  
      nn = NearestNeighbors(algorithm="auto", metric="minkowski", p=1)
      nn.fit(X)
      assert nn.effective_metric_ == "manhattan"
  
      nn = NearestNeighbors(algorithm="auto", metric="minkowski", p=2)
      nn.fit(X)
      assert nn.effective_metric_ == "euclidean"
  
      nn = NearestNeighbors(
          algorithm="auto", metric="minkowski", p=np.inf
      )
      nn.fit(X)
      assert nn.effective_metric_ == "chebyshev"
  
      nn2 = NearestNeighbors(algorithm="auto", metric="minkowski")
      nn2.fit(nn)
      assert nn2._fit_method == nn._fit_method
  
      nn = NearestNeighbors(algorithm="auto", metric="minkowski")
      ball_tree = SkBallTree(raw_X)
      nn.fit(ball_tree)
      assert nn._fit_method == "ball_tree"
  
      nn = NearestNeighbors(algorithm="auto", metric="minkowski")
      kd_tree = SkKDTree(raw_X)
      nn.fit(kd_tree)
      assert nn._fit_method == "kd_tree"
  
      with pytest.raises(ValueError):
          nn = NearestNeighbors()
          nn.fit(np.random.rand(0, 10))
  
      nn = NearestNeighbors(algorithm="ball_tree")
      with pytest.warns(UserWarning):
          nn.fit(X_sparse)
  
      nn = NearestNeighbors(metric="haversine")
      with pytest.raises(ValueError):
          nn.fit(X_sparse)
  
      nn = NearestNeighbors(metric=metric_func, n_neighbors=1)
      nn.fit(X)
      assert nn._fit_method == "ball_tree"
  
      nn = NearestNeighbors(metric="sqeuclidean", n_neighbors=1)
      nn.fit(X)
      assert nn._fit_method == "brute"
  
      with pytest.raises(ValueError):
          nn = NearestNeighbors(n_neighbors=-1)
          nn.fit(X)
  
      with pytest.raises(TypeError):
          nn = NearestNeighbors(n_neighbors=1.3)
          nn.fit(X)
  
      nn = NearestNeighbors()
      nn.fit(X)
      with pytest.raises(ValueError):
          nn.kneighbors(Y, n_neighbors=-1)
      with pytest.raises(TypeError):
          nn.kneighbors(Y, n_neighbors=1.3)
      with pytest.raises(ValueError):
          nn.kneighbors(Y, n_neighbors=11)
  
      nn = NearestNeighbors(algorithm="ball_tree")
      nn.fit(X)
      with pytest.raises(ValueError):
          nn.kneighbors(Y_sparse)
  
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 1 for calling a global function with example usage: test_nearest_neighbors(setup) without return types