1- using Microsoft . VisualStudio . TestTools . UnitTesting ;
1+ using System ;
2+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
23using Tensorflow ;
34
45namespace TensorFlowNET . UnitTest . control_flow_ops_test
@@ -14,24 +15,33 @@ public class SwitchTestCase : PythonTest
1415 [ TestMethod ]
1516 public void testResourceReadInLoop ( )
1617 {
17- //def testResourceReadInLoop(self):
18- // embedding_matrix = variable_scope.get_variable(
19- // "embedding_matrix", initializer=[[2.0], [3.0]], use_resource=True)
20- //
21- // def cond(it, _):
22- // return it < 5
23- //
24- // def body(it, cost):
25- // embedding = embedding_ops.embedding_lookup(embedding_matrix, [0])
26- // cost += math_ops.reduce_sum(embedding)
27- // return it + 1, cost
28- //
29- // _, cost = control_flow_ops.while_loop(
30- // cond, body, [constant_op.constant(0),
31- // constant_op.constant(0.0)])
32- // with self.cached_session():
33- // self.evaluate(variables.global_variables_initializer())
34- // self.assertAllEqual(10.0, self.evaluate(cost))
18+
19+ var embedding_matrix = variable_scope . get_variable (
20+ "embedding_matrix" , initializer : new double [ , ] { { 2.0 } , { 3.0 } } , use_resource : true ) ;
21+
22+ Tensor cond ( Tensor it , Tensor _ )
23+ {
24+ return it < 5 ;
25+ }
26+
27+ // TODO: below code doesn't compile
28+ //(Tensor, Tensor) body(Tensor it, Tensor cost)
29+ //{
30+ // var embedding = embedding_ops.embedding_lookup(embedding_matrix, new int[]{0});
31+ // cost += math_ops.reduce_sum(embedding);
32+ // return (it + 1, cost);
33+ //}
34+ //var (_, cost1) = control_flow_ops.while_loop(
35+ // cond, body, new[]
36+ // {
37+ // constant_op.constant(0),
38+ // constant_op.constant(0.0)
39+ // });
40+ //with<Session>(this.cached_session(), sess =>
41+ //{
42+ // self.evaluate(variables.global_variables_initializer());
43+ // self.assertAllEqual(10.0, self.evaluate(cost1));
44+ //});
3545 }
3646
3747
@@ -49,7 +59,7 @@ public void testIndexedSlicesGradientInCondInWhileLoopResource()
4959 doTestIndexedSlicesGradientInCondInWhileLoop ( use_resource : true ) ;
5060 }
5161
52- private void doTestIndexedSlicesGradientInCondInWhileLoop ( bool use_resource = false )
62+ private void doTestIndexedSlicesGradientInCondInWhileLoop ( bool use_resource = false )
5363 {
5464 //def doTestIndexedSlicesGradientInCondInWhileLoop(self, use_resource=False):
5565 // embedding_matrix = variable_scope.get_variable(
0 commit comments