def get_or_compute_grads(loss_or_grads, params):
 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)

def get_or_compute_grads ( loss_or_grads , params ) : 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 )
helper function returning a list of gradients parameters loss_or_grads : symbolic expression or list of expressions a scalar loss expression .