Skip to content

Commit 924e159

Browse files
acifonelliOceania2018
authored andcommitted
Adding logical_xor operator (SciSharp#346)
Relative unit test in `OperationTest`.
1 parent 03c1637 commit 924e159

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎src/TensorFlowNET.Core/APIs/tf.math.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ public static Tensor logical_not(Tensor x, string name = null)
198198
public static Tensor logical_or(Tensor x, Tensor y, string name = null)
199199
=> gen_math_ops.logical_or(x, y, name);
200200

201+
public static Tensor logical_xor(Tensor x, Tensor y, string name = "LogicalXor")
202+
=> gen_math_ops.logical_xor(x, y, name);
203+
201204
/// <summary>
202205
/// Clips tensor values to a specified min and max.
203206
/// </summary>

‎src/TensorFlowNET.Core/Operations/gen_math_ops.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,14 @@ public static Tensor logical_or(Tensor x, Tensor y, string name = null)
371371
return _op.outputs[0];
372372
}
373373

374+
public static Tensor logical_xor(Tensor x, Tensor y, string name = "LogicalXor")
375+
{
376+
return logical_and(
377+
logical_or(x, y),
378+
logical_not(logical_and(x, y)),
379+
name);
380+
}
381+
374382
public static Tensor squared_difference(Tensor x, Tensor y, string name = null)
375383
{
376384
var _op = _op_def_lib._apply_op_helper("SquaredDifference", name, args: new { x, y, name });

‎test/TensorFlowNET.UnitTest/OperationsTest.cs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ public void logicalOpsTest()
162162
var o = sess.run(d);
163163
Assert.IsTrue(o.array_equal(check));
164164
}
165+
166+
d = tf.cast(tf.logical_xor(b, c), tf.int32);
167+
check = np.array(new[] { 1, 1, 1, 1, 1, 1, 1, 1 });
168+
169+
using (var sess = tf.Session())
170+
{
171+
var o = sess.run(d);
172+
Assert.IsTrue(o.array_equal(check));
173+
}
165174
}
166175

167176
[TestMethod]

0 commit comments

Comments
 (0)