class_docstr: Manages issues related to near-duplicate examples.
class_docstr_tok: ["Manages","issues","related","to","near-duplicate","examples","."]
docstr: Returns a list of lists of indices of near-duplicate examples.
  
  Each list of indices represents a set of near-duplicate examples.
  
  If the list is empty for a given example, then that example is not
  a near-duplicate of any other example.
docstr_tok: ["Returns","a","list","of","lists","of","indices","of","near-duplicate","examples",".","Each","list","of","indices","represents","a","set","of","near-duplicate","examples",".","If","the","list","is","empty","for","a","given","example",",","then","that","example","is","not","a","near-duplicate","of","any","other","example","."]
code: def _neighbors_within_radius(
      knn_graph: csr_matrix, threshold: float, median: float
  ):
      """Returns a list of lists of indices of near-duplicate examples.
  
      Each list of indices represents a set of near-duplicate examples.
  
      If the list is empty for a given example, then that example is not
      a near-duplicate of any other example.
      """
  
      N = knn_graph.shape[0]
      distances = knn_graph.data.reshape(N, -1)
      # Create a mask for the threshold
      mask = distances < threshold * median
  
      # Update the indptr to reflect the new number of neighbors
      indptr = np.zeros(
          knn_graph.indptr.shape, dtype=knn_graph.indptr.dtype
      )
      indptr[1:] = np.cumsum(mask.sum(axis=1))
  
      # Filter the knn_graph based on the threshold
      indices = knn_graph.indices[mask.ravel()]
      near_duplicate_sets = [
          indices[indptr[i] : indptr[i + 1]] for i in range(N)
      ]
  
      # Second pass over the data is required to ensure each item is included in the near-duplicate sets of its own near-duplicates.
      # This is important because a "near-duplicate" relationship is reciprocal.
      # For example, if item A is a near-duplicate of item B, then item B should also be considered a near-duplicate of item A.
      # NOTE: This approach does not assure that the sets are ordered by increasing distance.
      for i, near_duplicates in enumerate(near_duplicate_sets):
          for j in near_duplicates:
              if i not in near_duplicate_sets[j]:
                  near_duplicate_sets[j] = np.append(
                      near_duplicate_sets[j], i
                  )
  
      return near_duplicate_sets
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, Any, ClassVar, Dict, List, Optional, Union
  import warnings
  import numpy
  import pandas
  from scipy.sparse import csr_matrix
  from sklearn.neighbors import NearestNeighbors
  from sklearn.exceptions import NotFittedError
  from sklearn.utils.validation import check_is_fitted
  from cleanlab.datalab.internal.issue_manager import IssueManager
label_desc: Use image node_id 3 for calling the NearDuplicateIssueManager obj's underlying member method code with example usage: obj._neighbors_within_radius(knn_graph, threshold, median) and returns: near_duplicate_sets