code: def create_sparse_positive_filter_(
      hrt_batch: MappedTriples,
      all_pos_triples: torch.LongTensor,
      relation_filter: torch.BoolTensor | None = None,
      filter_col: int = 0,
  ) -> Tuple[torch.LongTensor, torch.BoolTensor]:
      """Compute indices of all positives.
  
      For simplicity, only the head-side is described, i.e. filter_col=0. The tail-side is processed alike.
  
      For each (h, r, t) triple in the batch, the entity identifiers are computed such that (h', r, t) exists in all
      positive triples.
  
      :param hrt_batch: shape: (batch_size, 3)
          A batch of triples.
      :param all_pos_triples: shape: (num_positive_triples, 3)
          All positive triples to base the filtering on.
      :param relation_filter: shape: (batch_size, num_positive_triples)
          A boolean mask R[i, j] which is True iff the j-th positive triple contains the same relation as the i-th triple
          in the batch.
      :param filter_col:
          The column along which to filter. Allowed are {0, 2}, where 0 corresponds to filtering head-based and 2
          corresponds to filtering tail-based.
  
      :return:
          - positives, shape: (2, m)
              The indices of positives in format [(batch_index, entity_id)].
          - the relation filter for re-usage.
  
      :raises NotImplementedError:
          if the `filter_col` is not in `{0, 2}`
      """
      if filter_col not in {0, 2}:
          raise NotImplementedError(
              "This code has only been written for updating head (filter_col=0) or "
              f"tail (filter_col=2) mask, but filter_col={filter_col} was given.",
          )
  
      if relation_filter is None:
          relations = hrt_batch[:, 1:2]
          relation_filter = (all_pos_triples[:, 1:2]).view(
              1, -1
          ) == relations
  
      # Split batch
      other_col = 2 - filter_col
      entities = hrt_batch[:, other_col : other_col + 1]
  
      entity_filter_test = (
          all_pos_triples[:, other_col : other_col + 1]
      ).view(1, -1) == entities
      filter_batch = (entity_filter_test & relation_filter).nonzero(
          as_tuple=False
      )
      filter_batch[:, 1] = all_pos_triples[
          :, filter_col : filter_col + 1
      ].view(1, -1)[:, filter_batch[:, 1]]
  
      return filter_batch, relation_filter
  
imports: from __future__ import annotations
  import logging
  import timeit
  import warnings
  from abc import ABC, abstractmethod
  from collections import ChainMap
  from typing import Any, ClassVar, Collection, Generic, List, Mapping, NamedTuple, Optional, Tuple, Type, TypeVar, Union, cast
  import pandas
  import torch
  from torch_max_mem import maximize_memory_utilization
  from tqdm.autonotebook import tqdm
  from ..constants import COLUMN_LABELS, TARGET_TO_INDEX, TARGET_TO_KEY_LABELS
  from ..metrics.utils import Metric
  from ..models import Model
  from ..triples.triples_factory import restrict_triples
  from ..triples.utils import get_entities, get_relations
  from ..typing import LABEL_HEAD, LABEL_RELATION, LABEL_TAIL, InductiveMode, MappedTriples, Target
  from ..utils import flatten_dictionary, format_relative_comparison, normalize_string, prepare_filter_triples
label_desc: Use image node_id 3 for calling a global function with example usage: create_sparse_positive_filter_(hrt_batch, all_pos_triples, relation_filter, filter_col) and returns: filter_batch,  relation_filter