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

Method apply_op

tensorflow/python/framework/op_def_library.py:311–354  ·  view source on GitHub ↗

Add a node invoking a registered Op to a graph. Example usage: # input1 and input2 can be Tensors or anything ops.convert_to_tensor() # will convert to a Tensor. op_def_library.apply_op("op", input1=input1, input2=input2) # Can specify a node name. op_def_libr

(self, op_type_name, name=None, **keywords)

Source from the content-addressed store, hash-verified

309 self.add_op(op_def)
310
311 def apply_op(self, op_type_name, name=None, **keywords):
312 # pylint: disable=g-doc-args
313 """Add a node invoking a registered Op to a graph.
314
315 Example usage:
316 # input1 and input2 can be Tensors or anything ops.convert_to_tensor()
317 # will convert to a Tensor.
318 op_def_library.apply_op("op", input1=input1, input2=input2)
319 # Can specify a node name.
320 op_def_library.apply_op("op", input1=input1, name="node_name")
321 # Must use keyword arguments, with the names specified in the OpDef.
322 op_def_library.apply_op("op", input_name=input, attr_name=attr)
323
324 All attrs must either be inferred from an input or specified.
325 (If inferred, the attr must not be specified.) If an attr has a default
326 value specified in the Op's OpDef, then you may pass None as the value
327 of that attr to get the default.
328
329 Args:
330 op_type_name: string. Must match the name field of a registered Op.
331 name: string. Optional name of the created op.
332 **keywords: input Tensor and attr arguments specified by name,
333 and optional parameters to pass when constructing the Operation.
334
335 Returns:
336 The Tensor(s) representing the output of the operation, or the Operation
337 itself if there are no outputs.
338
339 Raises:
340 RuntimeError: On some errors.
341 TypeError: On some errors.
342 ValueError: On some errors.
343 """
344 output_structure, is_stateful, op = self._apply_op_helper(
345 op_type_name, name, **keywords)
346 if output_structure:
347 outputs = op.outputs
348 res = _Restructure(ops.convert_n_to_tensor(outputs), output_structure)
349 if isinstance(res, list) and not res and is_stateful:
350 return op
351 else:
352 return res
353 else:
354 return op
355
356 def _apply_op_helper(self, op_type_name, name=None, **keywords):
357 """Implementation of apply_op that returns output_structure, op."""

Callers 15

TensorMethod · 0.80
testSimpleMethod · 0.80
testSimpleFailuresMethod · 0.80
testReservedInputMethod · 0.80
testPolymorphicMethod · 0.80
testPolymorphicOutMethod · 0.80
testBinaryMethod · 0.80
testRestrictMethod · 0.80
testTypeListMethod · 0.80
testTypeListTwiceMethod · 0.80

Calls 2

_apply_op_helperMethod · 0.95
_RestructureFunction · 0.85

Tested by 15

TensorMethod · 0.64
testSimpleMethod · 0.64
testSimpleFailuresMethod · 0.64
testReservedInputMethod · 0.64
testPolymorphicMethod · 0.64
testPolymorphicOutMethod · 0.64
testBinaryMethod · 0.64
testRestrictMethod · 0.64
testTypeListMethod · 0.64
testTypeListTwiceMethod · 0.64