@@ -24,24 +24,24 @@ public partial class ResourceVariable
2424 {
2525 public static OpDefLibrary _op_def_lib = new OpDefLibrary ( ) ;
2626
27- public static ResourceVariable operator + ( ResourceVariable x , int y ) => op_helper ( "add" , x , y ) ;
28- public static ResourceVariable operator + ( ResourceVariable x , float y ) => op_helper ( "add" , x , y ) ;
29- public static ResourceVariable operator + ( ResourceVariable x , double y ) => op_helper ( "add" , x , y ) ;
30- public static ResourceVariable operator + ( ResourceVariable x , ResourceVariable y ) => op_helper ( "add" , x , y ) ;
31- public static ResourceVariable operator - ( ResourceVariable x , int y ) => op_helper ( "sub" , x , y ) ;
32- public static ResourceVariable operator - ( ResourceVariable x , float y ) => op_helper ( "sub" , x , y ) ;
33- public static ResourceVariable operator - ( ResourceVariable x , double y ) => op_helper ( "sub" , x , y ) ;
34- public static ResourceVariable operator - ( ResourceVariable x , Tensor y ) => op_helper ( "sub" , x , y ) ;
35- public static ResourceVariable operator - ( ResourceVariable x , ResourceVariable y ) => op_helper ( "sub" , x , y ) ;
27+ public static Tensor operator + ( ResourceVariable x , int y ) => op_helper ( "add" , x , y ) ;
28+ public static Tensor operator + ( ResourceVariable x , float y ) => op_helper ( "add" , x , y ) ;
29+ public static Tensor operator + ( ResourceVariable x , double y ) => op_helper ( "add" , x , y ) ;
30+ public static Tensor operator + ( ResourceVariable x , ResourceVariable y ) => op_helper ( "add" , x , y ) ;
31+ public static Tensor operator - ( ResourceVariable x , int y ) => op_helper ( "sub" , x , y ) ;
32+ public static Tensor operator - ( ResourceVariable x , float y ) => op_helper ( "sub" , x , y ) ;
33+ public static Tensor operator - ( ResourceVariable x , double y ) => op_helper ( "sub" , x , y ) ;
34+ public static Tensor operator - ( ResourceVariable x , Tensor y ) => op_helper ( "sub" , x , y ) ;
35+ public static Tensor operator - ( ResourceVariable x , ResourceVariable y ) => op_helper ( "sub" , x , y ) ;
3636
37- public static ResourceVariable operator * ( ResourceVariable x , ResourceVariable y ) => op_helper ( "mul" , x , y ) ;
38- public static ResourceVariable operator * ( ResourceVariable x , NDArray y ) => op_helper ( "mul" , x , y ) ;
37+ public static Tensor operator * ( ResourceVariable x , ResourceVariable y ) => op_helper ( "mul" , x , y ) ;
38+ public static Tensor operator * ( ResourceVariable x , NDArray y ) => op_helper ( "mul" , x , y ) ;
3939
40- public static ResourceVariable operator < ( ResourceVariable x , Tensor y ) => less ( x . value ( ) , y ) ;
40+ public static Tensor operator < ( ResourceVariable x , Tensor y ) => op_helper ( "less" , x , y ) ;
4141
42- public static ResourceVariable operator > ( ResourceVariable x , Tensor y ) => greater ( x . value ( ) , y ) ;
42+ public static Tensor operator > ( ResourceVariable x , Tensor y ) => op_helper ( "greater" , x , y ) ;
4343
44- private static ResourceVariable op_helper < T > ( string default_name , ResourceVariable x , T y )
44+ private static Tensor op_helper < T > ( string default_name , ResourceVariable x , T y )
4545 => tf_with ( ops . name_scope ( null , default_name , new { x , y } ) , scope =>
4646 {
4747 string name = scope ;
@@ -61,39 +61,19 @@ private static ResourceVariable op_helper<T>(string default_name, ResourceVariab
6161 case "mul" :
6262 result = gen_math_ops . mul ( xVal , yTensor , name : name ) ;
6363 break ;
64+ case "less" :
65+ result = gen_math_ops . less ( xVal , yTensor , name ) ;
66+ break ;
67+ case "greater" :
68+ result = gen_math_ops . greater ( xVal , yTensor , name ) ;
69+ break ;
6470 default :
6571 throw new NotImplementedException ( "" ) ;
6672 }
6773
6874 // x.assign(result);
6975 // result.ResourceVar = x;
70- return tf . Variable ( result ) ;
76+ return result ;
7177 } ) ;
72-
73- private static ResourceVariable less < Tx , Ty > ( Tx x , Ty y , string name = null )
74- {
75- if ( tf . context . executing_eagerly ( ) )
76- {
77- var results = EagerTensorPass . Create ( ) ;
78- var inputs = EagerTensorPass . From ( x , y ) ;
79- Status status = c_api . TFE_FastPathExecute ( tf . context , tf . context . device_name ,
80- "Less" , name ,
81- inputs . Points , inputs . Length ,
82- null , null ,
83- results . Points , results . Length ) ;
84- status . Check ( true ) ;
85- return tf . Variable ( results [ 0 ] . Resolve ( ) ) ;
86- }
87-
88- var _op = _op_def_lib . _apply_op_helper ( "Less" , name : name , args : new { x , y } ) ;
89-
90- return tf . Variable ( _op . outputs [ 0 ] ) ;
91- }
92- private static ResourceVariable greater < Tx , Ty > ( Tx x , Ty y , string name = null )
93- {
94- var _op = _op_def_lib . _apply_op_helper ( "Greater" , name : name , args : new { x , y } ) ;
95-
96- return tf . Variable ( _op . outputs [ 0 ] ) ;
97- }
9878 }
9979}
0 commit comments