code: def main(output_file="out.mp4", max_iter=128):
      """Run gradient descent on a sphere."""
      gs.random.seed(1985)
  
      sphere2 = Hypersphere(dim=2)
  
      A = generate_well_behaved_matrix()
  
      def grad(x):
          return 2 * gs.matvec(A, x)
  
      def loss(x, use_gs=False):
          if use_gs:
              return gs.matvec(x, gs.matvec(A, x))
          return np.matmul(x, np.matmul(A, x))
  
      initial_point = gs.array([0.0, 1.0, 0.0])
      previous_x = initial_point
      geodesics = []
      n_steps = 20
      for x, _ in gradient_descent(
          initial_point, loss, grad, max_iter=max_iter, manifold=sphere2
      ):
          initial_tangent_vec = sphere2.metric.log(
              point=x, base_point=previous_x
          )
          geodesic = sphere2.metric.geodesic(
              initial_point=previous_x,
              initial_tangent_vec=initial_tangent_vec,
          )
  
          t = np.linspace(0, 1, n_steps)
          geodesics.append(geodesic(t))
          previous_x = x
      if output_file:
          plot_and_save_video(geodesics, loss, out=output_file)
      eig, _ = np.linalg.eig(A)
      np.testing.assert_almost_equal(loss(x), np.min(eig), decimal=2)
  
file_path: geomstats/examples/gradient_descent_s2.py
imports: import logging
  import matplotlib
  import matplotlib.animation
  import matplotlib.pyplot
  import numpy
  import geomstats.backend
  import geomstats.visualization
  from geomstats.geometry.hypersphere import Hypersphere
  from geomstats.geometry.spd_matrices import SPDMatrices
label_desc: Use image node_id 4 for calling a global function with example usage: main(output_file, max_iter) and returns: unknown, np, gs