Adds a function to the graph. After the function has been added, you can call to the function by passing the function name in place of an op name to `Graph.create_op()`. Args: function: A `_DefinedFunction` object. Raises: ValueError: if another function is defined
(self, function)
| 3265 | return self._functions.get(compat.as_str(name), None) |
| 3266 | |
| 3267 | def _add_function(self, function): |
| 3268 | """Adds a function to the graph. |
| 3269 | |
| 3270 | After the function has been added, you can call to the function by |
| 3271 | passing the function name in place of an op name to |
| 3272 | `Graph.create_op()`. |
| 3273 | |
| 3274 | Args: |
| 3275 | function: A `_DefinedFunction` object. |
| 3276 | |
| 3277 | Raises: |
| 3278 | ValueError: if another function is defined with the same name. |
| 3279 | """ |
| 3280 | name = function.name |
| 3281 | # Sanity checks on gradient definition. |
| 3282 | if (function.grad_func_name is not None) and (function.python_grad_func is |
| 3283 | not None): |
| 3284 | raise ValueError("Gradient defined twice for function %s" % name) |
| 3285 | |
| 3286 | # Add function to graph |
| 3287 | # pylint: disable=protected-access |
| 3288 | gradient = ( |
| 3289 | function._grad_func._c_func.func if function._grad_func else None) |
| 3290 | c_api.TF_GraphCopyFunction(self._c_graph, function._c_func.func, gradient) |
| 3291 | # pylint: enable=protected-access |
| 3292 | |
| 3293 | self._functions[compat.as_str(name)] = function |
| 3294 | |
| 3295 | # Need a new-enough consumer to support the functions we add to the graph. |
| 3296 | if self._graph_def_versions.min_consumer < 12: |
| 3297 | self._graph_def_versions.min_consumer = 12 |
| 3298 | |
| 3299 | @property |
| 3300 | def building_function(self): |
no outgoing calls
no test coverage detected