code: def test_gradient_descent_stops():
      # Test stopping conditions of gradient descent.
      class ObjectiveSmallGradient:
          def __init__(self):
              self.it = -1
  
          def __call__(self, _, compute_error=True):
              self.it += 1
              return (10 - self.it) / 10.0, np.array([1e-5])
  
      def flat_function(_, compute_error=True):
          return 0.0, np.ones(1)
  
      # Gradient norm
      old_stdout = sys.stdout
      sys.stdout = StringIO()
      try:
          _, error, it = _gradient_descent(
              ObjectiveSmallGradient(),
              np.zeros(1),
              0,
              n_iter=100,
              n_iter_without_progress=100,
              momentum=0.0,
              learning_rate=0.0,
              min_gain=0.0,
              min_grad_norm=1e-5,
              verbose=2,
          )
      finally:
          out = sys.stdout.getvalue()
          sys.stdout.close()
          sys.stdout = old_stdout
      assert error == 1.0
      assert it == 0
      assert "gradient norm" in out
  
      # Maximum number of iterations without improvement
      old_stdout = sys.stdout
      sys.stdout = StringIO()
      try:
          _, error, it = _gradient_descent(
              flat_function,
              np.zeros(1),
              0,
              n_iter=100,
              n_iter_without_progress=10,
              momentum=0.0,
              learning_rate=0.0,
              min_gain=0.0,
              min_grad_norm=0.0,
              verbose=2,
          )
      finally:
          out = sys.stdout.getvalue()
          sys.stdout.close()
          sys.stdout = old_stdout
      assert error == 0.0
      assert it == 11
      assert "did not make any progress" in out
  
      # Maximum number of iterations
      old_stdout = sys.stdout
      sys.stdout = StringIO()
      try:
          _, error, it = _gradient_descent(
              ObjectiveSmallGradient(),
              np.zeros(1),
              0,
              n_iter=11,
              n_iter_without_progress=100,
              momentum=0.0,
              learning_rate=0.0,
              min_gain=0.0,
              min_grad_norm=0.0,
              verbose=2,
          )
      finally:
          out = sys.stdout.getvalue()
          sys.stdout.close()
          sys.stdout = old_stdout
      assert error == 0.0
      assert it == 10
      assert "Iteration 10" in out
  
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 1 for calling a global function with example usage: test_gradient_descent_stops() and returns: int,  np, unknown,  np