code: def _iou_compute(
      iou: torch.Tensor, aggregate: bool = True
  ) -> torch.Tensor:
      if not aggregate:
          return iou
      return (
          iou.diag().mean()
          if iou.numel() > 0
          else torch.tensor(0.0, device=iou.device)
      )
  
imports: from typing import Optional
  import torch
  from torchmetrics.utilities.imports import _TORCHVISION_GREATER_EQUAL_0_8
label_desc: Use image node_id 2 for calling a global function with example usage: _iou_compute(iou, aggregate) and returns: unknown, iou