code: def create_index(
      mapped_triples: MappedTriples,
      num_relations: int,
  ) -> Tuple[torch.LongTensor, torch.LongTensor]:
      """
      Create an index for efficient vectorized pseudo-type negative sampling.
  
      For this sampling, we need to store for each relation the set of head / tail entities. For efficient
      vectorized sampling, the following data structure is employed, which is partially inspired by the
      CSR format of sparse matrices (cf. :class:`scipy.sparse.csr_matrix`).
  
      We use two arrays, ``offsets`` and ``data``. The `offsets` array is of shape ``(2 * num_relations + 1,)``.
      The ``data`` array contains the sorted set of heads and tails for each relation, i.e.
      ``data[offsets[2*r]:offsets[2*r+1]]`` are the IDs of head entities for relation ``r``, and
      ``data[offsets[2*r+1]:offsets[2*r+2]]`` the ID of tail entities.
  
      :param mapped_triples:
          the mapped triples
      :param num_relations:
          the number of relations
  
      :return:
          A pair (data, offsets) containing the compressed triples.
      """
      heads, tails = create_relation_to_entity_set_mapping(
          triples=mapped_triples.tolist()
      )
      relations = set(heads.keys()).union(tails.keys())
  
      # TODO: move this warning to PseudoTypeNegativeSampler's constructor?
      for r in relations:
          if len(heads[r]) < 2 and len(tails[r]) < 2:
              logger.warning(
                  f"Relation {r} does not have a sufficient number of distinct heads and tails."
              )
  
      # create index structure
      data = []
      offsets = torch.empty(2 * num_relations + 1, dtype=torch.long)
      offsets[0] = 0
      for i, (r, m) in enumerate(
          itertools.product(range(num_relations), (heads, tails)),
          start=1,
      ):
          data.extend(sorted(m[r]))
          offsets[i] = len(data)
      data = torch.as_tensor(data=data, dtype=torch.long)
      return data, offsets
  
file_path: pykeen/src/pykeen/sampling/pseudo_type.py
imports: import itertools
  import logging
  from typing import Tuple
  import torch
  from .negative_sampler import NegativeSampler
  from ..typing import MappedTriples
  from ..utils import create_relation_to_entity_set_mapping
label_desc: Use image node_id 1 for calling a global function with example usage: create_index(mapped_triples, num_relations) and returns: data,  offsets