code: def _pack_ray_bundle(
      ray_bundle: RayBundle,
      camera_ids: torch.LongTensor,
      camera_counts: torch.LongTensor,
  ) -> HeterogeneousRayBundle:
      """
      Pack the raybundle from [n_cameras, max(rays_per_camera), ...] to
          [total_num_rays, 1, ...]
  
      Args:
          ray_bundle: A ray_bundle to pack
          camera_ids: Unique ids of cameras that were sampled
          camera_counts: how many of which camera to pack, each count coresponds to
              one 'row' of the ray_bundle and says how many rays wll be taken
              from it and packed.
      Returns:
          HeterogeneousRayBundle where batch_size=sum(camera_counts) and n_rays_per_image=1
      """
      # pyre-ignore[9]
      camera_counts = camera_counts.to(ray_bundle.origins.device)
      cumsum = torch.cumsum(camera_counts, dim=0, dtype=torch.long)
      # pyre-ignore[9]
      first_idxs: torch.LongTensor = torch.cat(
          (camera_counts.new_zeros((1,), dtype=torch.long), cumsum[:-1])
      )
      num_inputs = int(camera_counts.sum())
  
      return HeterogeneousRayBundle(
          origins=padded_to_packed(
              ray_bundle.origins, first_idxs, num_inputs
          )[:, None],
          directions=padded_to_packed(
              ray_bundle.directions, first_idxs, num_inputs
          )[:, None],
          lengths=padded_to_packed(
              ray_bundle.lengths, first_idxs, num_inputs
          )[:, None],
          xys=padded_to_packed(ray_bundle.xys, first_idxs, num_inputs)[
              :, None
          ],
          camera_ids=camera_ids,
          camera_counts=camera_counts,
      )
  
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 7 for calling a global function with example usage: _pack_ray_bundle(ray_bundle, camera_ids, camera_counts) and returns: HeterogeneousRayBundle