code: def jaccard_similarity_scipy(
      a: scipy.sparse.spmatrix,
      b: scipy.sparse.spmatrix,
  ) -> numpy.ndarray:
      r"""Compute the Jaccard similarity between sets represented as sparse matrices.
  
      The similarity is computed as
  
      .. math ::
          J(A, B) = \frac{|A \cap B|}{|A \cup B|}
                  = \frac{|A \cap B|}{|A| + |B| - |A \cap B|}
  
      where the intersection can be computed in one batch as matrix product.
  
      :param a: shape: (m, max_num_elements)
          The first sets.
      :param b: shape: (n, max_num_elements)
          The second sets.
  
      :return: shape: (m, n)
          The pairwise Jaccard similarity.
      """
      sum_size = numpy.asarray(a.sum(axis=1) + b.sum(axis=1).T)
      intersection_size = numpy.asarray((a @ b.T).todense())
      # safe division for empty sets
      divisor = numpy.clip(
          sum_size - intersection_size, a_min=1, a_max=None
      )
      return intersection_size / divisor
  
imports: import logging
  from typing import Collection, Iterable, List, Mapping, Optional, Set, Tuple, TypeVar, Union, cast
  import click
  import numpy
  import scipy.sparse
  import torch
  from pykeen.datasets.base import EagerDataset
  from pykeen.triples.triples_factory import CoreTriplesFactory, TriplesFactory, cat_triples
  from pykeen.typing import MappedTriples
  from pykeen.utils import compact_mapping, get_connected_components
label_desc: Use image node_id 2 for calling a global function with example usage: jaccard_similarity_scipy(a, b) and returns: unknown