code: def test_sample_locations():
      # check positions of samples on toy example, with an affine != identity
      # flat horizontal mesh
      mesh = flat_mesh(5, 7)
      affine = np.diagflat([10, 20, 30, 1])
      inv_affine = np.linalg.inv(affine)
      # transform vertices to world space
      vertices = np.asarray(
          resampling.coord_transform(*mesh[0].T, affine=affine)
      ).T
      # compute by hand the true offsets in voxel space
      # (transformed by affine^-1)
      ball_offsets = surface._load_uniform_ball_cloud(10)
      ball_offsets = np.asarray(
          resampling.coord_transform(*ball_offsets.T, affine=inv_affine)
      ).T
      line_offsets = np.zeros((10, 3))
      line_offsets[:, 2] = np.linspace(1, -1, 10)
      line_offsets = np.asarray(
          resampling.coord_transform(*line_offsets.T, affine=inv_affine)
      ).T
      # check we get the same locations
      for kind, offsets in [
          ("line", line_offsets),
          ("ball", ball_offsets),
      ]:
          locations = surface._sample_locations(
              [vertices, mesh[1]], affine, 1.0, kind=kind, n_points=10
          )
          true_locations = np.asarray(
              [vertex + offsets for vertex in mesh[0]]
          )
          assert_array_equal(locations.shape, true_locations.shape)
          assert_array_almost_equal(true_locations, locations)
      with pytest.raises(ValueError):
          surface._sample_locations(mesh, affine, 1.0, kind="bad_kind")
  
imports: import os
  import tempfile
  import warnings
  import nibabel
  import numpy
  import pytest
  from nibabel import gifti
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from scipy.spatial import Delaunay
  from scipy.stats import pearsonr
  from nilearn import datasets, image
  from nilearn._utils import data_gen
  from nilearn.image import resampling
  from nilearn.surface import Mesh, Surface, load_surf_data, load_surf_mesh, surface
  from nilearn.surface.surface import _gifti_img_to_mesh, _load_surf_files_gifti_gzip
  from nilearn.surface.tests._testing import flat_mesh, generate_surf, z_const_img
label_desc: Use image node_id 21 for calling a global function with example usage: test_sample_locations() without return types