code: def ref_interpolate(
      x,
      scale,
      output_size,
      mode,
      align_corners=True,
      half_pixel=False,
      half_pixel_for_nn=False,
      channel_last=False,
  ):
      assert scale or output_size, "Need either scale or output_size."
      assert not scale or len(scale) in (1, 2, 3), "Only 1D/2D/3D"
      assert not output_size or len(output_size) in (
          1,
          2,
          3,
      ), "Only 1D/2D/3D"
  
      if channel_last:
          n_sdim = len(scale) if scale else len(output_size)
          t = refs.ChannelLastToFirstTranspose(x.ndim, n_sdim)
          x = t(x)
  
      if not output_size:
          output_size = np.floor(
              np.array(scale) * x.shape[-len(scale) :]
          )
          output_size = tuple(map(int, output_size))
  
      if mode == "nearest":
          if len(output_size) == 1:
              out = ref_nearest_interpolate_1d(
                  x,
                  output_size,
                  align_corners,
                  half_pixel,
                  half_pixel_for_nn,
              )
              out = t.inv(out) if channel_last else out
          if len(output_size) == 2:
              out = ref_nearest_interpolate_2d(
                  x,
                  output_size,
                  align_corners,
                  half_pixel,
                  half_pixel_for_nn,
              )
              out = t.inv(out) if channel_last else out
          if len(output_size) == 3:
              out = ref_nearest_interpolate_3d(
                  x,
                  output_size,
                  align_corners,
                  half_pixel,
                  half_pixel_for_nn,
              )
              out = t.inv(out) if channel_last else out
      elif mode == "linear":
          if len(output_size) == 1:
              out = ref_linear_interpolate_1d(
                  x, output_size, align_corners, half_pixel
              )
  
          if len(output_size) == 2:
              out = ref_linear_interpolate_2d(
                  x, output_size, align_corners, half_pixel
              )
  
          if len(output_size) == 3:
              out = ref_linear_interpolate_3d(
                  x, output_size, align_corners, half_pixel
              )
          out = t.inv(out) if channel_last else out
      return out
  
imports: from __future__ import division
  import pytest
  import numpy
  import nnabla.functions
  import refs
  from nbla_test_utils import list_context
label_desc: Use image node_id 5 for calling a global function with example usage: ref_interpolate(x, scale, output_size, mode, align_corners, half_pixel, half_pixel_for_nn, channel_last) and returns: out