code: def test_trilinear_interpolate(rng):
      """This tests that the trilinear interpolation returns the correct values."""
      a, b, c = rng.random(3)
  
      def linear_function(x, y, z):
          return a * x + b * y + c * z
  
      N = 6
      x, y, z = np.mgrid[:N, :N, :N]
      data = np.empty((N, N, N, 2))
      data[..., 0] = linear_function(x, y, z)
      data[..., 1] = 99.0
  
      # Use a point not near the edges
      point = np.array([2.1, 4.8, 3.3])
      out = trilinear_interpolate4d(data, point)
      expected = [linear_function(*point), 99.0]
      npt.assert_array_almost_equal(out, expected)
  
      # Pass in out ourselves
      out[:] = -1
      trilinear_interpolate4d(data, point, out)
      npt.assert_array_almost_equal(out, expected)
  
      # use a point close to an edge
      point = np.array([-0.1, -0.1, -0.1])
      expected = [0.0, 99.0]
      out = trilinear_interpolate4d(data, point)
      npt.assert_array_almost_equal(out, expected)
  
      # different edge
      point = np.array([2.4, 5.4, 3.3])
      # On the edge 5.4 get treated as the max y value, 5.
      expected = [linear_function(point[0], 5.0, point[2]), 99.0]
      out = trilinear_interpolate4d(data, point)
      npt.assert_array_almost_equal(out, expected)
  
      # Test index errors
      point = np.array([2.4, 5.5, 3.3])
      npt.assert_raises(
          IndexError, trilinear_interpolate4d, data, point
      )
      point = np.array([2.4, -1.0, 3.3])
      npt.assert_raises(
          IndexError, trilinear_interpolate4d, data, point
      )
  
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 1 for calling a global function with example usage: test_trilinear_interpolate(rng) and returns: unknown