FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Graph: Added tf.peak_default_graph which just returns null if no defa… · feelsyt/TensorFlow.NET@067e62b · GitHub

Commit 067e62b

Browse files
committed
Graph: Added tf.peak_default_graph which just returns null if no default exists.
1 parent 44d58bc commit 067e62b

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎src/TensorFlowNET.Core/APIs/tf.graph.cs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,19 @@ public Graph get_default_graph()
2929
return ops.get_default_graph();
3030
}
3131

32-
public Graph Graph()
32+
/// <summary>
33+
/// Equivalent to <see cref="get_default_graph"/> but does not create a new graph if it there is none.
34+
/// </summary>
35+
public Graph peak_default_graph()
36+
{
37+
return ops.default_graph_stack.peak_controller();
38+
}
39+
40+
/// <summary>
41+
/// Creates a new graph.
42+
/// </summary>
43+
///<remarks>Has no interaction with graph defaulting. Equivalent to new Graph();</remarks>
44+
public Graph Graph()
3345
=> new Graph();
3446
}
35-
}
47+
}

‎src/TensorFlowNET.Core/Graphs/DefaultGraphStack.cs‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ limitations under the License.
2121

2222
namespace Tensorflow
2323
{
24-
2524
/// <summary>
2625
/// Serves as a stack for determining current default graph.
2726
/// </summary>
28-
public class DefaultGraphStack
27+
public class DefaultGraphStack
2928
{
3029
private readonly List<StackModel> _stack = new List<StackModel>();
3130

@@ -52,6 +51,20 @@ public Graph get_controller()
5251
throw new TensorflowException("Unable to find a default graph");
5352
}
5453

54+
public Graph peak_controller()
55+
{
56+
if (_stack.Count == 0 || _stack.Count(x => x.IsDefault) == 0)
57+
return null;
58+
for (var i = _stack.Count - 1; i >= 0; i--)
59+
{
60+
var x = _stack[i];
61+
if (x.IsDefault)
62+
return x.Graph;
63+
}
64+
65+
return null;
66+
}
67+
5568
public bool remove(Graph g)
5669
{
5770
if (_stack.Count == 0)

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL