From 0e99b605a5273554832031400a5033baed1d8537 Mon Sep 17 00:00:00 2001 From: Antonio Cifonelli Date: Wed, 7 Aug 2019 13:36:35 +0200 Subject: [PATCH] Adding `logical_or` operator (#344) Relative unit test in `OperationTest`. --- src/TensorFlowNET.Core/APIs/tf.math.cs | 3 +++ src/TensorFlowNET.Core/Operations/gen_math_ops.cs | 7 +++++++ test/TensorFlowNET.UnitTest/OperationsTest.cs | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/src/TensorFlowNET.Core/APIs/tf.math.cs b/src/TensorFlowNET.Core/APIs/tf.math.cs index b787bf1d..e76c1e4b 100644 --- a/src/TensorFlowNET.Core/APIs/tf.math.cs +++ b/src/TensorFlowNET.Core/APIs/tf.math.cs @@ -195,6 +195,9 @@ namespace Tensorflow public static Tensor logical_not(Tensor x, string name = null) => gen_math_ops.logical_not(x, name); + public static Tensor logical_or(Tensor x, Tensor y, string name = null) + => gen_math_ops.logical_or(x, y, name); + /// /// Clips tensor values to a specified min and max. /// diff --git a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs index c3b30d8f..b526c1d8 100644 --- a/src/TensorFlowNET.Core/Operations/gen_math_ops.cs +++ b/src/TensorFlowNET.Core/Operations/gen_math_ops.cs @@ -364,6 +364,13 @@ namespace Tensorflow return _op.outputs[0]; } + public static Tensor logical_or(Tensor x, Tensor y, string name = null) + { + var _op = _op_def_lib._apply_op_helper("LogicalOr", name, args: new { x, y }); + + return _op.outputs[0]; + } + public static Tensor squared_difference(Tensor x, Tensor y, string name = null) { var _op = _op_def_lib._apply_op_helper("SquaredDifference", name, args: new { x, y, name }); diff --git a/test/TensorFlowNET.UnitTest/OperationsTest.cs b/test/TensorFlowNET.UnitTest/OperationsTest.cs index 68c44831..542505a3 100644 --- a/test/TensorFlowNET.UnitTest/OperationsTest.cs +++ b/test/TensorFlowNET.UnitTest/OperationsTest.cs @@ -153,6 +153,15 @@ namespace TensorFlowNET.UnitTest var o = sess.run(d); Assert.IsTrue(o.array_equal(check)); } + + d = tf.cast(tf.logical_or(b, c), tf.int32); + check = np.array(new[] { 1, 1, 1, 1, 1, 1, 1, 1 }); + + using (var sess = tf.Session()) + { + var o = sess.run(d); + Assert.IsTrue(o.array_equal(check)); + } } [TestMethod]