(f, **kwargs)
return grad_f
Grad with support for argnums.
Grad with support for argnums.
Grad with support for argnums .
def _tf_grad(f, **kwargs):
  """Grad with support for argnums."""
  argnums = kwargs.pop('argnums', 0)
  if argnums != 0:
    def g(*args, **kwargs):
      args = list(args)
      args[0], args[argnums] = args[argnums], args[0]
      return f(*args, **kwargs)
  else:
    g = f
  grad_g = tf_np_extensions.grad(g, **kwargs)
  if argnums == 0:
    return grad_g
  def grad_f(*args, **kwargs):
    args = list(args)
    args[0], args[argnums] = args[argnums], args[0]
    return grad_g(*args, **kwargs)
  return grad_f
def _tf_grad ( f , * * kwargs ) : argnums = kwargs . pop ( 'argnums' , 0 ) if argnums != 0 : def g ( * args , * * kwargs ) : args = list ( args ) args [ 0 ] , args [ argnums ] = args [ argnums ] , args [ 0 ] return f ( * args , * * kwargs ) else : g = f grad_g = tf_np_extensions . grad ( g , * * kwargs ) if argnums == 0 : return grad_g def grad_f ( * args , * * kwargs ) : args = list ( args ) args [ 0 ] , args [ argnums ] = args [ argnums ] , args [ 0 ] return grad_g ( * args , * * kwargs ) return grad_f