code: def build_neighborhood_similarities(
      graphs_indptr, graphs_indices, relations
  ):
      result = np.zeros(relations.shape, dtype=np.float32)
      center_index = (relations.shape[1] - 1) // 2
      for i in range(relations.shape[0]):
          base_graph_indptr = graphs_indptr[i]
          base_graph_indices = graphs_indices[i]
          for j in range(relations.shape[1]):
              if (
                  i + j - center_index < 0
                  or i + j - center_index >= len(graphs_indptr)
              ):
                  continue
  
              comparison_graph_indptr = graphs_indptr[
                  i + j - center_index
              ]
              comparison_graph_indices = graphs_indices[
                  i + j - center_index
              ]
              for k in range(relations.shape[2]):
                  comparison_index = relations[i, j, k]
                  if comparison_index < 0:
                      continue
  
                  raw_base_graph_indices = base_graph_indices[
                      base_graph_indptr[k] : base_graph_indptr[k + 1]
                  ].copy()
                  base_indices = relations[i, j][
                      raw_base_graph_indices[
                          raw_base_graph_indices < relations.shape[2]
                      ]
                  ]
                  base_indices = base_indices[base_indices >= 0]
                  comparison_indices = comparison_graph_indices[
                      comparison_graph_indptr[
                          comparison_index
                      ] : comparison_graph_indptr[comparison_index + 1]
                  ]
                  comparison_indices = comparison_indices[
                      in1d(comparison_indices, relations[i, j])
                  ]
  
                  intersection_size = intersect1d(
                      base_indices, comparison_indices
                  ).shape[0]
                  union_size = union1d(
                      base_indices, comparison_indices
                  ).shape[0]
  
                  if union_size > 0:
                      result[i, j, k] = intersection_size / union_size
                  else:
                      result[i, j, k] = 1.0
  
      return result
  
imports: import numpy
  import numba
  from sklearn.base import BaseEstimator
  from sklearn.utils import check_array
  from umap.sparse import arr_intersect
  from umap.sparse import arr_union
  from umap.umap_ import UMAP, make_epochs_per_sample
  from umap.spectral import spectral_layout
  from umap.layouts import optimize_layout_aligned_euclidean
label_desc: Use image node_id 5 for calling a global function with example usage: build_neighborhood_similarities(graphs_indptr, graphs_indices, relations) and returns: result