code: def _hdbscan_prims_balltree(
      X,
      min_samples=5,
      alpha=1.0,
      metric="minkowski",
      p=2,
      leaf_size=40,
      gen_min_span_tree=False,
      **kwargs,
  ):
      if X.dtype != np.float64:
          X = X.astype(np.float64)
  
      # The Cython routines used require contiguous arrays
      if not X.flags["C_CONTIGUOUS"]:
          X = np.array(X, dtype=np.double, order="C")
  
      tree = BallTree(X, metric=metric, leaf_size=leaf_size, **kwargs)
  
      dist_metric = DistanceMetric.get_metric(metric, **kwargs)
  
      # Get distance to kth nearest neighbour
      core_distances = tree.query(
          X, k=min_samples + 1, dualtree=True, breadth_first=True
      )[0][:, -1].copy(order="C")
  
      # Mutual reachability distance is implicit in mst_linkage_core_vector
      min_spanning_tree = mst_linkage_core_vector(
          X, core_distances, dist_metric, alpha
      )
      # Sort edges of the min_spanning_tree by weight
      min_spanning_tree = min_spanning_tree[
          np.argsort(min_spanning_tree.T[2]), :
      ]
      # Convert edge list into standard hierarchical clustering format
      single_linkage_tree = label(min_spanning_tree)
  
      if gen_min_span_tree:
          return single_linkage_tree, min_spanning_tree
      else:
          return single_linkage_tree, None
  
imports: import numpy
  from sklearn.base import BaseEstimator, ClusterMixin
  from sklearn.metrics import pairwise_distances
  from scipy.sparse import issparse
  from sklearn.neighbors import KDTree, BallTree
  from joblib import Memory
  from warnings import warn
  from sklearn.utils import check_array
  from joblib.parallel import cpu_count
  from scipy.sparse import csgraph
  from ._hdbscan_linkage import single_linkage, mst_linkage_core, mst_linkage_core_vector, label
  from ._hdbscan_tree import condense_tree, compute_stability, get_clusters, outlier_scores
  from ._hdbscan_reachability import mutual_reachability, sparse_mutual_reachability
  from ._hdbscan_boruvka import KDTreeBoruvkaAlgorithm, BallTreeBoruvkaAlgorithm
  from .dist_metrics import DistanceMetric
  from .plots import CondensedTree, SingleLinkageTree, MinimumSpanningTree
  from .prediction import PredictionData
  from numpy import isclose
label_desc: Use image node_id 5 for calling a global function with example usage: _hdbscan_prims_balltree(X, min_samples, alpha, metric, p, leaf_size, gen_min_span_tree) and returns: single_linkage_tree,  min_spanning_tree, single_linkage_tree,  None