@@ -8,7 +8,7 @@ namespace Tensorflow.Operations
88 /// <summary>
99 /// The context for the conditional construct.
1010 /// </summary>
11- public class CondContext : ControlFlowContext
11+ public class CondContext : ControlFlowContext , IProtoBuf < CondContextDef , CondContext >
1212 {
1313
1414
@@ -35,16 +35,20 @@ public class CondContext : ControlFlowContext
3535 /// <param name="name">Name of the `CondContext` python object.</param>
3636 /// <param name="context_def"></param>
3737 /// <param name="import_scope"></param>
38- public CondContext ( Tensor pred ,
39- Tensor pivot ,
40- int branch ,
38+ public CondContext ( Tensor pred = null ,
39+ Tensor pivot = null ,
40+ int ? branch = null ,
4141 string name = "cond_text" ,
42- object context_def = null ,
42+ CondContextDef context_def = null ,
4343 string import_scope = null )
4444 {
45+ if ( pred == null && context_def == null ) return ;
46+
4547 _name = ops . get_default_graph ( ) . unique_name ( name ) ;
46- if ( context_def != null )
47- throw new NotImplementedException ( "CondContext context_def is not null" ) ;
48+ if ( context_def != null )
49+ {
50+ _init_from_proto ( context_def , import_scope : import_scope ) ;
51+ }
4852 else
4953 {
5054 // Initializes the default fields.
@@ -61,6 +65,18 @@ public CondContext(Tensor pred,
6165 }
6266 }
6367
68+ private void _init_from_proto ( CondContextDef context_def , string import_scope = null )
69+ {
70+ var g = ops . get_default_graph ( ) ;
71+ _name = ops . prepend_name_scope ( context_def . ContextName , import_scope ) ;
72+ var p1 = ops . prepend_name_scope ( context_def . PredName , import_scope ) ;
73+ _pred = g . as_graph_element ( p1 ) as Tensor ;
74+ var p2 = ops . prepend_name_scope ( context_def . PivotName , import_scope ) ;
75+ _pivot = g . as_graph_element ( p2 ) as Tensor ;
76+ _branch = context_def . Branch ;
77+ __init__ ( values_def : context_def . ValuesDef , import_scope : import_scope ) ;
78+ }
79+
6480 /// <summary>
6581 /// Add `val` to the current context and its outer context recursively.
6682 /// </summary>
@@ -230,6 +246,22 @@ private Tensor _ProcessOutputTensor(Tensor val)
230246 public override void AddInnerOp ( Operation resultOp )
231247 {
232248 throw new NotImplementedException ( ) ;
233- }
249+ }
250+
251+ public CondContextDef to_proto ( string export_scope )
252+ {
253+ throw new NotImplementedException ( ) ;
254+ }
255+
256+ public CondContext from_proto ( CondContextDef proto , string import_scope )
257+ {
258+ var ret = new CondContext ( context_def : proto , import_scope : import_scope ) ;
259+
260+ ret . Enter ( ) ;
261+ foreach ( var nested_def in proto . NestedContexts )
262+ throw new NotImplementedException ( "" ) ;
263+ ret . Exit ( ) ;
264+ return ret ;
265+ }
234266 }
235267}
0 commit comments