code: def test_sparse_morph():
      """Test sparse morphing."""
      rng = np.random.RandomState(0)
      vertices_fs = [
          np.sort(rng.permutation(np.arange(10242))[:4]),
          np.sort(rng.permutation(np.arange(10242))[:6]),
      ]
      data = rng.randn(10, 1)
      stc_fs = SourceEstimate(data, vertices_fs, 1, 1, "fsaverage")
      spheres_fs = [
          mne.read_surface(
              subjects_dir / "fsaverage" / "surf" / f"{hemi}.sphere.reg"
          )[0]
          for hemi in ("lh", "rh")
      ]
      spheres_sample = [
          mne.read_surface(
              subjects_dir / "sample" / "surf" / f"{hemi}.sphere.reg"
          )[0]
          for hemi in ("lh", "rh")
      ]
      morph_fs_sample = compute_source_morph(
          stc_fs,
          "fsaverage",
          "sample",
          sparse=True,
          spacing=None,
          subjects_dir=subjects_dir,
      )
      stc_sample = morph_fs_sample.apply(stc_fs)
      offset = 0
      orders = list()
      for v1, s1, v2, s2 in zip(
          stc_fs.vertices,
          spheres_fs,
          stc_sample.vertices,
          spheres_sample,
      ):
          dists = cdist(s1[v1], s2[v2])
          order = np.argmin(dists, axis=-1)
          assert_array_less(
              dists[np.arange(len(order)), order], 1.5
          )  # mm
          orders.append(order + offset)
          offset += len(order)
      assert_allclose(
          stc_fs.data, stc_sample.data[np.concatenate(orders)]
      )
      # Return
      morph_sample_fs = compute_source_morph(
          stc_sample,
          "sample",
          "fsaverage",
          sparse=True,
          spacing=None,
          subjects_dir=subjects_dir,
      )
      stc_fs_return = morph_sample_fs.apply(stc_sample)
      offset = 0
      orders = list()
      for v1, s, v2 in zip(
          stc_fs.vertices, spheres_fs, stc_fs_return.vertices
      ):
          dists = cdist(s[v1], s[v2])
          order = np.argmin(dists, axis=-1)
          assert_array_less(
              dists[np.arange(len(order)), order], 1.5
          )  # mm
          orders.append(order + offset)
          offset += len(order)
      assert_allclose(
          stc_fs.data, stc_fs_return.data[np.concatenate(orders)]
      )
  
imports: from inspect import signature
  import numpy
  import pytest
  from numpy.testing import assert_allclose, assert_array_equal, assert_array_less
  from scipy.sparse import csr_matrix
  from scipy.sparse import eye
  from scipy.spatial.distance import cdist
  import mne
  from mne import SourceEstimate, SourceMorph, VectorSourceEstimate, VolSourceEstimate, VolVectorSourceEstimate, compute_source_morph, get_volume_labels_from_aseg, grade_to_vertices, make_ad_hoc_cov, make_forward_solution, make_sphere_model, read_evokeds, read_forward_solution, read_freesurfer_lut, read_source_estimate, read_source_morph, setup_volume_source_space
  from mne._freesurfer import _get_atlas_values, _get_mri_info_data
  from mne.datasets import testing
  from mne.fixes import _get_img_fdata
  from mne.minimum_norm import apply_inverse, make_inverse_operator, read_inverse_operator
  from mne.source_space._source_space import _add_interpolator, _grid_interp
  from mne.transforms import quat_to_rot
  from mne.utils import _record_warnings, catch_logging
label_desc: Use image node_id 3 for calling a global function with example usage: test_sparse_morph() without return types