class_docstr: PyNNDescentTransformer for fast approximate nearest neighbor transformer.
  It uses the NNDescent algorithm, and is thus
  very flexible and supports a wide variety of distances, including
  non-metric distances. NNDescent also scales well against high dimensional
  graph_data in many cases.
  
  Transform X into a (weighted) graph of k nearest neighbors
  
  The transformed graph_data is a sparse graph as returned by kneighbors_graph.
  
  Parameters
  ----------
  n_neighbors: int (optional, default=5)
      The number of neighbors to use in k-neighbor graph graph_data structure
      used for fast approximate nearest neighbor search. Larger values
      will result in more accurate search results at the cost of
      computation time.
  
  metric: string or callable (optional, default='euclidean')
      The metric to use for computing nearest neighbors. If a callable is
      used it must be a numba njit compiled function. Supported metrics
      include:
          * euclidean
          * manhattan
          * chebyshev
          * minkowski
          * canberra
          * braycurtis
          * mahalanobis
          * wminkowski
          * seuclidean
          * cosine
          * correlation
          * haversine
          * hamming
          * jaccard
          * dice
          * russelrao
          * kulsinski
          * rogerstanimoto
          * sokalmichener
          * sokalsneath
          * yule
          * hellinger
          * wasserstein-1d
      Metrics that take arguments (such as minkowski, mahalanobis etc.)
      can have arguments passed via the metric_kwds dictionary. At this
      time care must be taken and dictionary elements must be ordered
      appropriately; this will hopefully be fixed in the future.
  
  metric_kwds: dict (optional, default {})
      Arguments to pass on to the metric, such as the ``p`` value for
      Minkowski distance.
  
  n_trees: int (optional, default=None)
      This implementation uses random projection forests for initialization
      of searches. This parameter controls the number of trees in that
      forest. A larger number will result in more accurate neighbor
      computation at the cost of performance. The default of None means
      a value will be chosen based on the size of the graph_data.
  
  leaf_size: int (optional, default=None)
      The maximum number of points in a leaf for the random projection trees.
      The default of None means a value will be chosen based on n_neighbors.
  
  pruning_degree_multiplier: float (optional, default=1.5)
      How aggressively to prune the graph. Since the search graph is undirected
      (and thus includes nearest neighbors and reverse nearest neighbors) vertices
      can have very high degree -- the graph will be pruned such that no
      vertex has degree greater than
      ``pruning_degree_multiplier * n_neighbors``.
  
  diversify_prob: float (optional, default=1.0)
      The search graph get "diversified" by removing potentially unnecessary
      edges. This controls the volume of edges removed. A value of 0.0 ensures
      that no edges get removed, and larger values result in significantly more
      aggressive edge removal. A value of 1.0 will prune all edges that it can.
  
  n_search_trees: int (optional, default=1)
      The number of random projection trees to use in initializing searching or
      querying.
  
      .. deprecated:: 0.5.5
  
  search_epsilon: float (optional, default=0.1)
      When searching for nearest neighbors of a query point this values
      controls the trade-off between accuracy and search cost. Larger values
      produce more accurate nearest neighbor results at larger computational
      cost for the search. Values should be in the range 0.0 to 0.5, but
      should probably not exceed 0.3 without good reason.
  
  tree_init: bool (optional, default=True)
      Whether to use random projection trees for initialization.
  
  random_state: int, RandomState instance or None, optional (default: None)
      If int, random_state is the seed used by the random number generator;
      If RandomState instance, random_state is the random number generator;
      If None, the random number generator is the RandomState instance used
      by `np.random`.
  
  n_jobs: int or None (optional, default=None)
      The maximum number of parallel threads to be run at a time. If none
      this will default to using all the cores available. Note that there is
      not perfect parallelism, so at several pints the algorithm will be
      single threaded.
  
  low_memory: boolean (optional, default=False)
      Whether to use a lower memory, but more computationally expensive
      approach to index construction. This defaults to false as for most
      cases it speeds index construction, but if you are having issues
      with excessive memory use for your dataset consider setting this
      to True.
  
  max_candidates: int (optional, default=20)
      Internally each "self-join" keeps a maximum number of candidates (
      nearest neighbors and reverse nearest neighbors) to be considered.
      This value controls this aspect of the algorithm. Larger values will
      provide more accurate search results later, but potentially at
      non-negligible computation cost in building the index. Don't tweak
      this value unless you know what you're doing.
  
  n_iters: int (optional, default=None)
      The maximum number of NN-descent iterations to perform. The
      NN-descent algorithm can abort early if limited progress is being
      made, so this only controls the worst case. Don't tweak
      this value unless you know what you're doing. The default of None means
      a value will be chosen based on the size of the graph_data.
  
  early_termination_value: float (optional, default=0.001)
      Controls the early abort due to limited progress. Larger values
      will result in earlier aborts, providing less accurate indexes,
      and less accurate searching. Don't tweak this value unless you know
      what you're doing.
  
  parallel_batch_queries: bool (optional, default=False)
      Whether to use parallelism of batched queries. This can be useful for large
      batches of queries on multicore machines, but results in performance degradation
      for single queries, so is poor for streaming use.
  
  verbose: bool (optional, default=False)
      Whether to print status graph_data during the computation.
  
  Examples
  --------
  >>> from sklearn.manifold import Isomap
  >>> from pynndescent import PyNNDescentTransformer
  >>> from sklearn.pipeline import make_pipeline
  >>> estimator = make_pipeline(
  ...     PyNNDescentTransformer(n_neighbors=5),
  ...     Isomap(neighbors_algorithm='precomputed'))
