code: def apply_weights(
      input, field_of_view, weights, dim, n_dims, pad_sz, pad_mode, fw
  ):
      # for this operation we assume the resized dim is the first one.
      # so we transpose and will transpose back after multiplying
      tmp_input = fw_swapaxes(input, dim, 0, fw)
  
      # apply padding
      tmp_input = fw_pad(tmp_input, fw, pad_sz, pad_mode)
  
      # field_of_view is a tensor of order 2: for each output (1d location
      # along cur dim)- a list of 1d neighbors locations.
      # note that this whole operations is applied to each dim separately,
      # this is why it is all in 1d.
      # neighbors = tmp_input[field_of_view] is a tensor of order image_dims+1:
      # for each output pixel (this time indicated in all dims), these are the
      # values of the neighbors in the 1d field of view. note that we only
      # consider neighbors along the current dim, but such set exists for every
      # multi-dim location, hence the final tensor order is image_dims+1.
      paddle.device.cuda.empty_cache()
      neighbors = tmp_input[field_of_view]
  
      # weights is an order 2 tensor: for each output location along 1d- a list
      # of weights matching the field of view. we augment it with ones, for
      # broadcasting, so that when multiplies some tensor the weights affect
      # only its first dim.
      tmp_weights = fw.reshape(
          weights, (*weights.shape, *[1] * (n_dims - 1))
      )
  
      # now we simply multiply the weights with the neighbors, and then sum
      # along the field of view, to get a single value per out pixel
      tmp_output = (neighbors * tmp_weights).sum(1)
      # we transpose back the resized dim to its original position
      return fw_swapaxes(tmp_output, 0, dim, fw)
  
imports: import warnings
  from fractions import Fraction
  from math import ceil
  from typing import Tuple
  import disco_diffusion_clip_rn50.resize_right.interp_methods
label_desc: Use image node_id 6 for calling a global function with example usage: apply_weights(input, field_of_view, weights, dim, n_dims, pad_sz, pad_mode, fw) and returns: fw_swapaxes