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

Graph.Operation-OperationByName: Added guard, docs and exception when… · feelsyt/TensorFlow.NET@e6640b5 · GitHub

Commit e6640b5

Browse files
committed
Graph.Operation-OperationByName: Added guard, docs and exception when IntPtr.Zero is returned
1 parent be02415 commit e6640b5

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎src/TensorFlowNET.Core/Graphs/Graph.Operation.cs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,28 @@ public Operation[] ReturnOperations(IntPtr results)
5959
return return_opers;
6060
}
6161

62+
/// <summary>
63+
/// Get operation with given <paramref name="operName"/>
64+
/// </summary>
65+
/// <exception cref="ValueError">When <paramref name="operName"/> is not found current graph.</exception>
66+
/// <exception cref="RuntimeError">When tf.get_default_graph() is not current graph.</exception>
67+
/// <example>
68+
/// graph.GetOperationByName("CustomInputName");
69+
/// </example>
6270
public Operation OperationByName(string operName)
6371
{
72+
if (operName == null)
73+
throw new ArgumentNullException(nameof(operName));
74+
6475
var handle = c_api.TF_GraphOperationByName(_handle, operName);
76+
if (handle == IntPtr.Zero)
77+
throw new ValueError($"Could not find operation \"{operName}\" inside graph \"{_graph_key}\".");
78+
6579
var defaultKey = tf.get_default_graph().graph_key;
6680
if (graph_key != defaultKey)
6781
{
6882
//Console.WriteLine($"Current graph is not default graph.");
69-
throw new ValueError($"Current graph is not default graph. Default Graph Key: {defaultKey}, Current Graph Key: {graph_key}");
83+
throw new RuntimeError($"Current graph is not default graph. Default Graph Key: {defaultKey}, Current Graph Key: {graph_key}");
7084
}
7185

7286
return new Operation(handle, g: this);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL