code: def _new_select_clusters(
      condensed_tree,
      cluster_selection_epsilon,
      allow_single_cluster=False,
      match_reference_implementation=False,
  ):
      """
      Adaptation of get_clusters from hdbscan._hdbscan_tree.
      Avoids the label and proba computation at the end,
          and returns only the selected clusters instead.
      """
      tree = condensed_tree._raw_tree
      cluster_selection_method = condensed_tree.cluster_selection_method
      stability = compute_stability(tree)
  
      if allow_single_cluster:
          node_list = sorted(stability.keys(), reverse=True)
      else:
          node_list = sorted(stability.keys(), reverse=True)[:-1]
          # (exclude root)
  
      cluster_tree = tree[tree["child_size"] > 1]
      is_cluster = {cluster: True for cluster in node_list}
  
      if cluster_selection_method == "eom":
          for node in node_list:
              child_selection = cluster_tree["parent"] == node
              subtree_stability = np.sum(
                  [
                      stability[child]
                      for child in cluster_tree["child"][
                          child_selection
                      ]
                  ]
              )
              if subtree_stability > stability[node]:
                  is_cluster[node] = False
                  stability[node] = subtree_stability
              else:
                  for sub_node in _bfs_from_cluster_tree(
                      cluster_tree, node
                  ):
                      if sub_node != node:
                          is_cluster[sub_node] = False
  
          if cluster_selection_epsilon != 0.0:
              eom_clusters = set(
                  [c for c in is_cluster if is_cluster[c]]
              )
              selected_clusters = epsilon_search(
                  eom_clusters,
                  cluster_tree,
                  cluster_selection_epsilon,
                  allow_single_cluster,
              )
              for c in is_cluster:
                  if c in selected_clusters:
                      is_cluster[c] = True
                  else:
                      is_cluster[c] = False
  
      elif cluster_selection_method == "leaf":
          leaves = set(get_cluster_tree_leaves(cluster_tree))
          if len(leaves) == 0:
              for c in is_cluster:
                  is_cluster[c] = False
              is_cluster[tree["parent"].min()] = True
  
          if cluster_selection_epsilon != 0.0:
              selected_clusters = epsilon_search(
                  leaves,
                  cluster_tree,
                  cluster_selection_epsilon,
                  allow_single_cluster,
              )
          else:
              selected_clusters = leaves
  
          for c in is_cluster:
              if c in selected_clusters:
                  is_cluster[c] = True
              else:
                  is_cluster[c] = False
      else:
          raise ValueError(
              "Invalid Cluster Selection Method: %s\n"
              'Should be one of: "eom", "leaf"\n'
          )
  
      clusters = set([int(c) for c in is_cluster if is_cluster[c]])
      return clusters
  
imports: import copy
  from warnings import warn
  import numpy
  from ._hdbscan_tree import compute_stability, get_cluster_tree_leaves
  from .hdbscan_ import HDBSCAN, _tree_to_labels
  from .plots import _bfs_from_cluster_tree
  from .prediction import PredictionData, _find_cluster_and_probability, _find_neighbor_and_lambda
  from ._prediction_utils import get_tree_row_with_child, dist_membership_vector, outlier_membership_vector, prob_in_some_cluster, all_points_dist_membership_vector, all_points_outlier_membership_vector, all_points_prob_in_some_cluster
label_desc: Use image node_id 9 for calling a global function with example usage: _new_select_clusters(condensed_tree, cluster_selection_epsilon, allow_single_cluster, match_reference_implementation) and returns: clusters