class_docstr: Gradient-descent optimizer with momentum.
  
  The momentum optimizer adds a "momentum" term to gradient descent
  which considers the past gradients:
  
  .. math:: x^{(t+1)} = x^{(t)} - a^{(t+1)}.
  
  The accumulator term :math:`a` is updated as follows:
  
  .. math:: a^{(t+1)} = m a^{(t)} + \eta \nabla f(x^{(t)}),
  
  with user defined parameters:
  
  * :math:`\eta`: the step size
  * :math:`m`: the momentum
  
  Args:
      stepsize (float): user-defined hyperparameter :math:`\eta`
      momentum (float): user-defined hyperparameter :math:`m`
  
  .. note::
  
      When using ``torch``, ``tensorflow`` or ``jax`` interfaces, refer to :doc:`Gradients and training </introduction/interfaces>` for suitable optimizers.
docstr: Update the trainable args to take a single optimization step. Flattens and unflattens
  the inputs to maintain nested iterables as the parameters of the optimization.
  
  Args:
      grad (tuple [array]): the gradient of the objective
          function at point :math:`x^{(t)}`: :math:`\nabla f(x^{(t)})`.
      args (tuple): the current value of the variables :math:`x^{(t)}`.
  
  Returns:
      list [array]: the new values :math:`x^{(t+1)}`.
docstr_tok: ["Update","the","trainable","args","to","take","a","single","optimization","step",".","Flattens","and","unflattens","the","inputs","to","maintain","nested","iterables","as","the","parameters","of","the","optimization",".","Args",":","grad","(","tuple","[","array","]",")",":","the","gradient","of","the","objective","function","at","point",":","math",":","`","x^","{","(","t",")","}","`",":",":","math",":","`","\\nabla","f","(","x^","{","(","t",")","}",")","`",".","args","(","tuple",")",":","the","current","value","of","the","variables",":","math",":","`","x^","{","(","t",")","}","`",".","Returns",":","list","[","array","]",":","the","new","values",":","math",":","`","x^","{","(","t+1",")","}","`","."]
code: def apply_grad(self, grad, args):
      r"""Update the trainable args to take a single optimization step. Flattens and unflattens
      the inputs to maintain nested iterables as the parameters of the optimization.
  
      Args:
          grad (tuple [array]): the gradient of the objective
              function at point :math:`x^{(t)}`: :math:`\nabla f(x^{(t)})`.
          args (tuple): the current value of the variables :math:`x^{(t)}`.
  
      Returns:
          list [array]: the new values :math:`x^{(t+1)}`.
      """
      args_new = list(args)
  
      if self.accumulation is None:
          self.accumulation = [0.0] * len(args)
  
      trained_index = 0
      for index, arg in enumerate(args):
          if getattr(arg, "requires_grad", False):
              self._update_accumulation(index, grad[trained_index])
              args_new[index] = arg - self.accumulation[index]
  
              trained_index += 1
  
      return args_new
  
imports: from .gradient_descent import GradientDescentOptimizer
label_desc: Use image node_id 2 for calling the MomentumOptimizer obj's underlying member method code with example usage: obj.apply_grad(grad, args) and returns: args_new