class_docstr: Samples a fixed number of pixels within denoted xy bounds uniformly at random.
  For each pixel, a fixed number of points is sampled along its ray at uniformly-spaced
  z-coordinates such that the z-coordinates range between a predefined minimum
  and maximum depth.
  
  For practical purposes, this is similar to MultinomialRaysampler without a mask,
  however sampling at real-valued locations bypassing replacement checks may be faster.
class_docstr_tok: ["Samples","a","fixed","number","of","pixels","within","denoted","xy","bounds","uniformly","at","random",".","For","each","pixel",",","a","fixed","number","of","points","is","sampled","along","its","ray","at","uniformly-spaced","z-coordinates","such","that","the","z-coordinates","range","between","a","predefined","minimum","and","maximum","depth",".","For","practical","purposes",",","this","is","similar","to","MultinomialRaysampler","without","a","mask",",","however","sampling","at","real-valued","locations","bypassing","replacement","checks","may","be","faster","."]
docstr: Args:
      cameras: A batch of `batch_size` cameras from which the rays are emitted.
      stratified_sampling: if set, overrides stratified_sampling provided
          in __init__.
  Returns:
      A named tuple `RayBundle` or dataclass `HeterogeneousRayBundle` with the
      following fields:
  
      origins: A tensor of shape
          `(batch_size, n_rays_per_image, 3)`
          denoting the locations of ray origins in the world coordinates.
      directions: A tensor of shape
          `(batch_size, n_rays_per_image, 3)`
          denoting the directions of each ray in the world coordinates.
      lengths: A tensor of shape
          `(batch_size, n_rays_per_image, n_pts_per_ray)`
          containing the z-coordinate (=depth) of each ray in world units.
      xys: A tensor of shape
          `(batch_size, n_rays_per_image, 2)`
          containing the 2D image coordinates of each ray.
      If `n_rays_total` is provided `batch_size=n_rays_total`and
      `n_rays_per_image=1` and `HeterogeneousRayBundle` is returned else `RayBundle`
      is returned.
  
      `HeterogeneousRayBundle` has additional members:
          - camera_ids: tensor of shape (M,), where `M` is the number of unique sampled
              cameras. It represents unique ids of sampled cameras.
          - camera_counts: tensor of shape (M,), where `M` is the number of unique sampled
              cameras. Represents how many times each camera from `camera_ids` was sampled
