class_docstr: Unit test for GPUImageResampling defined in python_wrapper.cpp
class_docstr_tok: ["Unit","test","for","GPUImageResampling","defined","in","python_wrapper.cpp"]
code: def _test_resampled(self, resampled, floating, d, inter, axis):
      use_nearest = inter == 0
      max_idx_disp = int(round(d)) if use_nearest else int(math.ceil(d))
  
      self.assertAllEqual(resampled.shape, floating.shape)
  
      ref = float("nan") * np.zeros_like(resampled)
      size = ref.shape[axis]
  
      ref_slice = slice(0, size - max_idx_disp)
      flo_slice = slice(max_idx_disp, size)
  
      base_block = [slice(0, d) for d in floating.shape]
      flo_block = copy.copy(base_block)
      ref_block = copy.copy(base_block)
      flo_block[axis] = flo_slice
      ref_block[axis] = ref_slice
  
      ref[tuple(ref_block)] = floating[tuple(flo_block)]
  
      if not use_nearest:
          flo_slice = slice(max_idx_disp - 1, size - 1)
          flo_block = copy.copy(base_block)
          flo_block[axis] = flo_slice
          ref[tuple(ref_block)] += floating[tuple(flo_block)]
          ref /= 2
  
      mask = np.isfinite(ref + resampled)
      max_err = abs(ref[mask] - resampled[mask]).max()
      self.assertLessEqual(max_err, 1e-2)
  
      if len(resampled.shape) == 2:
          bdy_size = 1 + max(max_idx_disp, 1) * (inter + 1) * (
              resampled.shape[0] + resampled.shape[1]
          )
      else:
          bdy_size = (
              7
              + (max(max_idx_disp, 1) + 2)
              * (inter + 1)
              * max(resampled.shape) ** 2
          )
  
      nof_nans = resampled.size - mask.sum()
      self.assertLess(nof_nans, bdy_size)
  
file_path: NiftyNet/niftynet/contrib/niftyreg_image_resampling/tests/test_resampler.py
imports: from glob import glob
  import math
  import os.path
  import nibabel
  import numpy
  import copy
  import tensorflow
  import tensorflow.test
  from niftynet.contrib.niftyreg_image_resampling.niftyreg_module_loader import get_niftyreg_module
label_desc: Use image node_id 3 for calling the ResamplerTest obj's underlying member method code with example usage: obj._test_resampled(resampled, floating, d, inter, axis) without return types