code: def get_or_compute_grads(loss_or_grads, params):
      """Helper function returning a list of gradients
  
      Parameters
      ----------
      loss_or_grads : symbolic expression or list of expressions
          A scalar loss expression, or a list of gradient expressions
      params : list of shared variables
          The variables to return the gradients for
  
      Returns
      -------
      list of expressions
          If `loss_or_grads` is a list, it is assumed to be a list of
          gradients and returned as is, unless it does not match the length
          of `params`, in which case a `ValueError` is raised.
          Otherwise, `loss_or_grads` is assumed to be a cost expression and
          the function returns `theano.grad(loss_or_grads, params)`.
  
      Raises
      ------
      ValueError
          If `loss_or_grads` is a list of a different length than `params`, or if
          any element of `params` is not a shared variable (while we could still
          compute its gradient, we can never update it and want to fail early).
      """
      if any(
          not isinstance(p, theano.compile.SharedVariable)
          for p in params
      ):
          raise ValueError(
              "params must contain shared variables only. If it "
              "contains arbitrary parameter expressions, then "
              "lasagne.utils.collect_shared_vars() may help you."
          )
      if isinstance(loss_or_grads, list):
          if not len(loss_or_grads) == len(params):
              raise ValueError(
                  "Got %d gradient expressions for %d parameters"
                  % (len(loss_or_grads), len(params))
              )
          return loss_or_grads
      else:
          return theano.grad(loss_or_grads, params)
  
file_path: Lasagne/lasagne/updates.py
imports: from collections import OrderedDict
  import numpy
  import theano
  import theano.tensor
  from .None import utils
label_desc: Use image node_id 1 for calling a global function with example usage: get_or_compute_grads(loss_or_grads, params) and returns: loss_or_grads, theano