forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContext.cs
More file actions
48 lines (38 loc) · 1.36 KB
/
Context.cs
File metadata and controls
48 lines (38 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
namespace Tensorflow.Eager
{
public class Context : DisposableObject
{
public const int GRAPH_MODE = 0;
public const int EAGER_MODE = 1;
public int default_execution_mode;
public string device_name = "";
public string scope_name = "";
bool _initialized = false;
public Context(ContextOptions opts, Status status)
{
_handle = c_api.TFE_NewContext(opts, status);
status.Check(true);
}
public void ensure_initialized()
{
if (_initialized)
return;
_initialized = true;
}
/// <summary>
/// Dispose any unmanaged resources related to given <paramref name="handle"/>.
/// </summary>
protected sealed override void DisposeUnmanagedResources(IntPtr handle)
=> c_api.TFE_DeleteContext(_handle);
public bool executing_eagerly() => true;
public string shared_name(string name = null)
=> !string.IsNullOrEmpty(name) || !executing_eagerly() ?
name :
"cd2c89b7-88b7-44c8-ad83-06c2a9158347";
public static implicit operator IntPtr(Context ctx)
=> ctx._handle;
public static implicit operator TFE_Context(Context ctx)
=> new TFE_Context(ctx._handle);
}
}