r"""Creates an `Operation`. NOTE: This constructor validates the name of the `Operation` (passed as `node_def.name`). Valid `Operation` names match the following regular expression: [A-Za-z0-9.][A-Za-z0-9_.\\-/]* Args: node_def: `node_def_pb2.NodeDef`. `NodeDef` for
(self,
node_def,
g,
inputs=None,
output_types=None,
control_inputs=None,
input_types=None,
original_op=None,
op_def=None)
| 1635 | """ |
| 1636 | |
| 1637 | def __init__(self, |
| 1638 | node_def, |
| 1639 | g, |
| 1640 | inputs=None, |
| 1641 | output_types=None, |
| 1642 | control_inputs=None, |
| 1643 | input_types=None, |
| 1644 | original_op=None, |
| 1645 | op_def=None): |
| 1646 | r"""Creates an `Operation`. |
| 1647 | |
| 1648 | NOTE: This constructor validates the name of the `Operation` (passed |
| 1649 | as `node_def.name`). Valid `Operation` names match the following |
| 1650 | regular expression: |
| 1651 | |
| 1652 | [A-Za-z0-9.][A-Za-z0-9_.\\-/]* |
| 1653 | |
| 1654 | Args: |
| 1655 | node_def: `node_def_pb2.NodeDef`. `NodeDef` for the `Operation`. Used for |
| 1656 | attributes of `node_def_pb2.NodeDef`, typically `name`, `op`, and |
| 1657 | `device`. The `input` attribute is irrelevant here as it will be |
| 1658 | computed when generating the model. |
| 1659 | g: `Graph`. The parent graph. |
| 1660 | inputs: list of `Tensor` objects. The inputs to this `Operation`. |
| 1661 | output_types: list of `DType` objects. List of the types of the `Tensors` |
| 1662 | computed by this operation. The length of this list indicates the |
| 1663 | number of output endpoints of the `Operation`. |
| 1664 | control_inputs: list of operations or tensors from which to have a control |
| 1665 | dependency. |
| 1666 | input_types: List of `DType` objects representing the types of the tensors |
| 1667 | accepted by the `Operation`. By default uses `[x.dtype.base_dtype for x |
| 1668 | in inputs]`. Operations that expect reference-typed inputs must specify |
| 1669 | these explicitly. |
| 1670 | original_op: Optional. Used to associate the new `Operation` with an |
| 1671 | existing `Operation` (for example, a replica with the op that was |
| 1672 | replicated). |
| 1673 | op_def: Optional. The `op_def_pb2.OpDef` proto that describes the op type |
| 1674 | that this `Operation` represents. |
| 1675 | |
| 1676 | Raises: |
| 1677 | TypeError: if control inputs are not Operations or Tensors, |
| 1678 | or if `node_def` is not a `NodeDef`, |
| 1679 | or if `g` is not a `Graph`, |
| 1680 | or if `inputs` are not tensors, |
| 1681 | or if `inputs` and `input_types` are incompatible. |
| 1682 | ValueError: if the `node_def` name is not valid. |
| 1683 | """ |
| 1684 | # For internal use only: `node_def` can be set to a TF_Operation to create |
| 1685 | # an Operation for that op. This is useful for creating Operations for ops |
| 1686 | # indirectly created by C API methods, e.g. the ops created by |
| 1687 | # TF_ImportGraphDef. When `node_def` is a TF_Operation, all optional fields |
| 1688 | # should be None. |
| 1689 | |
| 1690 | if isinstance(node_def, node_def_pb2.NodeDef): |
| 1691 | if node_def.ByteSize() >= (1 << 31) or node_def.ByteSize() < 0: |
| 1692 | raise ValueError( |
| 1693 | "Cannot create a tensor proto whose content is larger than 2GB.") |
| 1694 | if not _VALID_OP_NAME_REGEX.match(node_def.name): |
nothing calls this directly
no test coverage detected