code: def _bincount(x: Tensor, minlength: Optional[int] = None) -> Tensor:
      """PyTorch currently does not support``torch.bincount`` for:
  
          - deterministic mode on GPU.
          - MPS devices
  
      This implementation fallback to a for-loop counting occurrences in that case.
  
      Args:
          x: tensor to count
          minlength: minimum length to count
  
      Returns:
          Number of occurrences for each unique element in x
      """
      if minlength is None:
          minlength = len(torch.unique(x))
      if (
          torch.are_deterministic_algorithms_enabled()
          or _XLA_AVAILABLE
          or _TORCH_GREATER_EQUAL_1_12
          and x.is_mps
      ):
          output = torch.zeros(
              minlength, device=x.device, dtype=torch.long
          )
          for i in range(minlength):
              output[i] = (x == i).sum()
          return output
      return torch.bincount(x, minlength=minlength)
  
imports: from typing import Optional
  import torch
  from torch import Tensor
  from torchmetrics.utilities.imports import _TORCH_GREATER_EQUAL_1_12
label_desc: Use image node_id 1 for calling a global function with example usage: _bincount(x, minlength) and returns: torch, output