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

Function _prepare

tensorflow/python/ops/gradient_checker_v2.py:97–123  ·  view source on GitHub ↗

Return a function that executes 'f'. In TF 2.x, this is the same as `f`. In TF 1.x, returns a Python function that executes the graph defined by `f` in a Session. Args: f: the function. xs_dtypes: dtypes of f's arguments. Returns: a function that will be evaluated in b

(f, xs_dtypes)

Source from the content-addressed store, hash-verified

95
96
97def _prepare(f, xs_dtypes):
98 """Return a function that executes 'f'.
99
100 In TF 2.x, this is the same as `f`.
101 In TF 1.x, returns a Python function that executes the graph defined by `f`
102 in a Session.
103
104 Args:
105 f: the function.
106 xs_dtypes: dtypes of f's arguments.
107
108 Returns:
109 a function that will be evaluated in both graph and eager mode
110 """
111 if context.executing_eagerly():
112
113 def decorated_eager(*xs_data):
114 return f(*map(ops.convert_to_tensor, xs_data))
115
116 return decorated_eager
117 xs = [array_ops.placeholder(x_dtype) for x_dtype in xs_dtypes]
118 y = f(*xs)
119 sess = ops.get_default_session()
120 def decorated_graph(*xs_data):
121 xs_data = [_to_numpy(a) for a in xs_data]
122 return sess.run(y, feed_dict=dict(zip(xs, xs_data)))
123 return decorated_graph
124
125
126def _compute_theoretical_jacobian(f, y_shape, y_dtype, xs, param):

Callers 3

_compute_gradient_listFunction · 0.85

Calls 3

executing_eagerlyMethod · 0.80
fFunction · 0.70
placeholderMethod · 0.45

Tested by

no test coverage detected