code: def _resize_sparse_flow(
      self, flow, valid_flow_mask, scale_x=1.0, scale_y=1.0
  ):
      # This resizes both the flow and the valid_flow_mask mask (which is assumed to be reasonably sparse)
      # There are as-many non-zero values in the original flow as in the resized flow (up to OOB)
      # So for example if scale_x = scale_y = 2, the sparsity of the output flow is multiplied by 4
  
      h, w = flow.shape[-2:]
  
      h_new = int(round(h * scale_y))
      w_new = int(round(w * scale_x))
      flow_new = torch.zeros(size=[2, h_new, w_new], dtype=flow.dtype)
      valid_new = torch.zeros(
          size=[h_new, w_new], dtype=valid_flow_mask.dtype
      )
  
      jj, ii = torch.meshgrid(
          torch.arange(w), torch.arange(h), indexing="xy"
      )
  
      ii_valid, jj_valid = ii[valid_flow_mask], jj[valid_flow_mask]
  
      ii_valid_new = torch.round(ii_valid.to(float) * scale_y).to(
          torch.long
      )
      jj_valid_new = torch.round(jj_valid.to(float) * scale_x).to(
          torch.long
      )
  
      within_bounds_mask = (
          (0 <= ii_valid_new)
          & (ii_valid_new < h_new)
          & (0 <= jj_valid_new)
          & (jj_valid_new < w_new)
      )
  
      ii_valid = ii_valid[within_bounds_mask]
      jj_valid = jj_valid[within_bounds_mask]
      ii_valid_new = ii_valid_new[within_bounds_mask]
      jj_valid_new = jj_valid_new[within_bounds_mask]
  
      valid_flow_new = flow[:, ii_valid, jj_valid]
      valid_flow_new[0] *= scale_x
      valid_flow_new[1] *= scale_y
  
      flow_new[:, ii_valid_new, jj_valid_new] = valid_flow_new
      valid_new[ii_valid_new, jj_valid_new] = 1
  
      return flow_new, valid_new
  
imports: import torch
  import torchvision.transforms
  import torchvision.transforms.functional
label_desc: Use image node_id 3 for calling the RandomResizeAndCrop obj's underlying member method code with example usage: obj._resize_sparse_flow(flow, valid_flow_mask, scale_x, scale_y) and returns: flow_new,  valid_new