@@ -21,6 +21,10 @@ limitations under the License.
2121
2222namespace Tensorflow . Operations
2323{
24+ /// <summary>
25+ /// Operations for bitwise manipulation of integers.
26+ /// https://www.tensorflow.org/api_docs/python/tf/bitwise
27+ /// </summary>
2428 public class bitwise_ops
2529 {
2630 /// <summary>
@@ -31,20 +35,107 @@ public class bitwise_ops
3135 /// <param name="y"></param>
3236 /// <param name="name"></param>
3337 /// <returns></returns>
34- public Tensor left_shift ( Tensor x , Tensor y , string name = null )
38+ public Tensor left_shift ( Tensor x , Tensor y , string name = null ) => binary_op ( x , y , "LeftShift" , name ) ;
39+
40+ /// <summary>
41+ /// Elementwise computes the bitwise right-shift of `x` and `y`.
42+ /// https://www.tensorflow.org/api_docs/python/tf/bitwise/right_shift
43+ /// </summary>
44+ /// <param name="x"></param>
45+ /// <param name="y"></param>
46+ /// <param name="name"></param>
47+ /// <returns></returns>
48+ public Tensor right_shift ( Tensor x , Tensor y , string name = null ) => binary_op ( x , y , "RightShift" , name ) ;
49+
50+ /// <summary>
51+ /// Elementwise computes the bitwise inversion of `x`.
52+ /// https://www.tensorflow.org/api_docs/python/tf/bitwise/invert
53+ /// </summary>
54+ /// <param name="x"></param>
55+ /// <param name="name"></param>
56+ /// <returns></returns>
57+ public Tensor invert ( Tensor x , string name = null ) => unary_op ( x , "Invert" , name ) ;
58+
59+ /// <summary>
60+ /// Elementwise computes the bitwise AND of `x` and `y`.
61+ /// https://www.tensorflow.org/api_docs/python/tf/bitwise/bitwise_and
62+ /// </summary>
63+ /// <param name="x"></param>
64+ /// <param name="y"></param>
65+ /// <param name="name"></param>
66+ /// <returns></returns>
67+ public Tensor bitwise_and ( Tensor x , Tensor y , string name = null ) => binary_op ( x , y , "BitwiseAnd" , name ) ;
68+
69+ /// <summary>
70+ /// Elementwise computes the bitwise OR of `x` and `y`.
71+ /// https://www.tensorflow.org/api_docs/python/tf/bitwise/bitwise_or
72+ /// </summary>
73+ /// <param name="x"></param>
74+ /// <param name="y"></param>
75+ /// <param name="name"></param>
76+ /// <returns></returns>
77+ public Tensor bitwise_or ( Tensor x , Tensor y , string name = null ) => binary_op ( x , y , "BitwiseOr" , name ) ;
78+
79+ /// <summary>
80+ /// Elementwise computes the bitwise XOR of `x` and `y`.
81+ /// https://www.tensorflow.org/api_docs/python/tf/bitwise/bitwise_xor
82+ /// </summary>
83+ /// <param name="x"></param>
84+ /// <param name="y"></param>
85+ /// <param name="name"></param>
86+ /// <returns></returns>
87+ public Tensor bitwise_xor ( Tensor x , Tensor y , string name = null ) => binary_op ( x , y , "BitwiseXor" , name ) ;
88+
89+
90+ #region Private helper methods
91+
92+ /// <summary>
93+ /// Helper method to invoke unary operator with specified name.
94+ /// </summary>
95+ /// <param name="x"></param>
96+ /// <param name="opName"></param>
97+ /// <param name="name"></param>
98+ /// <returns></returns>
99+ Tensor unary_op ( Tensor x , string opName , string name )
100+ {
101+ if ( tf . Context . executing_eagerly ( ) )
102+ {
103+ var results = tf . Runner . TFE_FastPathExecute ( tf . Context , tf . Context . DeviceName ,
104+ opName , name ,
105+ null ,
106+ x ) ;
107+
108+ return results [ 0 ] ;
109+ }
110+
111+ var _op = tf . OpDefLib . _apply_op_helper ( opName , name , args : new { x } ) ;
112+ return _op . output ;
113+ }
114+
115+ /// <summary>
116+ /// Helper method to invoke binary operator with specified name.
117+ /// </summary>
118+ /// <param name="x"></param>
119+ /// <param name="y"></param>
120+ /// <param name="opName"></param>
121+ /// <param name="name"></param>
122+ /// <returns></returns>
123+ Tensor binary_op ( Tensor x , Tensor y , string opName , string name )
35124 {
36125 if ( tf . Context . executing_eagerly ( ) )
37126 {
38127 var results = tf . Runner . TFE_FastPathExecute ( tf . Context , tf . Context . DeviceName ,
39- "LeftShift" , name ,
128+ opName , name ,
40129 null ,
41130 x , y ) ;
42131
43132 return results [ 0 ] ;
44133 }
45134
46- var _op = tf . OpDefLib . _apply_op_helper ( "LeftShift" , name , args : new { x , y } ) ;
135+ var _op = tf . OpDefLib . _apply_op_helper ( opName , name , args : new { x , y } ) ;
47136 return _op . output ;
48137 }
138+
139+ #endregion
49140 }
50141}
0 commit comments