code: def hpdi(input, prob, dim=0):
      """
      Computes "highest posterior density interval" which is the narrowest
      interval with probability mass ``prob``.
  
      :param torch.Tensor input: the input tensor.
      :param float prob: the probability mass of samples within the interval.
      :param int dim: dimension to calculate percentile interval from ``input``.
      :returns torch.Tensor: quantiles of ``input`` at ``probs``.
      """
      sorted_input = input.sort(dim)[0]
      mass = input.size(dim)
      index_length = int(prob * mass)
      intervals_left = sorted_input.index_select(
          dim,
          torch.tensor(
              range(mass - index_length),
              dtype=torch.long,
              device=input.device,
          ),
      )
      intervals_right = sorted_input.index_select(
          dim,
          torch.tensor(
              range(index_length, mass),
              dtype=torch.long,
              device=input.device,
          ),
      )
      intervals_length = intervals_right - intervals_left
      index_start = intervals_length.argmin(dim)
      indices = torch.stack(
          [index_start, index_start + index_length], dim
      )
      return torch.gather(sorted_input, dim, indices)
  
imports: import math
  import numbers
  import torch
  from torch.fft import irfft, rfft
  from .tensor_utils import next_fast_len
label_desc: Use image node_id 11 for calling a global function with example usage: hpdi(input, prob, dim) and returns: torch