code: def _calc_unique_ir(
      data,
      argsorted_indices,
      inc_scan,
      index_converter,
      unique_elements,
      inverse_indices,
      counts,
  ):
      """Low level IR to calculate unique elements, inverse indices, and counts (optional) of
      unique elements of 1-D array.
  
      Parameters
      ----------
      data : Buffer
          Input 1-D Buffer.
  
      argsorted_indices : Buffer
          A buffer that stores the argsorted indices of the input data.
  
      inc_scan : Buffer
          A buffer that stores the inclusive scan of the binary tir.NE adjacent difference
          of the sorted data.
  
      index_converter (optional) : Buffer
          An optional index converter that transforms the unique element index
          such that new_idx = index_converter[old_idx].
  
      unique_elements : Buffer
          A buffer that stores the unique elements.
  
      inverse_indices : Buffer
          A buffer that stores the index of each input data element in the unique element array.
  
      counts (optional) : Buffer
          A buffer that stores the count of each unique element.
      """
      ib = tir.ir_builder.create()
      data_ptr = ib.buffer_ptr(data)
      argsorted_indices_ptr = ib.buffer_ptr(argsorted_indices)
      inc_scan_ptr = ib.buffer_ptr(inc_scan)
      unique_elements_ptr = ib.buffer_ptr(unique_elements)
      inverse_indices_ptr = ib.buffer_ptr(inverse_indices)
  
      index_converter_ptr = None
      if isinstance(index_converter, tir.Buffer):
          index_converter_ptr = ib.buffer_ptr(index_converter)
  
      if isinstance(counts, tir.Buffer):
          counts_ptr = ib.buffer_ptr(counts)
          # use indices_ptr as a tmp buffer to store tids with inc_scan[tid] != inc_scan[tid-1]
          unique_seq_indices_ptr = ib.buffer_ptr(inverse_indices)
  
      data_length = data.shape[0]
  
      # if need to return counts
      if isinstance(counts, tir.Buffer):
          num_unique = inc_scan_ptr[inc_scan.shape[0] - 1] + 1
          num_elements = data.shape[0]
          unique_seq_indices_ptr[num_unique - 1] = num_elements
          with ib.new_scope():
              with ib.for_range(0, data_length, kind="parallel") as i:
                  with ib.if_scope(i > 0):
                      with ib.if_scope(
                          inc_scan_ptr[i] != inc_scan_ptr[i - 1]
                      ):
                          unique_seq_indices_ptr[
                              inc_scan_ptr[i] - 1
                          ] = i
          with ib.new_scope():
              with ib.for_range(0, num_unique, kind="parallel") as i:
                  unique_idx = (
                      i
                      if not index_converter_ptr
                      else index_converter_ptr[i]
                  )
                  with ib.if_scope(i == 0):
                      counts_ptr[unique_idx] = unique_seq_indices_ptr[i]
                  with ib.else_scope():
                      counts_ptr[unique_idx] = (
                          unique_seq_indices_ptr[i]
                          - unique_seq_indices_ptr[i - 1]
                      )
      # calculate unique elements and inverse indices
      with ib.new_scope():
          with ib.for_range(0, data_length, kind="parallel") as i:
              data_idx = argsorted_indices_ptr[i]
              unique_idx = (
                  inc_scan_ptr[i]
                  if not index_converter_ptr
                  else index_converter_ptr[inc_scan_ptr[i]]
              )
              inverse_indices_ptr[data_idx] = unique_idx
              with ib.if_scope(i == 0):
                  unique_elements_ptr[unique_idx] = data_ptr[data_idx]
              with ib.else_scope():
                  with ib.if_scope(
                      inc_scan_ptr[i] != inc_scan_ptr[i - 1]
                  ):
                      unique_elements_ptr[unique_idx] = data_ptr[
                          data_idx
                      ]
      return ib.get()
  
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 4 for calling a global function with example usage: _calc_unique_ir(data, argsorted_indices, inc_scan, index_converter, unique_elements, inverse_indices, counts) and returns: ib