class_docstr_tok: ["PyNNDescentTransformer","for","fast","approximate","nearest","neighbor","transformer",".","It","uses","the","NNDescent","algorithm",",","and","is","thus","very","flexible","and","supports","a","wide","variety","of","distances",",","including","non-metric","distances",".","NNDescent","also","scales","well","against","high","dimensional","graph_data","in","many","cases",".","Transform","X","into","a","(","weighted",")","graph","of","k","nearest","neighbors","The","transformed","graph_data","is","a","sparse","graph","as","returned","by","kneighbors_graph",".","Parameters","--","--","--","--","--","n_neighbors",":","int","(","optional",",","default=5",")","The","number","of","neighbors","to","use","in","k-neighbor","graph","graph_data","structure","used","for","fast","approximate","nearest","neighbor","search",".","Larger","values","will","result","in","more","accurate","search","results","at","the","cost","of","computation","time",".","metric",":","string","or","callable","(","optional",",","default='euclidean","'",")","The","metric","to","use","for","computing","nearest","neighbors",".","If","a","callable","is","used","it","must","be","a","numba","njit","compiled","function",".","Supported","metrics","include",":","*","euclidean","*","manhattan","*","chebyshev","*","minkowski","*","canberra","*","braycurtis","*","mahalanobis","*","wminkowski","*","seuclidean","*","cosine","*","correlation","*","haversine","*","hamming","*","jaccard","*","dice","*","russelrao","*","kulsinski","*","rogerstanimoto","*","sokalmichener","*","sokalsneath","*","yule","*","hellinger","*","wasserstein-1d","Metrics","that","take","arguments","(","such","as","minkowski",",","mahalanobis","etc",".",")","can","have","arguments","passed","via","the","metric_kwds","dictionary",".","At","this","time","care","must","be","taken","and","dictionary","elements","must","be","ordered","appropriately",";","this","will","hopefully","be","fixed","in","the","future",".","metric_kwds",":","dict","(","optional",",","default","{","}",")","Arguments","to","pass","on","to","the","metric",",","such","as","the","``","p","``","value","for","Minkowski","distance",".","n_trees",":","int","(","optional",",","default=None",")","This","implementation","uses","random","projection","forests","for","initialization","of","searches",".","This","parameter","controls","the","number","of","trees","in","that","forest",".","A","larger","number","will","result","in","more","accurate","neighbor","computation","at","the","cost","of","performance",".","The","default","of","None","means","a","value","will","be","chosen","based","on","the","size","of","the","graph_data",".","leaf_size",":","int","(","optional",",","default=None",")","The","maximum","number","of","points","in","a","leaf","for","the","random","projection","trees",".","The","default","of","None","means","a","value","will","be","chosen","based","on","n_neighbors",".","pruning_degree_multiplier",":","float","(","optional",",","default=1.5",")","How","aggressively","to","prune","the","graph",".","Since","the","search","graph","is","undirected","(","and","thus","includes","nearest","neighbors","and","reverse","nearest","neighbors",")","vertices","can","have","very","high","degree","--","the","graph","will","be","pruned","such","that","no","vertex","has","degree","greater","than","``","pruning_degree_multiplier","*","n_neighbors","``",".","diversify_prob",":","float","(","optional",",","default=1.0",")","The","search","graph","get","``","diversified","''","by","removing","potentially","unnecessary","edges",".","This","controls","the","volume","of","edges","removed",".","A","value","of","0.0","ensures","that","no","edges","get","removed",",","and","larger","values","result","in","significantly","more","aggressive","edge","removal",".","A","value","of","1.0","will","prune","all","edges","that","it","can",".","n_search_trees",":","int","(","optional",",","default=1",")","The","number","of","random","projection","trees","to","use","in","initializing","searching","or","querying",".","..","deprecated",":",":","0.5.5","search_epsilon",":","float","(","optional",",","default=0.1",")","When","searching","for","nearest","neighbors","of","a","query","point","this","values","controls","the","trade-off","between","accuracy","and","search","cost",".","Larger","values","produce","more","accurate","nearest","neighbor","results","at","larger","computational","cost","for","the","search",".","Values","should","be","in","the","range","0.0","to","0.5",",","but","should","probably","not","exceed","0.3","without","good","reason",".","tree_init",":","bool","(","optional",",","default=True",")","Whether","to","use","random","projection","trees","for","initialization",".","random_state",":","int",",","RandomState","instance","or","None",",","optional","(","default",":","None",")","If","int",",","random_state","is","the","seed","used","by","the","random","number","generator",";","If","RandomState","instance",",","random_state","is","the","random","number","generator",";","If","None",",","the","random","number","generator","is","the","RandomState","instance","used","by","`","np.random","`",".","n_jobs",":","int","or","None","(","optional",",","default=None",")","The","maximum","number","of","parallel","threads","to","be","run","at","a","time",".","If","none","this","will","default","to","using","all","the","cores","available",".","Note","that","there","is","not","perfect","parallelism",",","so","at","several","pints","the","algorithm","will","be","single","threaded",".","low_memory",":","boolean","(","optional",",","default=False",")","Whether","to","use","a","lower","memory",",","but","more","computationally","expensive","approach","to","index","construction",".","This","defaults","to","false","as","for","most","cases","it","speeds","index","construction",",","but","if","you","are","having","issues","with","excessive","memory","use","for","your","dataset","consider","setting","this","to","True",".","max_candidates",":","int","(","optional",",","default=20",")","Internally","each","``","self-join","''","keeps","a","maximum","number","of","candidates","(","nearest","neighbors","and","reverse","nearest","neighbors",")","to","be","considered",".","This","value","controls","this","aspect","of","the","algorithm",".","Larger","values","will","provide","more","accurate","search","results","later",",","but","potentially","at","non-negligible","computation","cost","in","building","the","index",".","Do","n't","tweak","this","value","unless","you","know","what","you","'re","doing",".","n_iters",":","int","(","optional",",","default=None",")","The","maximum","number","of","NN-descent","iterations","to","perform",".","The","NN-descent","algorithm","can","abort","early","if","limited","progress","is","being","made",",","so","this","only","controls","the","worst","case",".","Do","n't","tweak","this","value","unless","you","know","what","you","'re","doing",".","The","default","of","None","means","a","value","will","be","chosen","based","on","the","size","of","the","graph_data",".","early_termination_value",":","float","(","optional",",","default=0.001",")","Controls","the","early","abort","due","to","limited","progress",".","Larger","values","will","result","in","earlier","aborts",",","providing","less","accurate","indexes",",","and","less","accurate","searching",".","Do","n't","tweak","this","value","unless","you","know","what","you","'re","doing",".","parallel_batch_queries",":","bool","(","optional",",","default=False",")","Whether","to","use","parallelism","of","batched","queries",".","This","can","be","useful","for","large","batches","of","queries","on","multicore","machines",",","but","results","in","performance","degradation","for","single","queries",",","so","is","poor","for","streaming","use",".","verbose",":","bool","(","optional",",","default=False",")","Whether","to","print","status","graph_data","during","the","computation",".","Examples","--","--","--","--",">",">",">","from","sklearn.manifold","import","Isomap",">",">",">","from","pynndescent","import","PyNNDescentTransformer",">",">",">","from","sklearn.pipeline","import","make_pipeline",">",">",">","estimator","=","make_pipeline","(","...","PyNNDescentTransformer","(","n_neighbors=5",")",",","...","Isomap","(","neighbors_algorithm='precomputed","'",")",")"]
docstr: Computes the (weighted) graph of Neighbors for points in X
  
  Parameters
  ----------
  X : array-like, shape (n_samples_transform, n_features)
      Sample graph_data
  
  Returns
  -------
  Xt : CSR sparse matrix, shape (n_samples_transform, n_samples_fit)
      Xt[i, j] is assigned the weight of edge that connects i to j.
      Only the neighbors have an explicit value.
