code: def test_nearest_no_broadcasting(self):
      # 3D
      test_input = np.zeros((2, 3, 3, 3, 2))
      test_input[:, 0, 0, 0, 0] = 1.0
      test_input = tf.constant(test_input)
      test_coords = tf.concat(
          [
              tf.ones((1, 5, 5, 5, 3)) * 0.1,
              tf.ones((1, 5, 5, 5, 3)) * 1.2,
          ],
          axis=0,
      )
      out = ResamplerLayer("NEAREST")(test_input, test_coords)
      with self.cached_session() as sess:
          out_value = sess.run(out)
          self.assertTrue(
              np.all(np.isclose(out_value[0, ..., 0], 1.0, atol=1e-5))
          )
          self.assertTrue(
              np.all(np.isclose(out_value[1, ..., 0], 0.0, atol=1e-5))
          )
          self.assertEqual(out_value.shape, (2, 5, 5, 5, 2))
      # 2D
      test_input = np.zeros((2, 3, 3, 2))
      test_input[:, 0, 0, 0] = 1.0
      test_input = tf.constant(test_input)
      test_coords = tf.concat(
          [tf.ones((1, 5, 5, 2)) * 0.1, tf.ones((1, 5, 5, 2)) * 1.2],
          axis=0,
      )
      out = ResamplerLayer("NEAREST")(test_input, test_coords)
      with self.cached_session() as sess:
          out_value = sess.run(out)
          self.assertTrue(
              np.all(np.isclose(out_value[0, ..., 0], 1.0, atol=1e-5))
          )
          self.assertTrue(
              np.all(np.isclose(out_value[1, ..., 0], 0.0, atol=1e-5))
          )
          self.assertEqual(out_value.shape, (2, 5, 5, 2))
      # 1D
      test_input = np.zeros((2, 3, 2))
      test_input[:, 0, 0] = 1.0
      test_input = tf.constant(test_input)
      test_coords = tf.concat(
          [tf.ones((1, 5, 1)) * 0.1, tf.ones((1, 5, 1)) * 1.2], axis=0
      )
      out = ResamplerLayer("NEAREST")(test_input, test_coords)
      with self.cached_session() as sess:
          out_value = sess.run(out)
          self.assertTrue(
              np.all(np.isclose(out_value[0, ..., 0], 1.0, atol=1e-5))
          )
          self.assertTrue(
              np.all(np.isclose(out_value[1, ..., 0], 0.0, atol=1e-5))
          )
          self.assertEqual(out_value.shape, (2, 5, 2))
  
file_path: NiftyNet/tests/resampler_batch_test.py
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import tensorflow
  from niftynet.layer.resampler import ResamplerLayer
  from tests.niftynet_testcase import NiftyNetTestCase
label_desc: Use image node_id 5 for calling the ResamplerTest obj's underlying member method code with example usage: obj.test_nearest_no_broadcasting() without return types