Skip to content

Commit 3ff5988

Browse files
acifonelliOceania2018
authored andcommitted
Adding logical_and operator (SciSharp#338)
Relative unit test in `OperationTest`.
1 parent ce7d5fe commit 3ff5988

3 files changed

Lines changed: 26 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
@@ -189,6 +189,9 @@ public static Tensor less_equal<Tx, Ty>(Tx x, Ty y, string name = null)
189189
public static Tensor log1p(Tensor x, string name = null)
190190
=> gen_math_ops.log1p(x, name);
191191

192+
public static Tensor logical_and(Tensor x, Tensor y, string name = null)
193+
=> gen_math_ops.logical_and(x, y, name);
194+
192195
/// <summary>
193196
/// Clips tensor values to a specified min and max.
194197
/// </summary>

src/TensorFlowNET.Core/Operations/gen_math_ops.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,13 @@ public static Tensor log1p(Tensor x, string name = null)
350350
return _op.outputs[0];
351351
}
352352

353+
public static Tensor logical_and(Tensor x, Tensor y, string name = null)
354+
{
355+
var _op = _op_def_lib._apply_op_helper("LogicalAnd", name, args: new { x, y });
356+
357+
return _op.outputs[0];
358+
}
359+
353360
public static Tensor squared_difference(Tensor x, Tensor y, string name = null)
354361
{
355362
var _op = _op_def_lib._apply_op_helper("SquaredDifference", name, args: new { x, y, name });

test/TensorFlowNET.UnitTest/OperationsTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ public void cumSumTest()
130130
}
131131
}
132132

133+
[TestMethod]
134+
public void logicalAndTest()
135+
{
136+
var a = tf.constant(new[] {1f, 2f, 3f, 4f, -4f, -3f, -2f, -1f});
137+
var b = tf.less(a, 0f);
138+
var c = tf.greater(a, 0f);
139+
var d = tf.cast(tf.logical_and(b, c), tf.int32);
140+
var check = np.array(new[] { 0, 0, 0, 0, 0, 0, 0, 0 });
141+
142+
using (var sess = tf.Session())
143+
{
144+
var o = sess.run(d);
145+
Assert.IsTrue(o.array_equal(check));
146+
}
147+
}
148+
133149
[TestMethod]
134150
public void addOpTests()
135151
{

0 commit comments

Comments
 (0)