| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d5b81e9 commit 64cc96b
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Core", "src\T | |||
| 9 | 9 | EndProject | |
| 10 | 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Examples", "test\TensorFlowNET.Examples\TensorFlowNET.Examples.csproj", "{1FE60088-157C-4140-91AB-E96B915E4BAE}" | |
| 11 | 11 | EndProject | |
| 12 | - Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NumSharp.Core", "..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj", "{DA680126-DA60-4CE3-9094-72C355C081D3}" | ||
| 13 | - EndProject | ||
| 14 | 12 | Global | |
| 15 | 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution | |
| 16 | 14 | Debug|Any CPU = Debug|Any CPU | |
@@ -29,10 +27,6 @@ Global | |||
| 29 | 27 | {1FE60088-157C-4140-91AB-E96B915E4BAE}.Debug|Any CPU.Build.0 = Debug|Any CPU | |
| 30 | 28 | {1FE60088-157C-4140-91AB-E96B915E4BAE}.Release|Any CPU.ActiveCfg = Release|Any CPU | |
| 31 | 29 | {1FE60088-157C-4140-91AB-E96B915E4BAE}.Release|Any CPU.Build.0 = Release|Any CPU | |
| 32 | - {DA680126-DA60-4CE3-9094-72C355C081D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| 33 | - {DA680126-DA60-4CE3-9094-72C355C081D3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| 34 | - {DA680126-DA60-4CE3-9094-72C355C081D3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| 35 | - {DA680126-DA60-4CE3-9094-72C355C081D3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| 36 | 30 | EndGlobalSection | |
| 37 | 31 | GlobalSection(SolutionProperties) = preSolution | |
| 38 | 32 | HideSolutionNode = FALSE | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,25 @@ public static partial class c_api | |||
| 31 | 31 | [DllImport(TensorFlowLibName)] | |
| 32 | 32 | public static extern void TF_GraphGetTensorShape(IntPtr graph, TF_Output output, long[] dims, int num_dims, IntPtr status); | |
| 33 | 33 | ||
| 34 | + /// <summary> | ||
| 35 | + /// Iterate through the operations of a graph. | ||
| 36 | + /// </summary> | ||
| 37 | + /// <param name="graph"></param> | ||
| 38 | + /// <param name="pos"></param> | ||
| 39 | + /// <returns></returns> | ||
| 40 | + [DllImport(TensorFlowLibName)] | ||
| 41 | + public static extern IntPtr TF_GraphNextOperation(IntPtr graph, ref uint pos); | ||
| 42 | + | ||
| 43 | + /// <summary> | ||
| 44 | + /// Returns the operation in the graph with `oper_name`. Returns nullptr if | ||
| 45 | + /// no operation found. | ||
| 46 | + /// </summary> | ||
| 47 | + /// <param name="graph"></param> | ||
| 48 | + /// <param name="oper_name"></param> | ||
| 49 | + /// <returns></returns> | ||
| 50 | + [DllImport(TensorFlowLibName)] | ||
| 51 | + public static extern IntPtr TF_GraphOperationByName(IntPtr graph, string oper_name); | ||
| 52 | + | ||
| 34 | 53 | /// <summary> | |
| 35 | 54 | /// Sets the shape of the Tensor referenced by `output` in `graph` to | |
| 36 | 55 | /// the shape described by `dims` and `num_dims`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,6 +116,8 @@ public override bool Equals(object obj) | |||
| 116 | 116 | { | |
| 117 | 117 | case IntPtr val: | |
| 118 | 118 | return val == _handle; | |
| 119 | + case Operation val: | ||
| 120 | + return val._handle == _handle; | ||
| 119 | 121 | } | |
| 120 | 122 | ||
| 121 | 123 | return base.Equals(obj); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + using System; | ||
| 2 | + using System.Collections.Generic; | ||
| 3 | + using System.Text; | ||
| 4 | + | ||
| 5 | + namespace Tensorflow | ||
| 6 | + { | ||
| 7 | + public class OperationDescription | ||
| 8 | + { | ||
| 9 | + private IntPtr _handle; | ||
| 10 | + | ||
| 11 | + public OperationDescription(IntPtr handle) | ||
| 12 | + { | ||
| 13 | + _handle = handle; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + public static implicit operator OperationDescription(IntPtr handle) | ||
| 17 | + { | ||
| 18 | + return new OperationDescription(handle); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + public static implicit operator IntPtr(OperationDescription desc) | ||
| 22 | + { | ||
| 23 | + return desc._handle; | ||
| 24 | + } | ||
| 25 | + } | ||
| 26 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ namespace Tensorflow | |||
| 9 | 9 | public struct TF_OperationDescription | |
| 10 | 10 | { | |
| 11 | 11 | public IntPtr node_builder; | |
| 12 | - //public TF_Graph graph; | ||
| 12 | + public IntPtr graph; | ||
| 13 | + public IntPtr colocation_constraints; | ||
| 13 | 14 | } | |
| 14 | 15 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,11 +33,7 @@ | |||
| 33 | 33 | ||
| 34 | 34 | <ItemGroup> | |
| 35 | 35 | <PackageReference Include="Google.Protobuf" Version="3.6.1" /> | |
| 36 | - <PackageReference Include="NumSharp" Version="0.6.2" /> | ||
| 37 | - </ItemGroup> | ||
| 38 | - | ||
| 39 | - <ItemGroup> | ||
| 40 | - <ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" /> | ||
| 36 | + <PackageReference Include="NumSharp" Version="0.6.3" /> | ||
| 41 | 37 | </ItemGroup> | |
| 42 | 38 | ||
| 43 | 39 | <ItemGroup> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ namespace Tensorflow | |||
| 22 | 22 | /// int32_t => int | |
| 23 | 23 | /// int64_t* => long[] | |
| 24 | 24 | /// size_t* => unlong[] | |
| 25 | + /// size_t* => ref uint | ||
| 25 | 26 | /// void* => IntPtr | |
| 26 | 27 | /// string => IntPtr c_api.StringPiece(IntPtr) | |
| 27 | 28 | /// </summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,11 +6,10 @@ | |||
| 6 | 6 | </PropertyGroup> | |
| 7 | 7 | ||
| 8 | 8 | <ItemGroup> | |
| 9 | - <PackageReference Include="NumSharp" Version="0.6.2" /> | ||
| 9 | + <PackageReference Include="NumSharp" Version="0.6.3" /> | ||
| 10 | 10 | </ItemGroup> | |
| 11 | 11 | ||
| 12 | 12 | <ItemGroup> | |
| 13 | - <ProjectReference Include="..\..\..\NumSharp\src\NumSharp.Core\NumSharp.Core.csproj" /> | ||
| 14 | 13 | <ProjectReference Include="..\..\src\TensorFlowNET.Core\TensorFlowNET.Core.csproj" /> | |
| 15 | 14 | </ItemGroup> | |
| 16 | 15 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,21 +104,98 @@ public void c_api_Graph() | |||
| 104 | 104 | Assert.IsFalse(found_placeholder); | |
| 105 | 105 | found_placeholder = true; | |
| 106 | 106 | } | |
| 107 | - /*else if (IsScalarConst(n, 3)) | ||
| 107 | + else if (c_test_util.IsScalarConst(n, 3)) | ||
| 108 | 108 | { | |
| 109 | 109 | Assert.IsFalse(found_scalar_const); | |
| 110 | 110 | found_scalar_const = true; | |
| 111 | 111 | } | |
| 112 | - else if (IsAddN(n, 2)) | ||
| 112 | + else if (c_test_util.IsAddN(n, 2)) | ||
| 113 | 113 | { | |
| 114 | 114 | Assert.IsFalse(found_add); | |
| 115 | 115 | found_add = true; | |
| 116 | 116 | } | |
| 117 | 117 | else | |
| 118 | 118 | { | |
| 119 | - ADD_FAILURE() << "Unexpected NodeDef: " << ProtoDebugString(n); | ||
| 120 | - }*/ | ||
| 119 | + Assert.Fail($"Unexpected NodeDef: {n}"); | ||
| 120 | + } | ||
| 121 | 121 | } | |
| 122 | + Assert.IsTrue(found_placeholder); | ||
| 123 | + Assert.IsTrue(found_scalar_const); | ||
| 124 | + Assert.IsTrue(found_add); | ||
| 125 | + | ||
| 126 | + // Add another oper to the graph. | ||
| 127 | + var neg = c_test_util.Neg(add, graph, s); | ||
| 128 | + Assert.AreEqual(TF_Code.TF_OK, s.Code); | ||
| 129 | + | ||
| 130 | + // Serialize to NodeDef. | ||
| 131 | + var node_def = c_test_util.GetNodeDef(neg); | ||
| 132 | + | ||
| 133 | + // Validate NodeDef is what we expect. | ||
| 134 | + Assert.IsTrue(c_test_util.IsNeg(node_def, "add")); | ||
| 135 | + | ||
| 136 | + // Serialize to GraphDef. | ||
| 137 | + var graph_def2 = c_test_util.GetGraphDef(graph); | ||
| 138 | + | ||
| 139 | + // Compare with first GraphDef + added NodeDef. | ||
| 140 | + graph_def.Node.Add(node_def); | ||
| 141 | + Assert.AreEqual(graph_def.ToString(), graph_def2.ToString()); | ||
| 142 | + | ||
| 143 | + // Look up some nodes by name. | ||
| 144 | + Operation neg2 = c_api.TF_GraphOperationByName(graph, "neg"); | ||
| 145 | + Assert.AreEqual(neg, neg2); | ||
| 146 | + var node_def2 = c_test_util.GetNodeDef(neg2); | ||
| 147 | + Assert.AreEqual(node_def.ToString(), node_def2.ToString()); | ||
| 148 | + | ||
| 149 | + Operation feed2 = c_api.TF_GraphOperationByName(graph, "feed"); | ||
| 150 | + Assert.AreEqual(feed, feed2); | ||
| 151 | + node_def = c_test_util.GetNodeDef(feed); | ||
| 152 | + node_def2 = c_test_util.GetNodeDef(feed2); | ||
| 153 | + Assert.AreEqual(node_def.ToString(), node_def2.ToString()); | ||
| 154 | + | ||
| 155 | + // Test iterating through the nodes of a graph. | ||
| 156 | + found_placeholder = false; | ||
| 157 | + found_scalar_const = false; | ||
| 158 | + found_add = false; | ||
| 159 | + bool found_neg = false; | ||
| 160 | + uint pos = 0; | ||
| 161 | + Operation oper; | ||
| 162 | + | ||
| 163 | + while((oper = c_api.TF_GraphNextOperation(graph, ref pos)) != IntPtr.Zero) | ||
| 164 | + { | ||
| 165 | + if (oper.Equals(feed)) | ||
| 166 | + { | ||
| 167 | + Assert.IsFalse(found_placeholder); | ||
| 168 | + found_placeholder = true; | ||
| 169 | + } | ||
| 170 | + else if (oper.Equals(three)) | ||
| 171 | + { | ||
| 172 | + Assert.IsFalse(found_scalar_const); | ||
| 173 | + found_scalar_const = true; | ||
| 174 | + } | ||
| 175 | + else if (oper.Equals(add)) | ||
| 176 | + { | ||
| 177 | + Assert.IsFalse(found_add); | ||
| 178 | + found_add = true; | ||
| 179 | + } | ||
| 180 | + else if (oper.Equals(neg)) | ||
| 181 | + { | ||
| 182 | + Assert.IsFalse(found_neg); | ||
| 183 | + found_neg = true; | ||
| 184 | + } | ||
| 185 | + else | ||
| 186 | + { | ||
| 187 | + node_def = c_test_util.GetNodeDef(oper); | ||
| 188 | + Assert.Fail($"Unexpected Node: {node_def.ToString()}"); | ||
| 189 | + } | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + Assert.IsTrue(found_placeholder); | ||
| 193 | + Assert.IsTrue(found_scalar_const); | ||
| 194 | + Assert.IsTrue(found_add); | ||
| 195 | + Assert.IsTrue(found_neg); | ||
| 196 | + | ||
| 197 | + graph.Dispose(); | ||
| 198 | + s.Dispose(); | ||
| 122 | 199 | } | |
| 123 | 200 | } | |
| 124 | 201 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ public void SetStatus() | |||
| 23 | 23 | var s = new Status(); | |
| 24 | 24 | s.SetStatus(TF_Code.TF_CANCELLED, "cancel"); | |
| 25 | 25 | Assert.AreEqual(s.Code, TF_Code.TF_CANCELLED); | |
| 26 | - // Assert.AreEqual(s.Message, "cancel"); | ||
| 26 | + Assert.AreEqual(s.Message, "cancel"); | ||
| 27 | 27 | } | |
| 28 | 28 | ||
| 29 | 29 | [TestMethod] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments