code: def unique(data, is_sorted=True, return_counts=False):
      """
      Find the unique elements of a 1-D tensor. Please note `output` and `counts` are all padded to
      have the same length of `data` and element with index >= num_unique[0] has undefined value.
  
      Parameters
      ----------
      data : tvm.te.Tensor
          A 1-D tensor of integers.
  
      sorted : bool
          Whether to sort the unique elements in ascending order before returning as output.
  
      return_counts : bool
          Whether to return the count of each unique element.
  
      Returns
      -------
      unique : tvm.te.Tensor
          A 1-D tensor containing the unique elements of the input data tensor. The same size as
          the input data. If there are less unique elements than input data, the end of the tensor
          is padded with zeros.
  
      indices : tvm.te.Tensor
          A 1-D tensor. The same size as output. For each entry in output, it contains
          the index of its first occurence in the input data. The end of the tensor is padded
          with the length of the input data.
  
      inverse_indices : tvm.te.Tensor
          A 1-D tensor. For each entry in data, it contains the index of that data element in
          the unique array. (Note that inverse_indices is very similar to indices if output is not
          sorted.)
  
      num_unique : tvm.te.Tensor
          A 1-D tensor with size=1 containing the number of unique elements in the input data tensor.
  
      counts (optional) : tvm.te.Tensor
          A 1-D tensor containing the count of each unique element in the output.
  
      Examples
      --------
      .. code-block:: python
  
          [output, indices, num_unique] = unique([4, 5, 1, 2, 3, 3, 4, 5], False, False)
          output          =  [4, 5, 1, 2, 3, _, _, _]
          indices         =  [0, 1, 2, 3, 4, _, _, _]
          inverse_indices =  [0, 1, 2, 3, 4, 4, 0, 1]
          num_unique      =  [5]
  
          [output, indices, num_unique, counts] = unique([4, 5, 1, 2, 3, 3, 4, 5], False, True)
          output          =  [4, 5, 1, 2, 3, _, _, _]
          indices         =  [0, 1, 2, 3, 4, _, _, _]
          inverse_indices =  [0, 1, 2, 3, 4, 4, 0, 1]
          num_unique      =  [5]
          counts          =  [2, 2, 1, 1, 2, _, _, _]
  
          [output, indices, num_unique] = unique([4, 5, 1, 2, 3, 3, 4, 5], True)
          output          =  [1, 2, 3, 4, 5, _, _, _]
          indices         =  [2, 3, 4, 0, 1, _, _, _]
          inverse_indices =  [3, 4, 0, 1, 2, 2, 3, 4]
          num_unique      =  [5]
      """
      sorted_data = sort(data)
      argsorted_indices = argsort(data, dtype="int32")
      # adjacent difference
      adjacent_diff = _calc_adjacent_diff(sorted_data, "int32", tir.NE)
      # inclusive scan
      inc_scan = cumsum(adjacent_diff, dtype="int32", exclusive=0)
      # total number of unique elements
      num_unique_elements = _calc_num_unique(inc_scan)
      # prepare outputs
      if return_counts:
          out_data_shape = [data.shape] * 3
          out_dtypes = [data.dtype, "int32", "int32"]
      else:
          out_data_shape = [data.shape] * 2
          out_dtypes = [data.dtype, "int32"]
      # prepare inputs and fcompute
  
      first_occurence = _calc_first_occurence(
          argsorted_indices, inc_scan
      )
      if is_sorted:
          in_data = [data, argsorted_indices, inc_scan]
          if return_counts:
              fcompute = lambda ins, outs: _calc_unique_ir(
                  *ins, None, *outs
              )
          else:
              fcompute = lambda ins, outs: _calc_unique_ir(
                  *ins, None, *outs, None
              )
  
          indices = first_occurence
      else:
          # calculate index converter by sorting unique elements by their first occurence
          argsorted_first_occurence = argsort(
              first_occurence, dtype="int32"
          )
          index_converter = argsort(
              argsorted_first_occurence, dtype="int32"
          )
          in_data = [data, argsorted_indices, inc_scan, index_converter]
          if return_counts:
              fcompute = lambda ins, outs: _calc_unique_ir(*ins, *outs)
          else:
              fcompute = lambda ins, outs: _calc_unique_ir(
                  *ins, *outs, None
              )
          # First occurence is in order of sorted unique output, if we sort the first_occurence array
          # we get the correct result
          indices = sort(first_occurence)
  
      outs = te.extern(
          out_data_shape,
          in_data,
          fcompute,
          dtype=out_dtypes,
          name="_calc_unique",
          tag="_calc_unique_cpu",
      )
      if return_counts:
          return [
              outs[0],
              indices,
              outs[1],
              num_unique_elements,
              outs[2],
          ]
      return [outs[0], indices, outs[1], num_unique_elements]
  
file_path: tvm/python/tvm/topi/unique.py
imports: from tvm import te, tir
  from ..te import hybrid
  from .scan import cumsum
  from .sort import sort, argsort
label_desc: Use image node_id 6 for calling a global function with example usage: unique(data, is_sorted, return_counts) and returns: list, list