code: def test_min_grad_norm():
      # Make sure that the parameter min_grad_norm is used correctly
      random_state = check_random_state(0)
      X = random_state.randn(100, 2)
      min_grad_norm = 0.002
      tsne = TSNE(
          min_grad_norm=min_grad_norm,
          verbose=2,
          random_state=0,
          method="exact",
      )
  
      old_stdout = sys.stdout
      sys.stdout = StringIO()
      try:
          tsne.fit_transform(X)
      finally:
          out = sys.stdout.getvalue()
          sys.stdout.close()
          sys.stdout = old_stdout
  
      lines_out = out.split("\n")
  
      # extract the gradient norm from the verbose output
      gradient_norm_values = []
      for line in lines_out:
          # When the computation is Finished just an old gradient norm value
          # is repeated that we do not need to store
          if "Finished" in line:
              break
  
          start_grad_norm = line.find("gradient norm")
          if start_grad_norm >= 0:
              line = line[start_grad_norm:]
              line = line.replace("gradient norm = ", "").split(" ")[0]
              gradient_norm_values.append(float(line))
  
      # Compute how often the gradient norm is smaller than min_grad_norm
      gradient_norm_values = np.array(gradient_norm_values)
      n_smaller_gradient_norms = len(
          gradient_norm_values[gradient_norm_values <= min_grad_norm]
      )
  
      # The gradient norm can be smaller than min_grad_norm at most once,
      # because in the moment it becomes smaller the optimization stops
      assert n_smaller_gradient_norms <= 1
  
imports: import sys
  from io import StringIO
  import numpy
  import pytest
  import scipy.sparse
  from numpy.testing import assert_allclose
  from scipy.optimize import check_grad
  from scipy.spatial.distance import pdist, squareform
  from sklearn import config_context
  from sklearn.datasets import make_blobs
  from sklearn.exceptions import EfficiencyWarning
  from sklearn.manifold import TSNE, _barnes_hut_tsne
  from sklearn.manifold._t_sne import _gradient_descent, _joint_probabilities, _joint_probabilities_nn, _kl_divergence, _kl_divergence_bh, trustworthiness
  from sklearn.manifold._utils import _binary_search_perplexity
  from sklearn.metrics.pairwise import cosine_distances, manhattan_distances, pairwise_distances
  from sklearn.neighbors import NearestNeighbors, kneighbors_graph
  from sklearn.utils import check_random_state
  from sklearn.utils._testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal, ignore_warnings, skip_if_32bit
  from sklearn.utils.fixes import CSR_CONTAINERS, LIL_CONTAINERS
label_desc: Use image node_id 37 for calling a global function with example usage: test_min_grad_norm() without return types