diff --git a/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs b/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs index 883f2b64..2d099292 100644 --- a/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs +++ b/src/TensorFlowNET.Core/Graphs/Graph.Operation.cs @@ -21,8 +21,14 @@ namespace Tensorflow public OperationDescription NewOperation(string opType, string opName) { return c_api.TF_NewOperation(_handle, opType, opName); - } - + } + + /// + /// Returns the `Operation` with the given `name`. + /// + /// This method may be called concurrently from multiple threads. + /// + /// The name of the `Operation` to return. public Operation get_operation_by_name(string name) => as_graph_element(name, allow_tensor: false, allow_operation: true) as Operation; diff --git a/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs b/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs index 3887d2a1..8def1417 100644 --- a/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs +++ b/src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs @@ -17,8 +17,29 @@ namespace Tensorflow private bool _new_stack; private IControlFlowContext _old_control_flow_context; - public ITensorOrOperation[] control_inputs => _control_inputs_val.ToArray(); - + public ITensorOrOperation[] control_inputs => _control_inputs_val.ToArray(); + + /// + /// Create a new `_ControlDependenciesController`. + /// + /// A `_ControlDependenciesController` is the context manager for + /// `with tf.control_dependencies()` blocks.These normally nest, + /// as described in the documentation for `control_dependencies()`. + /// + /// The `control_inputs` argument list control dependencies that must be + /// added to the current set of control dependencies.Because of + /// uniquification the set can be empty even if the caller passed a list of + /// ops.The special value `None` indicates that we want to start a new + /// empty set of control dependencies instead of extending the current set. + /// + /// In that case we also clear the current control flow context, which is an + /// additional mechanism to add control dependencies. + /// + /// The graph that this controller is managing. + /// List of ops to use as control inputs in addition + /// to the current control dependencies.None to indicate that + /// the dependencies should be cleared. + /// public _ControlDependenciesController(Graph graph, List control_inputs) { _graph = graph; diff --git a/src/TensorFlowNET.Core/Operations/Operation.Input.cs b/src/TensorFlowNET.Core/Operations/Operation.Input.cs index 5db34ce9..9ef89271 100644 --- a/src/TensorFlowNET.Core/Operations/Operation.Input.cs +++ b/src/TensorFlowNET.Core/Operations/Operation.Input.cs @@ -1,68 +1,79 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; - -namespace Tensorflow -{ - public partial class Operation - { - public TF_Output Input(int index) => c_api.TF_OperationInput(new TF_Input(_handle, index)); - public TF_DataType InputType(int index) => c_api.TF_OperationInputType(new TF_Input(_handle, index)); - public int InputListLength(string name) => c_api.TF_OperationInputListLength(_handle, name, status); - public int NumInputs => c_api.TF_OperationNumInputs(_handle); - private TF_DataType[] _input_types => _inputs._inputs.Select(x => x.dtype).ToArray(); - - private InputList _inputs; - public InputList inputs - { - get - { - if (_inputs == null) - { - var retval = new Tensor[NumInputs]; - - for (int i = 0; i < NumInputs; i++) - { - var tf_outpus = Input(i); - var op = new Operation(tf_outpus.oper); - retval[i] = op.outputs[tf_outpus.index]; - } - - _inputs = new InputList(retval); - } - - return _inputs; - } - } - - public int NumControlInputs => c_api.TF_OperationNumControlInputs(_handle); - - public Operation[] control_inputs - { - get - { - return GetControlInputs(); - } - } - - public unsafe Operation[] GetControlInputs() - { - var control_inputs = new Operation[NumControlInputs]; - - if (NumControlInputs > 0) - { - IntPtr control_input_handle = Marshal.AllocHGlobal(Marshal.SizeOf() * NumControlInputs); - c_api.TF_OperationGetControlInputs(_handle, control_input_handle, NumControlInputs); - for (int i = 0; i < NumControlInputs; i++) - { - var handle = control_input_handle + Marshal.SizeOf() * i; - control_inputs[i] = new Operation(*(IntPtr*)handle); - } - } - - return control_inputs; - } - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; + +namespace Tensorflow +{ + + // from ops.py + public partial class Operation + { + public TF_Output Input(int index) => c_api.TF_OperationInput(new TF_Input(_handle, index)); + public TF_DataType InputType(int index) => c_api.TF_OperationInputType(new TF_Input(_handle, index)); + public int InputListLength(string name) => c_api.TF_OperationInputListLength(_handle, name, status); + public int NumInputs => c_api.TF_OperationNumInputs(_handle); + private TF_DataType[] _input_types => _inputs._inputs.Select(x => x.dtype).ToArray(); + + private InputList _inputs; + public InputList inputs + { + get + { + if (_inputs == null) + { + var retval = new Tensor[NumInputs]; + + for (int i = 0; i < NumInputs; i++) + { + var tf_outpus = Input(i); + var op = new Operation(tf_outpus.oper); + retval[i] = op.outputs[tf_outpus.index]; + } + + _inputs = new InputList(retval); + } + + return _inputs; + } + } + + public int NumControlInputs => c_api.TF_OperationNumControlInputs(_handle); + + /// + /// The `Operation` objects on which this op has a control dependency. + /// + /// Before this op is executed, TensorFlow will ensure that the + /// operations in `self.control_inputs` have finished executing.This + /// mechanism can be used to run ops sequentially for performance + /// reasons, or to ensure that the side effects of an op are observed + /// in the correct order. + /// + public Operation[] control_inputs + { + get + { + return GetControlInputs(); + } + } + + public unsafe Operation[] GetControlInputs() + { + var control_inputs = new Operation[NumControlInputs]; + + if (NumControlInputs > 0) + { + IntPtr control_input_handle = Marshal.AllocHGlobal(Marshal.SizeOf() * NumControlInputs); + c_api.TF_OperationGetControlInputs(_handle, control_input_handle, NumControlInputs); + for (int i = 0; i < NumControlInputs; i++) + { + var handle = control_input_handle + Marshal.SizeOf() * i; + control_inputs[i] = new Operation(*(IntPtr*)handle); + } + } + + return control_inputs; + } + } +}