@@ -15,14 +15,15 @@ public Operation _apply_op_helper(string op_type_name, string name = "", Diction
1515 var g = ops . get_default_graph ( ) ;
1616 var op_def = g . GetOpDef ( op_type_name ) ;
1717
18+ // Default name if not specified.
1819 if ( String . IsNullOrEmpty ( name ) )
19- {
2020 name = op_type_name ;
21- }
2221
23- string scope = "" ;
24- using ( var namescope = new ops . name_scope < object > ( name ) )
25- scope = namescope ;
22+ // Check for deprecation
23+ if ( op_def . Deprecation != null && op_def . Deprecation . Version > 0 )
24+ {
25+
26+ }
2627
2728 var default_type_attr_map = new Dictionary < string , object > ( ) ;
2829 foreach ( var attr_def in op_def . Attr )
@@ -39,101 +40,107 @@ public Operation _apply_op_helper(string op_type_name, string name = "", Diction
3940 var inputs = new List < Tensor > ( ) ;
4041 var input_types = new List < TF_DataType > ( ) ;
4142
42- // Perform input type inference
43- foreach ( var input_arg in op_def . InputArg )
43+ string scope = "" ;
44+ using ( var namescope = new ops . name_scope < object > ( name ) )
4445 {
45- var input_name = input_arg . Name ;
46- if ( keywords [ input_name ] is double int_value )
47- {
48- keywords [ input_name ] = constant_op . Constant ( int_value , input_name ) ;
49- }
46+ scope = namescope ;
5047
51- if ( keywords [ input_name ] is Tensor value )
48+ // Perform input type inference
49+ foreach ( var input_arg in op_def . InputArg )
5250 {
53- if ( keywords . ContainsKey ( input_name ) )
51+ var input_name = input_arg . Name ;
52+ if ( keywords [ input_name ] is double int_value )
5453 {
55- inputs . Add ( value ) ;
54+ keywords [ input_name ] = constant_op . Constant ( int_value , input_name ) ;
5655 }
5756
58- if ( ! String . IsNullOrEmpty ( input_arg . TypeAttr ) )
57+ if ( keywords [ input_name ] is Tensor value )
5958 {
60- attrs [ input_arg . TypeAttr ] = value . dtype ;
59+ if ( keywords . ContainsKey ( input_name ) )
60+ {
61+ inputs . Add ( value ) ;
62+ }
63+
64+ if ( ! String . IsNullOrEmpty ( input_arg . TypeAttr ) )
65+ {
66+ attrs [ input_arg . TypeAttr ] = value . dtype ;
67+ }
68+
69+ if ( input_arg . IsRef )
70+ {
71+
72+ }
73+ else
74+ {
75+ input_types . Add ( value . dtype ) ;
76+ }
6177 }
78+ }
6279
63- if ( input_arg . IsRef )
64- {
65-
66- }
67- else
80+ // Process remaining attrs
81+ foreach ( var attr in op_def . Attr )
82+ {
83+ if ( keywords . ContainsKey ( attr . Name ) )
6884 {
69- input_types . Add ( value . dtype ) ;
85+ attrs [ attr . Name ] = keywords [ attr . Name ] ;
7086 }
7187 }
72- }
7388
74- // Process remaining attrs
75- foreach ( var attr in op_def . Attr )
76- {
77- if ( keywords . ContainsKey ( attr . Name ) )
89+ // Convert attr values to AttrValue protos.
90+ var attr_protos = new Dictionary < string , AttrValue > ( ) ;
91+ foreach ( var attr_def in op_def . Attr )
7892 {
79- attrs [ attr . Name ] = keywords [ attr . Name ] ;
80- }
81- }
93+ var key = attr_def . Name ;
94+ var value = attrs [ key ] ;
95+ var attr_value = new AttrValue ( ) ;
8296
83- // Convert attr values to AttrValue protos.
84- var attr_protos = new Dictionary < string , AttrValue > ( ) ;
85- foreach ( var attr_def in op_def . Attr )
86- {
87- var key = attr_def . Name ;
88- var value = attrs [ key ] ;
89- var attr_value = new AttrValue ( ) ;
90-
91- switch ( attr_def . Type )
92- {
93- case "string" :
94- attr_value . S = Google . Protobuf . ByteString . CopyFromUtf8 ( ( string ) value ) ;
95- break ;
96- case "type" :
97- attr_value . Type = _MakeType ( ( TF_DataType ) value , attr_def ) ;
98- break ;
99- case "bool" :
100- attr_value . B = ( bool ) value ;
101- break ;
102- case "shape" :
103- attr_value . Shape = value == null ?
104- attr_def . DefaultValue . Shape :
105- tensor_util . as_shape ( ( long [ ] ) value ) ;
106- break ;
107- default :
108- throw new InvalidDataException ( $ "attr_def.Type { attr_def . Type } ") ;
109- }
97+ switch ( attr_def . Type )
98+ {
99+ case "string" :
100+ attr_value . S = Google . Protobuf . ByteString . CopyFromUtf8 ( ( string ) value ) ;
101+ break ;
102+ case "type" :
103+ attr_value . Type = _MakeType ( ( TF_DataType ) value , attr_def ) ;
104+ break ;
105+ case "bool" :
106+ attr_value . B = ( bool ) value ;
107+ break ;
108+ case "shape" :
109+ attr_value . Shape = value == null ?
110+ attr_def . DefaultValue . Shape :
111+ tensor_util . as_shape ( ( long [ ] ) value ) ;
112+ break ;
113+ default :
114+ throw new InvalidDataException ( $ "attr_def.Type { attr_def . Type } ") ;
115+ }
110116
111- attr_protos [ key ] = attr_value ;
112- }
117+ attr_protos [ key ] = attr_value ;
118+ }
113119
114- // Determine output types (possibly using attrs)
115- var output_types = new List < TF_DataType > ( ) ;
120+ // Determine output types (possibly using attrs)
121+ var output_types = new List < TF_DataType > ( ) ;
116122
117- foreach ( var arg in op_def . OutputArg )
118- {
119- if ( ! String . IsNullOrEmpty ( arg . NumberAttr ) )
123+ foreach ( var arg in op_def . OutputArg )
120124 {
125+ if ( ! String . IsNullOrEmpty ( arg . NumberAttr ) )
126+ {
121127
128+ }
129+ else if ( ! String . IsNullOrEmpty ( arg . TypeAttr ) )
130+ {
131+ output_types . Add ( ( TF_DataType ) attr_protos [ arg . TypeAttr ] . Type ) ;
132+ }
122133 }
123- else if ( ! String . IsNullOrEmpty ( arg . TypeAttr ) )
124- {
125- output_types . Add ( ( TF_DataType ) attr_protos [ arg . TypeAttr ] . Type ) ;
126- }
127- }
128134
129- // Add Op to graph
130- var op = g . create_op ( op_type_name , inputs , output_types . ToArray ( ) ,
131- name : scope ,
132- input_types : input_types . ToArray ( ) ,
133- attrs : attr_protos ,
134- op_def : op_def ) ;
135+ // Add Op to graph
136+ var op = g . create_op ( op_type_name , inputs , output_types . ToArray ( ) ,
137+ name : scope ,
138+ input_types : input_types . ToArray ( ) ,
139+ attrs : attr_protos ,
140+ op_def : op_def ) ;
135141
136- return op ;
142+ return op ;
143+ }
137144 }
138145
139146 public DataType _MakeType ( TF_DataType v , AttrDef attr_def )
0 commit comments