Skip to content

Commit 5442727

Browse files
committed
change CondContext to IControlFlowContext in Operation and Graph.
1 parent 2e89fa7 commit 5442727

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

src/TensorFlowNET.Core/Gradients/control_flow_grad.py.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text;
4+
using Tensorflow.Operations;
45

56
namespace Tensorflow.Gradients
67
{
@@ -13,7 +14,7 @@ public static Tensor[] _MergeGrad(Operation op, Tensor[] grads)
1314
var input_op = op.inputs[0].op;
1415
var graph = ops.get_default_graph();
1516
var op_ctxt = control_flow_util.GetOutputContext(input_op);
16-
var pred = op_ctxt.pred;
17+
var pred = (op_ctxt as CondContext).pred;
1718

1819
var results = control_flow_ops._SwitchRefOrTensor(grad, pred, name: "cond_grad");
1920
return new Tensor[] { results.Item1, results.Item2 };

src/TensorFlowNET.Core/Operations/Operation.Control.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Tensorflow
77
{
88
public partial class Operation
99
{
10-
private CondContext _control_flow_context;
10+
private IControlFlowContext _control_flow_context;
1111

1212
/// <summary>
1313
/// Add this op to its control flow context.
@@ -28,12 +28,12 @@ public void _add_control_inputs(Operation[] ops)
2828
}
2929
}
3030

31-
public void _set_control_flow_context(CondContext ctx)
31+
public void _set_control_flow_context(IControlFlowContext ctx)
3232
{
3333
_control_flow_context = ctx;
3434
}
3535

36-
public CondContext _get_control_flow_context()
36+
public IControlFlowContext _get_control_flow_context()
3737
{
3838
return _control_flow_context;
3939
}

src/TensorFlowNET.Core/Operations/Operation.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ public Operation(NodeDef node_def, Graph g, Tensor[] inputs = null, TF_DataType[
102102
}
103103
}
104104

105+
// Dict mapping op name to file and line information for op colocation
106+
// context managers.
107+
_control_flow_context = graph._get_control_flow_context();
108+
105109
// This will be set by self.inputs.
106-
if(op_def == null)
110+
if (op_def == null)
107111
op_def = g.GetOpDef(node_def.Op);
108112

109113
var grouped_inputs = _reconstruct_sequence_inputs(op_def, inputs, node_def.Attr);

src/TensorFlowNET.Core/Operations/control_flow_util.py.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static bool IsSwitch(Operation op)
2727
return op.type == "Switch" || op.type == "RefSwitch";
2828
}
2929

30-
public static CondContext GetOutputContext(Operation op)
30+
public static IControlFlowContext GetOutputContext(Operation op)
3131
{
3232
var ctxt = op._get_control_flow_context();
3333

src/TensorFlowNET.Core/TensorFlowNET.Core.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<AssemblyName>TensorFlow.NET</AssemblyName>
66
<RootNamespace>Tensorflow</RootNamespace>
7-
<Version>0.4.2</Version>
7+
<Version>0.5.0</Version>
88
<Authors>Haiping Chen</Authors>
99
<Company>SciSharp STACK</Company>
1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -13,14 +13,13 @@
1313
<RepositoryType>git</RepositoryType>
1414
<PackageProjectUrl>https://github.com/SciSharp</PackageProjectUrl>
1515
<PackageIconUrl>https://avatars3.githubusercontent.com/u/44989469?s=200&amp;v=4</PackageIconUrl>
16-
<PackageTags>TensorFlow, NumSharp, SciSharp, MachineLearning, TensorFlow.NET</PackageTags>
16+
<PackageTags>TensorFlow, NumSharp, SciSharp, MachineLearning, TensorFlow.NET, C#</PackageTags>
1717
<Description>Google's TensorFlow binding in .NET Standard.
1818
Docs: https://tensorflownet.readthedocs.io</Description>
19-
<AssemblyVersion>0.4.2.0</AssemblyVersion>
20-
<PackageReleaseNotes>Added ConfigProto to control CPU and GPU resource.
21-
Fixed import name scope issue.</PackageReleaseNotes>
19+
<AssemblyVersion>0.5.0.0</AssemblyVersion>
20+
<PackageReleaseNotes>Add a lot of APIs to build neural networks model</PackageReleaseNotes>
2221
<LangVersion>7.2</LangVersion>
23-
<FileVersion>0.4.2.0</FileVersion>
22+
<FileVersion>0.5.0.0</FileVersion>
2423
</PropertyGroup>
2524

2625
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

0 commit comments

Comments
 (0)