docstr: Tests the shapes and outputs of MC and GridRaysamplers for randomly
  generated cameras and different numbers of points per ray.
docstr_tok: ["Tests","the","shapes","and","outputs","of","MC","and","GridRaysamplers","for","randomly","generated","cameras","and","different","numbers","of","points","per","ray","."]
code: def test_raysamplers(
      self,
      batch_size=25,
      min_x=-1.0,
      max_x=1.0,
      min_y=-1.0,
      max_y=1.0,
      image_width=10,
      image_height=20,
      min_depth=1.0,
      max_depth=10.0,
  ):
      """
      Tests the shapes and outputs of MC and GridRaysamplers for randomly
      generated cameras and different numbers of points per ray.
      """
  
      device = torch.device("cuda")
  
      for n_pts_per_ray in (100, 1):
          for raysampler_type in (
              MonteCarloRaysampler,
              MultinomialRaysampler,
              NDCMultinomialRaysampler,
          ):
              raysampler = TestRaysampling.init_raysampler(
                  raysampler_type=raysampler_type,
                  min_x=min_x,
                  max_x=max_x,
                  min_y=min_y,
                  max_y=max_y,
                  image_width=image_width,
                  image_height=image_height,
                  min_depth=min_depth,
                  max_depth=max_depth,
                  n_pts_per_ray=n_pts_per_ray,
              )
  
              if issubclass(raysampler_type, NDCMultinomialRaysampler):
                  # adjust the gt bounds for NDCGridRaysampler
                  if image_width >= image_height:
                      range_x = image_width / image_height
                      range_y = 1.0
                  else:
                      range_x = 1.0
                      range_y = image_height / image_width
  
                  half_pix_width = range_x / image_width
                  half_pix_height = range_y / image_height
                  min_x_ = range_x - half_pix_width
                  max_x_ = -range_x + half_pix_width
                  min_y_ = range_y - half_pix_height
                  max_y_ = -range_y + half_pix_height
              else:
                  min_x_ = min_x
                  max_x_ = max_x
                  min_y_ = min_y
                  max_y_ = max_y
  
              # carry out the test over several camera types
              for cam_type in (
                  FoVPerspectiveCameras,
                  FoVOrthographicCameras,
                  OrthographicCameras,
                  PerspectiveCameras,
              ):
                  # init a batch of random cameras
                  cameras = init_random_cameras(
                      cam_type, batch_size, random_z=True
                  ).to(device)
  
                  # call the raysampler
                  ray_bundle = raysampler(cameras=cameras)
  
                  # check the shapes of the raysampler outputs
                  self._check_raysampler_output_shapes(
                      raysampler,
                      ray_bundle,
                      batch_size,
                      image_width,
                      image_height,
                      n_pts_per_ray,
                  )
  
                  # check the points sampled along each ray
                  self._check_raysampler_ray_points(
                      raysampler,
                      cameras,
                      ray_bundle,
                      min_x_,
                      max_x_,
                      min_y_,
                      max_y_,
                      image_width,
                      image_height,
                      min_depth,
                      max_depth,
                  )
  
                  # check the output direction vectors
                  self._check_raysampler_ray_directions(
                      cameras, raysampler, ray_bundle
                  )
  
imports: import unittest
  from typing import Callable
  import torch
  from pytorch3d.common.compat import meshgrid_ij
  from pytorch3d.ops import eyes
  from pytorch3d.renderer import MonteCarloRaysampler, MultinomialRaysampler, NDCGridRaysampler, NDCMultinomialRaysampler
  from pytorch3d.renderer.cameras import FoVOrthographicCameras, FoVPerspectiveCameras, OrthographicCameras, PerspectiveCameras
  from pytorch3d.renderer.implicit.raysampling import _jiggle_within_stratas, _safe_multinomial
  from pytorch3d.renderer.implicit.utils import ray_bundle_to_ray_points, ray_bundle_variables_to_ray_points
  from pytorch3d.transforms import Rotate
  from .common_testing import TestCaseMixin
  from .test_cameras import init_random_cameras
label_desc: Use image node_id 4 for calling the TestRaysampling obj's underlying member method code with example usage: obj.test_raysamplers(batch_size, min_x, max_x, min_y, max_y, image_width, image_height, min_depth, max_depth) without return types