docstr_tok: ["Args",":","cameras",":","A","batch","of","`","batch_size","`","cameras","from","which","the","rays","are","emitted",".","stratified_sampling",":","if","set",",","overrides","stratified_sampling","provided","in","__init__",".","Returns",":","A","named","tuple","`","RayBundle","`","or","dataclass","`","HeterogeneousRayBundle","`","with","the","following","fields",":","origins",":","A","tensor","of","shape","`","(","batch_size",",","n_rays_per_image",",","3",")","`","denoting","the","locations","of","ray","origins","in","the","world","coordinates",".","directions",":","A","tensor","of","shape","`","(","batch_size",",","n_rays_per_image",",","3",")","`","denoting","the","directions","of","each","ray","in","the","world","coordinates",".","lengths",":","A","tensor","of","shape","`","(","batch_size",",","n_rays_per_image",",","n_pts_per_ray",")","`","containing","the","z-coordinate","(","=depth",")","of","each","ray","in","world","units",".","xys",":","A","tensor","of","shape","`","(","batch_size",",","n_rays_per_image",",","2",")","`","containing","the","2D","image","coordinates","of","each","ray",".","If","`","n_rays_total","`","is","provided","`","batch_size=n_rays_total","`","and","`","n_rays_per_image=1","`","and","`","HeterogeneousRayBundle","`","is","returned","else","`","RayBundle","`","is","returned",".","`","HeterogeneousRayBundle","`","has","additional","members",":","-","camera_ids",":","tensor","of","shape","(","M",",",")",",","where","`","M","`","is","the","number","of","unique","sampled","cameras",".","It","represents","unique","ids","of","sampled","cameras",".","-","camera_counts",":","tensor","of","shape","(","M",",",")",",","where","`","M","`","is","the","number","of","unique","sampled","cameras",".","Represents","how","many","times","each","camera","from","`","camera_ids","`","was","sampled"]
code: def forward(
      self,
      cameras: CamerasBase,
      *,
      stratified_sampling: Optional[bool] = None,
      **kwargs,
  ) -> Union[RayBundle, HeterogeneousRayBundle]:
      """
      Args:
          cameras: A batch of `batch_size` cameras from which the rays are emitted.
          stratified_sampling: if set, overrides stratified_sampling provided
              in __init__.
      Returns:
          A named tuple `RayBundle` or dataclass `HeterogeneousRayBundle` with the
          following fields:
  
          origins: A tensor of shape
              `(batch_size, n_rays_per_image, 3)`
              denoting the locations of ray origins in the world coordinates.
          directions: A tensor of shape
              `(batch_size, n_rays_per_image, 3)`
              denoting the directions of each ray in the world coordinates.
          lengths: A tensor of shape
              `(batch_size, n_rays_per_image, n_pts_per_ray)`
              containing the z-coordinate (=depth) of each ray in world units.
          xys: A tensor of shape
              `(batch_size, n_rays_per_image, 2)`
              containing the 2D image coordinates of each ray.
          If `n_rays_total` is provided `batch_size=n_rays_total`and
          `n_rays_per_image=1` and `HeterogeneousRayBundle` is returned else `RayBundle`
          is returned.
  
          `HeterogeneousRayBundle` has additional members:
              - camera_ids: tensor of shape (M,), where `M` is the number of unique sampled
                  cameras. It represents unique ids of sampled cameras.
              - camera_counts: tensor of shape (M,), where `M` is the number of unique sampled
                  cameras. Represents how many times each camera from `camera_ids` was sampled
      """
      if (
          sum(
              x is not None
              for x in [self._n_rays_total, self._n_rays_per_image]
          )
          != 1
      ):
          raise ValueError(
              "Exactly one of `self.n_rays_total` and `self.n_rays_per_image` "
              "must be given."
          )
  
      if self._n_rays_total:
          (
              cameras,
              _,
              camera_ids,
              camera_counts,
              n_rays_per_image,
          ) = _sample_cameras_and_masks(
              self._n_rays_total, cameras, None
          )
      else:
          # pyre-ignore[9]
          camera_ids: torch.LongTensor = torch.arange(
              len(cameras), dtype=torch.long
          )
          n_rays_per_image = self._n_rays_per_image
  
      batch_size = cameras.R.shape[0]
  
      device = cameras.device
  
      # get the initial grid of image xy coords
      # of shape (batch_size, n_rays_per_image, 2)
      rays_xy = torch.cat(
          [
              torch.rand(
                  size=(batch_size, n_rays_per_image, 1),
                  dtype=torch.float32,
                  device=device,
              )
              * (high - low)
              + low
              for low, high in (
                  (self._min_x, self._max_x),
                  (self._min_y, self._max_y),
              )
          ],
          dim=2,
      )
  
      stratified_sampling = (
          stratified_sampling
          if stratified_sampling is not None
          else self._stratified_sampling
      )
  
      ray_bundle = _xy_to_ray_bundle(
          cameras,
          rays_xy,
          self._min_depth,
          self._max_depth,
          self._n_pts_per_ray,
          self._unit_directions,
          stratified_sampling,
      )
  
      return (
          # pyre-ignore[61]
          _pack_ray_bundle(ray_bundle, camera_ids, camera_counts)
          if self._n_rays_total
          else ray_bundle
      )
  
imports: import warnings
  from typing import Optional, Tuple, Union
  import torch
  from pytorch3d.common.compat import meshgrid_ij
  from pytorch3d.ops import padded_to_packed
  from pytorch3d.renderer.cameras import CamerasBase
  from pytorch3d.renderer.implicit.utils import HeterogeneousRayBundle, RayBundle
  from torch.nn import functional
label_desc: Use image node_id 2 for calling the MonteCarloRaysampler obj's underlying member method code with example usage: obj.forward(cameras) and returns: unknown