docstr: Test the conversion from ndc to grid_sample coords by comparing
  to known conversion results.
docstr_tok: ["Test","the","conversion","from","ndc","to","grid_sample","coords","by","comparing","to","known","conversion","results","."]
code: def test_ndc_to_grid_sample_coords(self):
      """
      Test the conversion from ndc to grid_sample coords by comparing
      to known conversion results.
      """
  
      # square image tests
      image_size_square = [100, 100]
      xy_ndc_gs_square = torch.FloatTensor(
          [
              # 4 corners
              [[-1.0, -1.0], [1.0, 1.0]],
              [[1.0, 1.0], [-1.0, -1.0]],
              [[1.0, -1.0], [-1.0, 1.0]],
              [[1.0, 1.0], [-1.0, -1.0]],
              # center
              [[0.0, 0.0], [0.0, 0.0]],
          ]
      )
  
      # non-batched version
      for xy_ndc, xy_gs in xy_ndc_gs_square:
          xy_gs_predicted = ndc_to_grid_sample_coords(
              xy_ndc,
              image_size_square,
          )
          self.assertClose(xy_gs_predicted, xy_gs)
  
      # batched version
      xy_ndc, xy_gs = xy_ndc_gs_square[:, 0], xy_ndc_gs_square[:, 1]
      xy_gs_predicted = ndc_to_grid_sample_coords(
          xy_ndc,
          image_size_square,
      )
      self.assertClose(xy_gs_predicted, xy_gs)
  
      # non-square image tests
      image_size = [100, 200]
      xy_ndc_gs = torch.FloatTensor(
          [
              # 4 corners
              [[-2.0, -1.0], [1.0, 1.0]],
              [[2.0, -1.0], [-1.0, 1.0]],
              [[-2.0, 1.0], [1.0, -1.0]],
              [[2.0, 1.0], [-1.0, -1.0]],
              # center
              [[0.0, 0.0], [0.0, 0.0]],
              # non-corner points
              [[4.0, 0.5], [-2.0, -0.5]],
              [[1.0, -0.5], [-0.5, 0.5]],
          ]
      )
  
      # check both H > W and W > H
      for flip_axes in [False, True]:
          # non-batched version
          for xy_ndc, xy_gs in xy_ndc_gs:
              xy_gs_predicted = ndc_to_grid_sample_coords(
                  xy_ndc.flip(dims=(-1,)) if flip_axes else xy_ndc,
                  list(reversed(image_size))
                  if flip_axes
                  else image_size,
              )
              self.assertClose(
                  xy_gs_predicted,
                  xy_gs.flip(dims=(-1,)) if flip_axes else xy_gs,
              )
  
          # batched version
          xy_ndc, xy_gs = xy_ndc_gs[:, 0], xy_ndc_gs[:, 1]
          xy_gs_predicted = ndc_to_grid_sample_coords(
              xy_ndc.flip(dims=(-1,)) if flip_axes else xy_ndc,
              list(reversed(image_size)) if flip_axes else image_size,
          )
          self.assertClose(
              xy_gs_predicted,
              xy_gs.flip(dims=(-1,)) if flip_axes else xy_gs,
          )
  
imports: import unittest
  import numpy
  import torch
  from pytorch3d.common.compat import meshgrid_ij
  from pytorch3d.ops import eyes
  from pytorch3d.renderer import AlphaCompositor, PerspectiveCameras, PointsRasterizationSettings, PointsRasterizer, PointsRenderer
  from pytorch3d.renderer.utils import ndc_grid_sample, ndc_to_grid_sample_coords, TensorProperties
  from pytorch3d.structures import Pointclouds
  from .common_testing import TestCaseMixin
label_desc: Use image node_id 8 for calling the TestTensorProperties obj's underlying member method code with example usage: obj.test_ndc_to_grid_sample_coords() without return types