code: def _non_trivial_radius(
      *,
      X=None,
      Y=None,
      metric=None,
      precomputed_dists=None,
      expected_n_neighbors=10,
      n_subsampled_queries=10,
      **metric_kwargs,
  ):
      # Find a non-trivial radius using a small subsample of the pairwise
      # distances between X and Y: we want to return around expected_n_neighbors
      # on average. Yielding too many results would make the test slow (because
      # checking the results is expensive for large result sets), yielding 0 most
      # of the time would make the test useless.
      assert (
          precomputed_dists is not None or metric is not None
      ), "Either metric or precomputed_dists must be provided."
  
      if precomputed_dists is None:
          assert X is not None
          assert Y is not None
          sampled_dists = pairwise_distances(
              X, Y, metric=metric, **metric_kwargs
          )
      else:
          sampled_dists = precomputed_dists[
              :n_subsampled_queries
          ].copy()
      sampled_dists.sort(axis=1)
      return sampled_dists[:, expected_n_neighbors].mean()
  
imports: import itertools
  import re
  import warnings
  from functools import partial
  import numpy
  import pytest
  import threadpoolctl
  from scipy.spatial.distance import cdist
  from sklearn.metrics import euclidean_distances, pairwise_distances
  from sklearn.metrics._pairwise_distances_reduction import ArgKmin, ArgKminClassMode, BaseDistancesReductionDispatcher, RadiusNeighbors, RadiusNeighborsClassMode, sqeuclidean_row_norms
  from sklearn.utils._testing import assert_allclose, assert_array_equal, create_memmap_backed_data
  from sklearn.utils.fixes import CSR_CONTAINERS
label_desc: Use image node_id 5 for calling a global function with example usage: _non_trivial_radius() and returns: sampled_dists