MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _get_arg_spec

Function _get_arg_spec

tensorflow/python/eager/backprop.py:275–298  ·  view source on GitHub ↗

The positions of the parameters of f to be differentiated in param_args.

(f, params, param_args)

Source from the content-addressed store, hash-verified

273
274
275def _get_arg_spec(f, params, param_args):
276 """The positions of the parameters of f to be differentiated in param_args."""
277 try:
278 args = tf_inspect.getfullargspec(f).args
279 except TypeError as e:
280 # TypeError can happen when f is a callable object.
281 if params is None:
282 return range(len(param_args))
283 elif all(isinstance(x, int) for x in params):
284 return params
285 raise ValueError("Either callable provided is not a function or could not "
286 "inspect its arguments by name: %s. Original error: %s"
287 % (f, e))
288 if params is None:
289 if not args:
290 return range(len(param_args))
291 return range(len(args))
292 elif all(isinstance(x, six.string_types) for x in params):
293 return [args.index(n) for n in params]
294 elif all(isinstance(x, int) for x in params):
295 return params
296 else:
297 raise ValueError(
298 "params must be all strings or all integers; got %s." % params)
299
300
301def gradients_function(f, params=None):

Callers 1

decoratedFunction · 0.70

Calls 3

allFunction · 0.85
rangeFunction · 0.50
indexMethod · 0.45

Tested by

no test coverage detected