Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/TensorFlowNET.Core/APIs/tf.math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public static Tensor arg_max(Tensor input, int dimension, TF_DataType output_typ
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>
Expand Down
7 changes: 7 additions & 0 deletions src/TensorFlowNET.Core/Operations/gen_math_ops.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ public static Tensor is_finite(Tensor x, string name = null)
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>
Expand Down
28 changes: 28 additions & 0 deletions test/TensorFlowNET.UnitTest/OperationsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,34 @@ public void addInConstant()
}
}

[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()
{
Expand Down