docstr: Test the correctness of the conversion between the internal
  Transform3D Volumes.VolumeLocator._local_to_world_transform and the initialization
  from the translation and voxel_size.
docstr_tok: ["Test","the","correctness","of","the","conversion","between","the","internal","Transform3D","Volumes.VolumeLocator._local_to_world_transform","and","the","initialization","from","the","translation","and","voxel_size","."]
code: def test_coord_transforms(
      self, num_volumes=3, num_channels=4, dtype=torch.float32
  ):
      """
      Test the correctness of the conversion between the internal
      Transform3D Volumes.VolumeLocator._local_to_world_transform and the initialization
      from the translation and voxel_size.
      """
  
      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()
  
          densities = torch.randn(
              size=[num_volumes, num_channels, *size],
              device=device,
              dtype=torch.float32,
          )
  
          # init the transformation params
          volume_translation = torch.randn(num_volumes, 3)
          voxel_size = torch.rand(num_volumes, 3) * 3.0 + 0.5
  
          # get the corresponding Transform3d object
          local_offset = torch.tensor(
              list(size), dtype=torch.float32, device=device
          )[[2, 1, 0]][None].repeat(num_volumes, 1)
          local_to_world_transform = (
              Scale(0.5 * local_offset - 0.5, device=device)
              .scale(voxel_size)
              .translate(-volume_translation)
          )
  
          # init the volume structures with the scale and translation,
          # then get the coord grid in world coords
          v_trans_vs = Volumes(
              densities=densities,
              voxel_size=voxel_size,
              volume_translation=volume_translation,
          )
          grid_rot_trans_vs = v_trans_vs.get_coord_grid(
              world_coordinates=True
          )
  
          # map the default local coords to the world coords
          # with local_to_world_transform
          v_default = Volumes(densities=densities)
          grid_default_local = v_default.get_coord_grid(
              world_coordinates=False
          )
          grid_default_world = (
              local_to_world_transform.transform_points(
                  grid_default_local.view(num_volumes, -1, 3)
              ).view(num_volumes, *size, 3)
          )
  
          # check that both grids are the same
          self.assertClose(
              grid_rot_trans_vs, grid_default_world, atol=1e-5
          )
  
          # check that the transformations are the same
          self.assertClose(
              v_trans_vs.get_local_to_world_coords_transform().get_matrix(),
              local_to_world_transform.get_matrix(),
              atol=1e-5,
          )
  
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 6 for calling the TestVolumes obj's underlying member method code with example usage: obj.test_coord_transforms(num_volumes, num_channels, dtype) without return types