code: def ndc_to_grid_sample_coords(
      xy_ndc: torch.Tensor,
      image_size_hw: Tuple[int, int],
  ) -> torch.Tensor:
      """
      Convert from the PyTorch3D's NDC coordinates to
      `torch.nn.functional.grid_sampler`'s coordinates.
  
      Args:
          xy_ndc: Tensor of shape `(..., 2)` containing 2D points in the
              PyTorch3D's NDC coordinates.
          image_size_hw: A tuple `(image_height, image_width)` denoting the
              height and width of the image tensor to sample.
      Returns:
          xy_grid_sample: Tensor of shape `(..., 2)` containing 2D points in the
              `torch.nn.functional.grid_sample` coordinates.
      """
      if len(image_size_hw) != 2 or any(s <= 0 for s in image_size_hw):
          raise ValueError(
              "'image_size_hw' has to be a 2-tuple of positive integers"
          )
      aspect = min(image_size_hw) / max(image_size_hw)
      xy_grid_sample = -xy_ndc  # first negate the coords
      if image_size_hw[0] >= image_size_hw[1]:
          xy_grid_sample[..., 1] *= aspect
      else:
          xy_grid_sample[..., 0] *= aspect
      return xy_grid_sample
  
imports: import copy
  import inspect
  import warnings
  from typing import Any, List, Optional, Tuple, TypeVar, Union
  import numpy
  import torch
  import torch.nn
  from ..common.datatypes import Device, make_device
label_desc: Use image node_id 4 for calling a global function with example usage: ndc_to_grid_sample_coords(xy_ndc, image_size_hw) and returns: xy_grid_sample