Browse Source

Revamped Context and ContextOptions

tags/v0.12
Eli Belash 6 years ago
parent
commit
a7dd34dca6
2 changed files with 23 additions and 31 deletions
  1. +12
    -17
      src/TensorFlowNET.Core/Eager/Context.cs
  2. +11
    -14
      src/TensorFlowNET.Core/Eager/ContextOptions.cs

+ 12
- 17
src/TensorFlowNET.Core/Eager/Context.cs View File

@@ -2,12 +2,10 @@

namespace Tensorflow.Eager
{
public class Context : IDisposable
public class Context : DisposableObject
{
private IntPtr _handle;

public static int GRAPH_MODE = 0;
public static int EAGER_MODE = 1;
public const int GRAPH_MODE = 0;
public const int EAGER_MODE = 1;

public int default_execution_mode;

@@ -17,19 +15,16 @@ namespace Tensorflow.Eager
status.Check(true);
}

public void Dispose()
{
c_api.TFE_DeleteContext(_handle);
}
/// <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()
{
return false;
}

public static implicit operator IntPtr(Context ctx)
{
return ctx._handle;
}
public bool executing_eagerly() => false;

public static implicit operator IntPtr(Context ctx)
=> ctx._handle;
}
}

+ 11
- 14
src/TensorFlowNET.Core/Eager/ContextOptions.cs View File

@@ -3,23 +3,20 @@ using System.IO;

namespace Tensorflow.Eager
{
public class ContextOptions : IDisposable //TODO! Eli: Shouldn't this inherieting DisposableObject?
public class ContextOptions : DisposableObject
{
private IntPtr _handle;
public ContextOptions() : base(c_api.TFE_NewContextOptions())
{ }

public ContextOptions()
{
_handle = c_api.TFE_NewContextOptions();
}
/// <summary>
/// Dispose any unmanaged resources related to given <paramref name="handle"/>.
/// </summary>
protected sealed override void DisposeUnmanagedResources(IntPtr handle)
=> c_api.TFE_DeleteContextOptions(_handle);

public void Dispose()
{
c_api.TFE_DeleteContextOptions(_handle);
}

public static implicit operator IntPtr(ContextOptions opts)
{
return opts._handle;
}
public static implicit operator IntPtr(ContextOptions opts)
=> opts._handle;
}

}

Loading…
Cancel
Save