code: def test_compute_nearest():
      """Test nearest neighbor searches."""
      x = rng.randn(500, 3)
      x /= np.sqrt(np.sum(x**2, axis=1))[:, None]
      nn_true = rng.permutation(np.arange(500, dtype=np.int64))[:20]
      y = x[nn_true]
  
      nn1 = _compute_nearest(x, y, method="BallTree")
      nn2 = _compute_nearest(x, y, method="KDTree")
      nn3 = _compute_nearest(x, y, method="cdist")
      assert_array_equal(nn_true, nn1)
      assert_array_equal(nn_true, nn2)
      assert_array_equal(nn_true, nn3)
  
      # test distance support
      nnn1 = _compute_nearest(
          x, y, method="BallTree", return_dists=True
      )
      nnn2 = _compute_nearest(x, y, method="KDTree", return_dists=True)
      nnn3 = _compute_nearest(x, y, method="cdist", return_dists=True)
      assert_array_equal(nnn1[0], nn_true)
      assert_array_equal(
          nnn1[1], np.zeros_like(nn1)
      )  # all dists should be 0
      assert_equal(len(nnn1), len(nnn2))
      for nn1, nn2, nn3 in zip(nnn1, nnn2, nnn3):
          assert_array_equal(nn1, nn2)
          assert_array_equal(nn1, nn3)
  
imports: from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_equal
  from mne import decimate_surface, dig_mri_distances, get_montage_volume_labels, pick_types, read_surface, write_surface
  from mne._fiff.constants import FIFF
  from mne.channels import make_dig_montage
  from mne.datasets import testing
  from mne.io import read_info
  from mne.surface import _compute_nearest, _get_ico_surface, _marching_cubes, _normal_orth, _project_onto_surface, _read_patch, _tessellate_sphere, _voxel_neighbors, fast_cross_3d, get_head_surf, get_meg_helmet_surf, read_curvature
  from mne.transforms import _get_trans
  from mne.utils import _record_warnings, catch_logging, object_diff, requires_freesurfer
label_desc: Use image node_id 4 for calling a global function with example usage: test_compute_nearest() without return types