Creates an `Operation` in this graph. Implements `Graph.create_op()` without the overhead of the deprecation wrapper. Args: op_type: The `Operation` type to create. This corresponds to the `OpDef.name` field for the proto that defines the operation. inputs: A list o
(
self,
op_type,
inputs,
dtypes=None, # pylint: disable=redefined-outer-name
input_types=None,
name=None,
attrs=None,
op_def=None,
compute_device=True)
| 3361 | attrs, op_def, compute_device) |
| 3362 | |
| 3363 | def _create_op_internal( |
| 3364 | self, |
| 3365 | op_type, |
| 3366 | inputs, |
| 3367 | dtypes=None, # pylint: disable=redefined-outer-name |
| 3368 | input_types=None, |
| 3369 | name=None, |
| 3370 | attrs=None, |
| 3371 | op_def=None, |
| 3372 | compute_device=True): |
| 3373 | """Creates an `Operation` in this graph. |
| 3374 | |
| 3375 | Implements `Graph.create_op()` without the overhead of the deprecation |
| 3376 | wrapper. |
| 3377 | |
| 3378 | Args: |
| 3379 | op_type: The `Operation` type to create. This corresponds to the |
| 3380 | `OpDef.name` field for the proto that defines the operation. |
| 3381 | inputs: A list of `Tensor` objects that will be inputs to the `Operation`. |
| 3382 | dtypes: (Optional) A list of `DType` objects that will be the types of the |
| 3383 | tensors that the operation produces. |
| 3384 | input_types: (Optional.) A list of `DType`s that will be the types of the |
| 3385 | tensors that the operation consumes. By default, uses the base `DType` |
| 3386 | of each input in `inputs`. Operations that expect reference-typed inputs |
| 3387 | must specify `input_types` explicitly. |
| 3388 | name: (Optional.) A string name for the operation. If not specified, a |
| 3389 | name is generated based on `op_type`. |
| 3390 | attrs: (Optional.) A dictionary where the key is the attribute name (a |
| 3391 | string) and the value is the respective `attr` attribute of the |
| 3392 | `NodeDef` proto that will represent the operation (an `AttrValue` |
| 3393 | proto). |
| 3394 | op_def: (Optional.) The `OpDef` proto that describes the `op_type` that |
| 3395 | the operation will have. |
| 3396 | compute_device: (Optional.) If True, device functions will be executed to |
| 3397 | compute the device property of the Operation. |
| 3398 | |
| 3399 | Raises: |
| 3400 | ValueError: if colocation conflicts with existing device assignment. |
| 3401 | |
| 3402 | Returns: |
| 3403 | An `Operation` object. |
| 3404 | """ |
| 3405 | self._check_not_finalized() |
| 3406 | if name is None: |
| 3407 | name = op_type |
| 3408 | # If a names ends with a '/' it is a "name scope" and we use it as-is, |
| 3409 | # after removing the trailing '/'. |
| 3410 | if name and name[-1] == "/": |
| 3411 | name = name_from_scope_name(name) |
| 3412 | else: |
| 3413 | name = self.unique_name(name) |
| 3414 | |
| 3415 | node_def = _NodeDef(op_type, name, device=None, attrs=attrs) |
| 3416 | |
| 3417 | input_ops = set([t.op for t in inputs]) |
| 3418 | control_inputs = self._control_dependencies_for_inputs(input_ops) |
| 3419 | # _create_op_helper mutates the new Operation. `_mutation_lock` ensures a |
| 3420 | # Session.run call cannot occur between creating and mutating the op. |
no test coverage detected