code: def test_interpolate_scalar_nn_2d(rng):
      sz = 64
      target_shape = (sz, sz)
      image = np.empty(target_shape, dtype=floating)
      image[...] = rng.integers(0, 10, np.size(image)).reshape(
          target_shape
      )
      # Select some coordinates to interpolate at
      nsamples = 200
      locations = (
          rng.random(2 * nsamples).reshape((nsamples, 2)) * (sz + 2)
          - 1.0
      )
  
      # Call the implementation under test
      interp, inside = interpolate_scalar_nn_2d(image, locations)
  
      # Call the reference implementation
      expected = map_coordinates(image, locations.transpose(), order=0)
  
      npt.assert_array_almost_equal(expected, interp)
  
      # Test the 'inside' flag
      for i in range(nsamples):
          if (locations[i, 0] < 0 or locations[i, 0] > (sz - 1)) or (
              locations[i, 1] < 0 or locations[i, 1] > (sz - 1)
          ):
              npt.assert_equal(inside[i], 0)
          else:
              npt.assert_equal(inside[i], 1)
  
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 3 for calling a global function with example usage: test_interpolate_scalar_nn_2d(rng) without return types