parameters: (cell_fn, cell_grad)
return_statement: return CellGrad
docstring: Returns the gradient function for cell_fn.
  
    Args:
      cell_fn: The recurrent neural net's cell function.
      cell_grad: If not None, cell_fn's gradient function.
  
    Returns:
      Returns cell_grad if not None. Otherwise, assume cell_fn is a python
      function representing the recurrent neural net's cell function, i.e.,
        cell_fn: (theta, state0, inputs) -> (state1, extra)
      returns its default gradient python function, i.e.,
        cell_grad: (theta, state0, inputs, extras, dstate1) -> (
                    dtheta, dstate0, dinputs)
docstring_summary: Returns the gradient function for cell_fn.
docstring_tokens: Returns the gradient function for cell_fn .
function: def _GetCellGrad(cell_fn, cell_grad):
    """Returns the gradient function for cell_fn.
  
    Args:
      cell_fn: The recurrent neural net's cell function.
      cell_grad: If not None, cell_fn's gradient function.
  
    Returns:
      Returns cell_grad if not None. Otherwise, assume cell_fn is a python
      function representing the recurrent neural net's cell function, i.e.,
        cell_fn: (theta, state0, inputs) -> (state1, extra)
      returns its default gradient python function, i.e.,
        cell_grad: (theta, state0, inputs, extras, dstate1) -> (
                    dtheta, dstate0, dinputs)
    """
  
    if cell_grad:
      return cell_grad
  
    def CellGrad(theta, state0, inputs, extras, dstate1):
      """Default gradient function for cell_fn."""
      # NOTE: The default grad function recomputes the forward
      # function and does not take advantage of 'extras' returned by
      # the forward function.
      del extras
      state1, extras = cell_fn(theta, state0, inputs)
      ys = _Flatten([state1])
      xs = _Flatten([theta, state0, inputs])
      grad_ys = _Flatten([dstate1])
      grads = gradients_impl.gradients(ys=ys, xs=xs, grad_ys=grad_ys)
      return _ConvertNoneGradientToZeros([theta, state0, inputs],
                                         _Pack(grads, [theta, state0, inputs]))
  
    return CellGrad
function_tokens: def _GetCellGrad ( cell_fn , cell_grad ) : if cell_grad : return cell_grad def CellGrad ( theta , state0 , inputs , extras , dstate1 ) : """Default gradient function for cell_fn.""" # NOTE: The default grad function recomputes the forward # function and does not take advantage of 'extras' returned by # the forward function. del extras state1 , extras = cell_fn ( theta , state0 , inputs ) ys = _Flatten ( [ state1 ] ) xs = _Flatten ( [ theta , state0 , inputs ] ) grad_ys = _Flatten ( [ dstate1 ] ) grads = gradients_impl . gradients ( ys = ys , xs = xs , grad_ys = grad_ys ) return _ConvertNoneGradientToZeros ( [ theta , state0 , inputs ] , _Pack ( grads , [ theta , state0 , inputs ] ) ) return CellGrad