code: def discrete_metric_simplicial_set_intersection(
      simplicial_set,
      discrete_space,
      unknown_dist=1.0,
      far_dist=5.0,
      metric=None,
      metric_kws={},
      metric_scale=1.0,
  ):
      """Combine a fuzzy simplicial set with another fuzzy simplicial set
      generated from discrete metric data using discrete distances. The target
      data is assumed to be categorical label data (a vector of labels),
      and this will update the fuzzy simplicial set to respect that label data.
  
      TODO: optional category cardinality based weighting of distance
  
      Parameters
      ----------
      simplicial_set: sparse matrix
          The input fuzzy simplicial set.
  
      discrete_space: array of shape (n_samples)
          The categorical labels to use in the intersection.
  
      unknown_dist: float (optional, default 1.0)
          The distance an unknown label (-1) is assumed to be from any point.
  
      far_dist: float (optional, default 5.0)
          The distance between unmatched labels.
  
      metric: str (optional, default None)
          If not None, then use this metric to determine the
          distance between values.
  
      metric_scale: float (optional, default 1.0)
          If using a custom metric scale the distance values by
          this value -- this controls the weighting of the
          intersection. Larger values weight more toward target.
  
      Returns
      -------
      simplicial_set: sparse matrix
          The resulting intersected fuzzy simplicial set.
      """
      simplicial_set = simplicial_set.tocoo()
  
      if metric is not None:
          # We presume target is now a 2d array, with each row being a
          # vector of target info
          if metric in dist.named_distances:
              metric_func = dist.named_distances[metric]
          else:
              raise ValueError(
                  "Discrete intersection metric is not recognized"
              )
  
          fast_metric_intersection(
              simplicial_set.row,
              simplicial_set.col,
              simplicial_set.data,
              discrete_space,
              metric_func,
              tuple(metric_kws.values()),
              metric_scale,
          )
      else:
          fast_intersection(
              simplicial_set.row,
              simplicial_set.col,
              simplicial_set.data,
              discrete_space,
              unknown_dist,
              far_dist,
          )
  
      simplicial_set.eliminate_zeros()
  
      return reset_local_connectivity(simplicial_set)
  
imports: from __future__ import print_function
  import locale
  from warnings import warn
  import time
  from scipy.optimize import curve_fit
  from sklearn.base import BaseEstimator
  from sklearn.utils import check_random_state, check_array
  from sklearn.utils.validation import check_is_fitted
  from sklearn.metrics import pairwise_distances
  from sklearn.preprocessing import normalize
  from sklearn.neighbors import KDTree
  from sklearn.decomposition import PCA, TruncatedSVD
  import numpy
  import scipy.sparse
  from scipy.sparse import tril, triu
  import scipy.sparse.csgraph
  import numba
  import umap.distances
  import umap.sparse
  from umap.utils import submatrix, ts, csr_unique, fast_knn_indices
  from umap.spectral import spectral_layout, tswspectral_layout
  from umap.layouts import optimize_layout_euclidean, optimize_layout_generic, optimize_layout_inverse
  from pynndescent import NNDescent
  from pynndescent.distances import named_distances
  from pynndescent.sparse import sparse_named_distances
label_desc: Use image node_id 14 for calling a global function with example usage: discrete_metric_simplicial_set_intersection(simplicial_set, discrete_space, unknown_dist, far_dist, metric, metric_kws, metric_scale) and returns: reset_local_connectivity