class_docstr: Tests for identifying inverse relationships and leakage.
class_docstr_tok: ["Tests","for","identifying","inverse","relationships","and","leakage","."]
docstr: Test :func:`_generate_compact_vectorized_lookup`.
docstr_tok: ["Test",":","func",":","`","_generate_compact_vectorized_lookup","`","."]
code: def test_generate_compact_vectorized_lookup(self):
      """Test :func:`_generate_compact_vectorized_lookup`."""
      max_id = 13
      ids = 2 * torch.randint(max_id, size=(2, 5))
      label_to_id = {f"e_{i}": i for i in range(2 * max_id)}
      new_label_to_id, mapping = _generate_compact_vectorized_lookup(
          ids=ids,
          label_to_id=label_to_id,
      )
      # test new label to ID
      # type
      assert isinstance(new_label_to_id, dict)
      # old labels
      assert set(new_label_to_id.keys()) == {
          f"e_{i}" for i in ids.unique().tolist()
      }
      # new, compact IDs
      assert set(new_label_to_id.values()) == set(
          range(len(ids.unique()))
      )
  
      # test vectorized lookup
      # type
      assert torch.is_tensor(mapping)
      assert mapping.dtype == torch.long
      # shape
      assert mapping.shape == (ids.max() + 1,)
      # value range
      assert (mapping >= -1).all()
      # only occurring Ids get mapped to non-negative numbers
      assert set((mapping >= 0).nonzero().view(-1).tolist()) == set(
          ids.unique().tolist()
      )
      # Ids are mapped to (0, ..., num_unique_ids-1)
      assert set(mapping[mapping >= 0].tolist()) == set(
          range(len(ids.unique()))
      )
  
file_path: pykeen/tests/test_leakage.py
imports: import itertools
  import unittest
  import numpy
  import numpy
  import scipy.sparse
  import torch
  from pykeen.datasets import Nations
  from pykeen.triples import TriplesFactory
  from pykeen.triples.leakage import Sealant, _generate_compact_vectorized_lookup, _translate_triples, get_candidate_pairs, jaccard_similarity_scipy, mapped_triples_to_sparse_matrices, triples_factory_to_sparse_matrices
label_desc: Use image node_id 2 for calling the TestLeakage obj's underlying member method code with example usage: obj.test_generate_compact_vectorized_lookup() without return types