Browse Source

TF_Status holds error information.

tags/v0.1.0-Tensor
Oceania2018 7 years ago
parent
commit
e784618327
4 changed files with 63 additions and 3 deletions
  1. +12
    -2
      src/TensorFlowNET.Core/Status.cs
  2. +14
    -0
      src/TensorFlowNET.Core/c_api.cs
  3. +1
    -1
      test/TensorFlowNET.UnitTest/OperationsTest.cs
  4. +36
    -0
      test/TensorFlowNET.UnitTest/StatusTest.cs

+ 12
- 2
src/TensorFlowNET.Core/Status.cs View File

@@ -4,9 +4,9 @@ using System.Text;


namespace Tensorflow namespace Tensorflow
{ {
public class Status
public class Status : IDisposable
{ {
private IntPtr _handle;
private readonly IntPtr _handle;
public IntPtr Handle => _handle; public IntPtr Handle => _handle;


/// <summary> /// <summary>
@@ -23,5 +23,15 @@ namespace Tensorflow
{ {
_handle = c_api.TF_NewStatus(); _handle = c_api.TF_NewStatus();
} }

public void SetStatus(TF_Code code, string msg)
{
c_api.TF_SetStatus(_handle, code, msg);
}

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

+ 14
- 0
src/TensorFlowNET.Core/c_api.cs View File

@@ -28,6 +28,13 @@ namespace Tensorflow
[DllImport(TensorFlowLibName)] [DllImport(TensorFlowLibName)]
public static unsafe extern void TF_DeleteSessionOptions(IntPtr opts); public static unsafe extern void TF_DeleteSessionOptions(IntPtr opts);


/// <summary>
/// Delete a previously created status object.
/// </summary>
/// <param name="s"></param>
[DllImport(TensorFlowLibName)]
public static unsafe extern void TF_DeleteStatus(IntPtr s);

/// <summary> /// <summary>
/// Destroy a tensor. /// Destroy a tensor.
/// </summary> /// </summary>
@@ -59,6 +66,10 @@ namespace Tensorflow
[DllImport(TensorFlowLibName)] [DllImport(TensorFlowLibName)]
public static unsafe extern TF_OperationDescription TF_NewOperation(IntPtr graph, string opType, string oper_name); public static unsafe extern TF_OperationDescription TF_NewOperation(IntPtr graph, string opType, string oper_name);


/// <summary>
/// Return a new status object.
/// </summary>
/// <returns></returns>
[DllImport(TensorFlowLibName)] [DllImport(TensorFlowLibName)]
public static unsafe extern IntPtr TF_NewStatus(); public static unsafe extern IntPtr TF_NewStatus();


@@ -121,6 +132,9 @@ namespace Tensorflow
[DllImport(TensorFlowLibName)] [DllImport(TensorFlowLibName)]
public static extern unsafe void TF_SetAttrType(TF_OperationDescription desc, string attr_name, TF_DataType value); public static extern unsafe void TF_SetAttrType(TF_OperationDescription desc, string attr_name, TF_DataType value);


[DllImport(TensorFlowLibName)]
public static extern void TF_SetStatus(IntPtr s, TF_Code code, string msg);

/// <summary> /// <summary>
/// Return the size of the underlying data in bytes. /// Return the size of the underlying data in bytes.
/// </summary> /// </summary>


+ 1
- 1
test/TensorFlowNET.UnitTest/OperationsTest.cs View File

@@ -34,7 +34,7 @@ namespace TensorFlowNET.UnitTest
feed_dict.Add(a, 3.0f); feed_dict.Add(a, 3.0f);
feed_dict.Add(b, 2.0f); feed_dict.Add(b, 2.0f);


//var o = sess.run(c, feed_dict);
var o = sess.run(c, feed_dict);
} }
} }




+ 36
- 0
test/TensorFlowNET.UnitTest/StatusTest.cs View File

@@ -0,0 +1,36 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Text;
using Tensorflow;

namespace TensorFlowNET.UnitTest
{
[TestClass]
public class StatusTest
{
[TestMethod]
public void NewStatus()
{
var s = new Status();
Assert.AreEqual(s.Code, TF_Code.TF_OK);
Assert.AreEqual(s.Message, String.Empty);
}

[TestMethod]
public void SetStatus()
{
var s = new Status();
s.SetStatus(TF_Code.TF_CANCELLED, "cancel");
Assert.AreEqual(s.Code, TF_Code.TF_CANCELLED);
// Assert.AreEqual(s.Message, "cancel");
}

[TestMethod]
public void DeleteStatus()
{
var s = new Status();
s.Dispose();
}
}
}

Loading…
Cancel
Save