Browse Source

Adding `IsNan` operation (#315)

Exposing also the `IsFinite` one.
Unit testing both operations.
tags/v0.12
Antonio Haiping 6 years ago
parent
commit
a880b5326d
3 changed files with 41 additions and 0 deletions
  1. +6
    -0
      src/TensorFlowNET.Core/APIs/tf.math.cs
  2. +7
    -0
      src/TensorFlowNET.Core/Operations/gen_math_ops.cs
  3. +28
    -0
      test/TensorFlowNET.UnitTest/OperationsTest.cs

+ 6
- 0
src/TensorFlowNET.Core/APIs/tf.math.cs View File

@@ -57,6 +57,12 @@ namespace Tensorflow
public static Tensor arg_min(Tensor input, int dimension, TF_DataType output_type = TF_DataType.TF_INT64, string name = null)
=> gen_math_ops.arg_min(input, dimension, output_type: output_type, name: name);

public static Tensor is_finite(Tensor input, string name = null)
=> gen_math_ops.is_finite(input, name);

public static Tensor is_nan(Tensor input, string name = null)
=> gen_math_ops.is_nan(input, name);

/// <summary>
/// Returns element-wise smallest integer not less than x.
/// </summary>


+ 7
- 0
src/TensorFlowNET.Core/Operations/gen_math_ops.cs View File

@@ -376,6 +376,13 @@ namespace Tensorflow
return _op.outputs[0];
}
public static Tensor is_nan(Tensor x, string name = null)
{
var _op = _op_def_lib._apply_op_helper("IsNan", name: name, args: new { x });
return _op.outputs[0];
}
/// <summary>
/// Computes exponential of x element-wise. \\(y = e^x\\).
/// </summary>


+ 28
- 0
test/TensorFlowNET.UnitTest/OperationsTest.cs View File

@@ -61,6 +61,34 @@ namespace TensorFlowNET.UnitTest
}
}

[TestMethod]
public void isFinite()
{
var a = tf.constant(new[] { 1, np.nan, 2, np.nan, 3, np.nan, 4, np.nan });
var b = tf.cast(tf.is_finite(a), tf.float32);
var check = np.array(1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);

using (var sess = tf.Session())
{
var o = sess.run(b);
Assert.IsTrue(o.array_equal(check));
}
}

[TestMethod]
public void isNan()
{
var a = tf.constant(new[] { 1, np.nan, 2, np.nan, 3, np.nan, 4, np.nan });
var b = tf.cast(tf.is_nan(a), tf.float32);
var check = np.array(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);

using (var sess = tf.Session())
{
var o = sess.run(b);
Assert.IsTrue(o.array_equal(check));
}
}

[TestMethod]
public void addOpTests()
{


Loading…
Cancel
Save