|
|
@@ -1,4 +1,5 @@ |
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
using System;
|
|
|
|
using Tensorflow;
|
|
|
|
|
|
|
|
namespace TensorFlowNET.UnitTest.control_flow_ops_test
|
|
|
@@ -18,25 +19,54 @@ namespace TensorFlowNET.UnitTest.control_flow_ops_test |
|
|
|
var x = tf.constant(2);
|
|
|
|
var y = tf.constant(5);
|
|
|
|
var z = control_flow_ops.cond(tf.less(x, y),
|
|
|
|
() => tf.multiply(x, tf.constant(17)),
|
|
|
|
() => tf.add(y, tf.constant(23)));
|
|
|
|
() => tf.multiply(x, 17),
|
|
|
|
() => tf.add(y, 23));
|
|
|
|
int result = z.eval(sess);
|
|
|
|
assertEquals(result, 34);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[Ignore("Todo")]
|
|
|
|
[TestMethod]
|
|
|
|
public void testCondFalse()
|
|
|
|
{
|
|
|
|
// def testCondFalse(self):
|
|
|
|
// x = constant_op.constant(2)
|
|
|
|
// y = constant_op.constant(1)
|
|
|
|
// z = control_flow_ops.cond(
|
|
|
|
// math_ops.less(
|
|
|
|
// x,
|
|
|
|
// y), lambda: math_ops.multiply(x, 17), lambda: math_ops.add(y, 23))
|
|
|
|
// self.assertEquals(self.evaluate(z), 24)
|
|
|
|
/* python
|
|
|
|
* import tensorflow as tf
|
|
|
|
from tensorflow.python.framework import ops
|
|
|
|
|
|
|
|
def if_true():
|
|
|
|
return tf.math.multiply(x, 17)
|
|
|
|
def if_false():
|
|
|
|
return tf.math.add(y, 23)
|
|
|
|
|
|
|
|
with tf.Session() as sess:
|
|
|
|
x = tf.constant(2)
|
|
|
|
y = tf.constant(1)
|
|
|
|
pred = tf.math.less(x,y)
|
|
|
|
z = tf.cond(pred, if_true, if_false)
|
|
|
|
result = z.eval()
|
|
|
|
|
|
|
|
print(result == 24) */
|
|
|
|
|
|
|
|
with(tf.Session(), sess =>
|
|
|
|
{
|
|
|
|
var x = tf.constant(2);
|
|
|
|
var y = tf.constant(1);
|
|
|
|
var pred = tf.less(x, y);
|
|
|
|
|
|
|
|
Func<ITensorOrOperation> if_true = delegate
|
|
|
|
{
|
|
|
|
return tf.multiply(x, 17);
|
|
|
|
};
|
|
|
|
|
|
|
|
Func<ITensorOrOperation> if_false = delegate
|
|
|
|
{
|
|
|
|
return tf.add(y, 23);
|
|
|
|
};
|
|
|
|
|
|
|
|
var z = control_flow_ops.cond(pred, if_true, if_false);
|
|
|
|
int result = z.eval(sess);
|
|
|
|
assertEquals(result, 24);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[Ignore("Todo")]
|
|
|
|