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

Revamped Context and ContextOptions · MSavameri/TensorFlow.NET@a7dd34d · GitHub

Repository navigation

Commit a7dd34d

Browse files
committed
Revamped Context and ContextOptions
1 parent 1f297ea commit a7dd34d

2 files changed

Lines changed: 23 additions & 31 deletions

File tree

‎src/TensorFlowNET.Core/Eager/Context.cs‎

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace Tensorflow.Eager
44
{
5-
public class Context : IDisposable
5+
public class Context : DisposableObject
66
{
7-
private IntPtr _handle;
8-
9-
public static int GRAPH_MODE = 0;
10-
public static int EAGER_MODE = 1;
7+
public const int GRAPH_MODE = 0;
8+
public const int EAGER_MODE = 1;
119

1210
public int default_execution_mode;
1311

@@ -17,19 +15,16 @@ public Context(ContextOptions opts, Status status)
1715
status.Check(true);
1816
}
1917

20-
public void Dispose()
21-
{
22-
c_api.TFE_DeleteContext(_handle);
23-
}
18+
/// <summary>
19+
/// Dispose any unmanaged resources related to given <paramref name="handle"/>.
20+
/// </summary>
21+
protected sealed override void DisposeUnmanagedResources(IntPtr handle)
22+
=> c_api.TFE_DeleteContext(_handle);
2423

25-
public bool executing_eagerly()
26-
{
27-
return false;
28-
}
2924

30-
public static implicit operator IntPtr(Context ctx)
31-
{
32-
return ctx._handle;
33-
}
25+
public bool executing_eagerly() => false;
26+
27+
public static implicit operator IntPtr(Context ctx)
28+
=> ctx._handle;
3429
}
3530
}

‎src/TensorFlowNET.Core/Eager/ContextOptions.cs‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@
33

44
namespace Tensorflow.Eager
55
{
6-
public class ContextOptions : IDisposable //TODO! Eli: Shouldn't this inherieting DisposableObject?
6+
public class ContextOptions : DisposableObject
77
{
8-
private IntPtr _handle;
8+
public ContextOptions() : base(c_api.TFE_NewContextOptions())
9+
{ }
910

10-
public ContextOptions()
11-
{
12-
_handle = c_api.TFE_NewContextOptions();
13-
}
11+
/// <summary>
12+
/// Dispose any unmanaged resources related to given <paramref name="handle"/>.
13+
/// </summary>
14+
protected sealed override void DisposeUnmanagedResources(IntPtr handle)
15+
=> c_api.TFE_DeleteContextOptions(_handle);
1416

15-
public void Dispose()
16-
{
17-
c_api.TFE_DeleteContextOptions(_handle);
18-
}
1917

20-
public static implicit operator IntPtr(ContextOptions opts)
21-
{
22-
return opts._handle;
23-
}
18+
public static implicit operator IntPtr(ContextOptions opts)
19+
=> opts._handle;
2420
}
21+
2522
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL