code: def test_downsample_displacement_field_3d(rng):
      size = 32
      sh = (size, size, size, 3)
      for reduce_s in [True, False]:
          ns = size - 1 if reduce_s else size
          for reduce_r in [True, False]:
              nr = size - 1 if reduce_r else size
              for reduce_c in [True, False]:
                  nc = size - 1 if reduce_c else size
                  field = np.empty(
                      (size, size, size, 3), dtype=floating
                  )
                  field[...] = rng.integers(
                      0, 10, np.size(field)
                  ).reshape(sh)
  
                  if reduce_s:
                      field[-1, :, :] = 0
                  if reduce_r:
                      field[:, -1, :] = 0
                  if reduce_c:
                      field[:, :, -1] = 0
  
                  a = field[::2, ::2, ::2, :]
                  b = field[1::2, ::2, ::2, :]
                  c = field[::2, 1::2, ::2, :]
                  d = field[1::2, 1::2, ::2, :]
                  aa = field[::2, ::2, 1::2, :]
                  bb = field[1::2, ::2, 1::2, :]
                  cc = field[::2, 1::2, 1::2, :]
                  dd = field[1::2, 1::2, 1::2, :]
  
                  expected = 0.125 * (a + b + c + d + aa + bb + cc + dd)
  
                  if reduce_s:
                      expected[-1, :, :, :] *= 2
                  if reduce_r:
                      expected[:, -1, :, :] *= 2
                  if reduce_c:
                      expected[:, :, -1, :] *= 2
  
                  actual = vfu.downsample_displacement_field_3d(
                      field[:ns, :nr, :nc]
                  )
                  assert_array_almost_equal(expected, actual)
  
imports: import numpy
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_almost_equal, assert_equal, assert_raises
  from scipy.ndimage import map_coordinates
  from nibabel.affines import apply_affine, from_matvec
  from dipy.core import geometry
  from dipy.align import floating
  from dipy.align import imwarp
  from dipy.align import vector_fields
  from dipy.align.transforms import regtransforms
  from dipy.align.parzenhist import sample_domain_regular
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 20 for calling a global function with example usage: test_downsample_displacement_field_3d(rng) without return types