docstr: Test whether conversion between local-world coordinates of the
  volume returns correct results.
docstr_tok: ["Test","whether","conversion","between","local-world","coordinates","of","the","volume","returns","correct","results","."]
code: def test_coord_grid_transforms(
      self, num_volumes=3, num_channels=4, dtype=torch.float32
  ):
      """
      Test whether conversion between local-world coordinates of the
      volume returns correct results.
      """
  
      device = torch.device("cuda:0")
  
      # try for 10 sets of different random sizes/centers/voxel_sizes
      for _ in range(10):
          size = torch.randint(high=10, size=(3,), low=3).tolist()
  
          center = torch.randn(
              num_volumes, 3, dtype=torch.float32, device=device
          )
          voxel_size = (
              torch.rand(1, dtype=torch.float32, device=device) * 5.0
              + 0.5
          )
  
          for densities in (
              torch.randn(
                  size=[num_volumes, num_channels, *size],
                  device=device,
                  dtype=torch.float32,
              ),
              TestVolumes._random_volume_list(
                  num_volumes,
                  3,
                  size,
                  num_channels,
                  device,
                  rand_sizes=None,
              )[0],
          ):
              # init the volume structure
              v = Volumes(
                  densities=densities,
                  voxel_size=voxel_size,
                  volume_translation=-center,
              )
  
              # get local coord grid
              grid_local = v.get_coord_grid(world_coordinates=False)
  
              # convert from world to local to world
              grid_world = v.get_coord_grid(world_coordinates=True)
              grid_local_2 = v.world_to_local_coords(grid_world)
              grid_world_2 = v.local_to_world_coords(grid_local_2)
  
              # assertions on shape and values of grid_world and grid_local
              self.assertClose(grid_world, grid_world_2, atol=1e-5)
              self.assertClose(grid_local, grid_local_2, atol=1e-5)
  
              # check that the individual slices of the location grid have
              # constant values along expected dimensions
              for plane_dim in (1, 2, 3):
                  for grid_plane in grid_world.split(1, dim=plane_dim):
                      grid_coord_dim = {1: 2, 2: 1, 3: 0}[plane_dim]
                      grid_coord_plane = grid_plane.squeeze()[
                          ..., grid_coord_dim
                      ]
                      # check that all elements of grid_coord_plane are
                      # the same for each batch element
                      self.assertClose(
                          grid_coord_plane.reshape(num_volumes, -1)
                          .max(dim=1)
                          .values,
                          grid_coord_plane.reshape(num_volumes, -1)
                          .min(dim=1)
                          .values,
                      )
  
imports: import copy
  import itertools
  import random
  import unittest
  import numpy
  import torch
  from pytorch3d.structures.volumes import VolumeLocator, Volumes
  from pytorch3d.transforms import Scale
  from .common_testing import TestCaseMixin
label_desc: Use image node_id 9 for calling the TestVolumes obj's underlying member method code with example usage: obj.test_coord_grid_transforms(num_volumes, num_channels, dtype) without return types