docstr_tok: ["Computes","the","(","weighted",")","graph","of","Neighbors","for","points","in","X","Parameters","--","--","--","--","--","X",":","array-like",",","shape","(","n_samples_transform",",","n_features",")","Sample","graph_data","Returns","--","--","--","-","Xt",":","CSR","sparse","matrix",",","shape","(","n_samples_transform",",","n_samples_fit",")","Xt","[","i",",","j","]","is","assigned","the","weight","of","edge","that","connects","i","to","j",".","Only","the","neighbors","have","an","explicit","value","."]
code: def transform(self, X, y=None):
      """Computes the (weighted) graph of Neighbors for points in X
  
      Parameters
      ----------
      X : array-like, shape (n_samples_transform, n_features)
          Sample graph_data
  
      Returns
      -------
      Xt : CSR sparse matrix, shape (n_samples_transform, n_samples_fit)
          Xt[i, j] is assigned the weight of edge that connects i to j.
          Only the neighbors have an explicit value.
      """
  
      if X is None:
          n_samples_transform = self.n_samples_fit
      else:
          n_samples_transform = X.shape[0]
  
      if X is None:
          indices, distances = self.index_.neighbor_graph
      else:
          indices, distances = self.index_.query(
              X, k=self.n_neighbors, epsilon=self.search_epsilon
          )
  
      if self.verbose:
          print(ts(), "Constructing neighbor matrix")
      result = coo_matrix(
          (n_samples_transform, self.n_samples_fit), dtype=np.float32
      )
      result.row = np.repeat(
          np.arange(indices.shape[0], dtype=np.int32), indices.shape[1]
      )
      result.col = indices.ravel()
      result.data = distances.ravel()
  
      return result.tocsr()
  
imports: from warnings import warn
  import numba
  import numpy
  from sklearn.utils import check_random_state, check_array
  from sklearn.preprocessing import normalize
  from sklearn.base import BaseEstimator, TransformerMixin
  from scipy.sparse import csr_matrix, coo_matrix, isspmatrix_csr, vstack, issparse
  import heapq
  import pynndescent.sparse
  import pynndescent.sparse_nndescent
  import pynndescent.distances
  from pynndescent.utils import tau_rand_int, tau_rand, make_heap, deheap_sort, new_build_candidates, ts, simple_heap_push, checked_flagged_heap_push, has_been_visited, mark_visited, apply_graph_updates_high_memory, apply_graph_updates_low_memory, initalize_heap_from_graph_indices, initalize_heap_from_graph_indices_and_distances, sparse_initalize_heap_from_graph_indices
  from pynndescent.rp_trees import make_forest, rptree_leaf_array, convert_tree_format, FlatTree, denumbaify_tree, renumbaify_tree, select_side, sparse_select_side, score_linked_tree
label_desc: Use image node_id 3 for calling the PyNNDescentTransformer obj's underlying member method code with example usage: obj.transform(X, y) and returns: result