Browse Source

more documentation strings

tags/v0.9
Meinrad Recheis 6 years ago
parent
commit
923d8458b2
3 changed files with 110 additions and 72 deletions
  1. +8
    -2
      src/TensorFlowNET.Core/Graphs/Graph.Operation.cs
  2. +23
    -2
      src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs
  3. +79
    -68
      src/TensorFlowNET.Core/Operations/Operation.Input.cs

+ 8
- 2
src/TensorFlowNET.Core/Graphs/Graph.Operation.cs View File

@@ -21,8 +21,14 @@ namespace Tensorflow
public OperationDescription NewOperation(string opType, string opName)
{
return c_api.TF_NewOperation(_handle, opType, opName);
}

}
/// <summary>
/// Returns the `Operation` with the given `name`.
///
/// This method may be called concurrently from multiple threads.
/// </summary>
/// <param name="name">The name of the `Operation` to return.</param>
public Operation get_operation_by_name(string name)
=> as_graph_element(name, allow_tensor: false, allow_operation: true) as Operation;



+ 23
- 2
src/TensorFlowNET.Core/Graphs/_ControlDependenciesController.cs View File

@@ -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();
/// <summary>
/// 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.
/// </summary>
/// <param name="graph">The graph that this controller is managing.</param>
/// <param name="control_inputs">List of ops to use as control inputs in addition
/// to the current control dependencies.None to indicate that
/// the dependencies should be cleared.
/// </param>
public _ControlDependenciesController(Graph graph, List<ITensorOrOperation> control_inputs)
{
_graph = graph;


+ 79
- 68
src/TensorFlowNET.Core/Operations/Operation.Input.cs View File

@@ -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<IntPtr>() * NumControlInputs);
c_api.TF_OperationGetControlInputs(_handle, control_input_handle, NumControlInputs);
for (int i = 0; i < NumControlInputs; i++)
{
var handle = control_input_handle + Marshal.SizeOf<IntPtr>() * 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);
/// <summary>
/// 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.
/// </summary>
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<IntPtr>() * NumControlInputs);
c_api.TF_OperationGetControlInputs(_handle, control_input_handle, NumControlInputs);
for (int i = 0; i < NumControlInputs; i++)
{
var handle = control_input_handle + Marshal.SizeOf<IntPtr>() * i;
control_inputs[i] = new Operation(*(IntPtr*)handle);
}
}
return control_inputs;
}
}
}

Loading…
Cancel
Save