class_docstr: Class to manage random ray spatial sampling.
  
  Sampling is done on a regular grid of pixels by randomizing
  column and row values, and casting rays for all pixels along the selected ones.
  
  Args:
      min_depth: sampled rays minimal depth from cameras: float
      max_depth: sampled rays maximal depth from cameras: float
      ndc: convert to normalized device coordinates: bool
      device: device for ray tensors: Union[str, torch.device]
docstr: Randomly sample pixel points in 2d over a regular row-column grid.
  
  Args:
      heights: tensor that holds scene camera image heights (can vary between cameras): math: `(B)`.
      widths: tensor that holds scene camera image widths (can vary between cameras): math: `(B)`.
      num_img_rays: tensor that holds the number of rays to randomly cast from each scene camera. Number of rows
        and columns is the square root of this value: int math: `(B)`.
  
  Returns:
      dictionary of Points2D objects that holds information on pixel 2d coordinates of each ray and the camera
        id it was casted by: Dict[int, Points2D]
docstr_tok: ["Randomly","sample","pixel","points","in","2d","over","a","regular","row-column","grid",".","Args",":","heights",":","tensor","that","holds","scene","camera","image","heights","(","can","vary","between","cameras",")",":","math",":","`","(","B",")","`",".","widths",":","tensor","that","holds","scene","camera","image","widths","(","can","vary","between","cameras",")",":","math",":","`","(","B",")","`",".","num_img_rays",":","tensor","that","holds","the","number","of","rays","to","randomly","cast","from","each","scene","camera",".","Number","of","rows","and","columns","is","the","square","root","of","this","value",":","int","math",":","`","(","B",")","`",".","Returns",":","dictionary","of","Points2D","objects","that","holds","information","on","pixel","2d","coordinates","of","each","ray","and","the","camera","id","it","was","casted","by",":","Dict","[","int",",","Points2D","]"]
code: def sample_points_2d(
      self, heights: Tensor, widths: Tensor, num_img_rays: Tensor
  ) -> Dict[int, RaySampler.Points2D]:
      r"""Randomly sample pixel points in 2d over a regular row-column grid.
  
      Args:
          heights: tensor that holds scene camera image heights (can vary between cameras): math: `(B)`.
          widths: tensor that holds scene camera image widths (can vary between cameras): math: `(B)`.
          num_img_rays: tensor that holds the number of rays to randomly cast from each scene camera. Number of rows
            and columns is the square root of this value: int math: `(B)`.
  
      Returns:
          dictionary of Points2D objects that holds information on pixel 2d coordinates of each ray and the camera
            id it was casted by: Dict[int, Points2D]
      """
      num_img_rays = num_img_rays.int()
      points2d_as_flat_tensors: Dict[
          int, RaySampler.Points2D_FlatTensors
      ] = {}
      for camera_id, (height, width, n) in enumerate(
          zip(heights.tolist(), widths.tolist(), num_img_rays.tolist())
      ):
          n_sqrt = int(math.sqrt(n))
          y_rand = torch.randperm(
              int(height), device=self._device, dtype=self._dtype
          )[: min(int(height), n_sqrt)]
          x_rand = torch.randperm(
              int(width), device=self._device, dtype=self._dtype
          )[: min(int(width), n_sqrt)]
          y_grid, x_grid = torch_meshgrid(
              [y_rand, x_rand], indexing="ij"
          )
          RaySampler._add_points2d_as_flat_tensors_to_num_ray_dict(
              n_sqrt * n_sqrt,
              x_grid,
              y_grid,
              camera_id,
              points2d_as_flat_tensors,
          )
      return RaySampler._build_num_ray_dict_of_points2d(
          points2d_as_flat_tensors
      )
  
imports: import math
  from typing import Dict, List, Tuple
  import torch
  from kornia.core import Device, Tensor, tensor
  from kornia.geometry.camera import PinholeCamera
  from kornia.nerf.camera_utils import cameras_for_ids
  from kornia.utils._compat import torch_meshgrid
  from kornia.utils.helpers import _torch_inverse_cast
label_desc: Use image node_id 2 for calling the RandomGridRaySampler obj's underlying member method code with example usage: obj.sample_points_2d(heights, widths, num_img_rays) and returns: RaySampler