code: def test_interpolate_vector_2d(rng):
      sz = 64
      target_shape = (sz, sz)
      field = np.empty(target_shape + (2,), dtype=floating)
      field[...] = rng.integers(0, 10, np.size(field)).reshape(
          target_shape + (2,)
      )
      extended_field = np.zeros((sz + 2, sz + 2, 2), dtype=floating)
      extended_field[1 : sz + 1, 1 : sz + 1] = field
      # Select some coordinates to interpolate at
      nsamples = 200
      locations = (
          rng.random(2 * nsamples).reshape((nsamples, 2)) * (sz + 2)
          - 1.0
      )
      extended_locations = locations + 1
  
      # Call the implementation under test
      interp, inside = interpolate_vector_2d(field, locations)
  
      # Call the reference implementation
      expected = np.zeros_like(interp)
      for i in range(2):
          expected[..., i] = map_coordinates(
              extended_field[..., i],
              extended_locations.transpose(),
              order=1,
          )
  
      npt.assert_array_almost_equal(expected, interp)
  
      # Test interpolation stability along the boundary
      epsilon = 5e-8
      for k in range(2):
          for offset in [0, sz - 1]:
              delta = ((rng.random(nsamples) * 2) - 1) * epsilon
              locations[:, k] = delta + offset
              locations[:, (k + 1) % 2] = rng.random(nsamples) * (
                  sz - 1
              )
              interp, inside = interpolate_vector_2d(field, locations)
  
              locations[:, k] = offset
              for i in range(2):
                  expected[..., i] = map_coordinates(
                      field[..., i], locations.transpose(), order=1
                  )
              npt.assert_array_almost_equal(expected, interp)
  
              if offset == 0:
                  expected_flag = np.array(delta >= 0, dtype=np.int32)
              else:
                  expected_flag = np.array(delta <= 0, dtype=np.int32)
              npt.assert_array_almost_equal(expected_flag, inside)
  
file_path: dipy/dipy/core/tests/test_interpolation.py
imports: import numpy
  import numpy.testing
  import warnings
  from scipy.ndimage import map_coordinates
  from dipy.core.subdivide_octahedron import create_unit_sphere
  from dipy.core.interpolation import trilinear_interpolate4d, interpolate_scalar_2d, interpolate_scalar_3d, interpolate_vector_2d, interpolate_vector_3d, interpolate_scalar_nn_2d, interpolate_scalar_nn_3d, NearestNeighborInterpolator, TriLinearInterpolator, OutsideImage, map_coordinates_trilinear_iso, interp_rbf
  from dipy.align import floating
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 7 for calling a global function with example usage: test_interpolate_vector_2d(rng) without return types