code: def test_resample_equiv(
      from_shape, from_affine, to_shape, to_affine, order, seed
  ):
      """Test resampling equivalences."""
      pytest.importorskip("nibabel")
      pytest.importorskip("dipy")
      rng = np.random.RandomState(seed)
      from_data = rng.randn(*from_shape)
      is_rand = False
      if isinstance(to_affine, str):
          assert to_affine == "rand"
          to_affine = _rand_affine(rng)
          is_rand = True
      if isinstance(from_affine, str):
          assert from_affine == "rand"
          from_affine = _rand_affine(rng)
          is_rand = True
      to_affine = np.array(to_affine, float)
      assert to_affine.shape == (4, 4)
      from_affine = np.array(from_affine, float)
      assert from_affine.shape == (4, 4)
      #
      # 1. nibabel.processing.resample_from_to
      #
      # for a 1mm iso / 256 -> 5mm / 51 one sample takes ~486 ms
      from nibabel.processing import resample_from_to
      from nibabel.spatialimages import SpatialImage
  
      start = np.linalg.norm(from_data)
      got_nibabel = resample_from_to(
          SpatialImage(from_data, from_affine),
          (to_shape, to_affine),
          order=order,
      ).get_fdata()
      end = np.linalg.norm(got_nibabel)
      assert end > 0.05 * start  # not too much power lost
      #
      # 2. dipy.align.imaffine
      #
      # ~366 ms
      import dipy.align.imaffine
  
      interp = "linear" if order == 1 else "nearest"
      got_dipy = dipy.align.imaffine.AffineMap(
          None, to_shape, to_affine, from_shape, from_affine
      ).transform(from_data, interpolation=interp, resample_only=True)
      # XXX possibly some error in dipy or nibabel (/SciPy), or some boundary
      # condition?
      nib_different = (is_rand and order == 1) or (
          from_affine[0, 0] == 2.0
          and not np.allclose(from_affine, to_affine)
      )
      nib_different = nib_different and not (
          is_rand and from_affine[0, 0] == 2 and order == 0
      )
      if nib_different:
          assert not np.allclose(got_dipy, got_nibabel), "nibabel fixed"
      else:
          assert_allclose(
              got_dipy, got_nibabel, err_msg="dipy<->nibabel"
          )
      #
      # 3. mne.source_space._grid_interp
      #
      # ~339 ms
      trans = np.linalg.inv(from_affine) @ to_affine  # to -> from
      interp = _grid_interp(from_shape, to_shape, trans, order=order)
      got_mne = np.asarray(interp @ from_data.ravel(order="F")).reshape(
          to_shape, order="F"
      )
      if order == 1:
          assert_allclose(got_mne, got_dipy, err_msg="MNE<->dipy")
      else:
          perc = 100 * np.isclose(got_mne, got_dipy).mean()
          assert 83 < perc <= 100
  
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 17 for calling a global function with example usage: test_resample_equiv(from_shape, from_affine, to_shape, to_affine, order, seed) without return types