code: def piecewise_arange(piecewise_idxer: Tensor) -> Tensor:
      """
      count repeated indices
      Example:
      [0, 0, 0, 3, 3, 3, 3, 1, 1, 2] -> [0, 1, 2, 0, 1, 2, 3, 0, 1, 0]
      """
      dv = piecewise_idxer.device
      # print(piecewise_idxer)
      uni: Tensor
      uni, counts = torch.unique_consecutive(
          piecewise_idxer, return_counts=True
      )
      # print(counts)
      maxcnt = int(torch.max(counts).item())
      numuni = uni.shape[0]
      tmp = torch.zeros(size=(numuni, maxcnt), device=dv).bool()
      ranges = (
          torch.arange(maxcnt, device=dv)
          .unsqueeze(0)
          .expand(numuni, -1)
      )
      tmp[ranges < counts.unsqueeze(-1)] = True
      return ranges[tmp]
  
file_path: kornia/kornia/feature/adalam/utils.py
imports: import math
  from typing import Tuple
  import torch
  from kornia.core import Tensor
label_desc: Use image node_id 4 for calling a global function with example usage: piecewise_arange(piecewise_idxer) and returns: ranges