@@ -22,56 +22,21 @@ namespace Tensorflow
2222{
2323 public partial class ResourceVariable
2424 {
25- public static Tensor operator + ( ResourceVariable x , int y ) => op_helper ( "add" , x , y ) ;
26- public static Tensor operator + ( ResourceVariable x , float y ) => op_helper ( "add" , x , y ) ;
27- public static Tensor operator + ( ResourceVariable x , double y ) => op_helper ( "add" , x , y ) ;
28- public static Tensor operator + ( ResourceVariable x , ResourceVariable y ) => op_helper ( "add" , x , y ) ;
29- public static Tensor operator - ( ResourceVariable x , int y ) => op_helper ( "sub" , x , y ) ;
30- public static Tensor operator - ( ResourceVariable x , float y ) => op_helper ( "sub" , x , y ) ;
31- public static Tensor operator - ( ResourceVariable x , double y ) => op_helper ( "sub" , x , y ) ;
32- public static Tensor operator - ( ResourceVariable x , Tensor y ) => op_helper ( "sub" , x , y ) ;
33- public static Tensor operator - ( ResourceVariable x , ResourceVariable y ) => op_helper ( "sub" , x , y ) ;
34-
35- public static Tensor operator * ( ResourceVariable x , ResourceVariable y ) => op_helper ( "mul" , x , y ) ;
36- public static Tensor operator * ( ResourceVariable x , NDArray y ) => op_helper ( "mul" , x , y ) ;
37-
38- public static Tensor operator < ( ResourceVariable x , Tensor y ) => op_helper ( "less" , x , y ) ;
39-
40- public static Tensor operator > ( ResourceVariable x , Tensor y ) => op_helper ( "greater" , x , y ) ;
41-
42- private static Tensor op_helper < T > ( string default_name , ResourceVariable x , T y )
43- => tf_with ( ops . name_scope ( null , default_name , new { x , y } ) , scope =>
44- {
45- string name = scope ;
46- var xVal = x . value ( ) ;
47- var yTensor = ops . convert_to_tensor ( y , xVal . dtype . as_base_dtype ( ) , "y" ) ;
48- Tensor result = null ;
49- switch ( default_name )
50- {
51- case "add" :
52- result = x . dtype == TF_DataType . TF_STRING ?
53- gen_math_ops . add ( xVal , yTensor , name ) :
54- gen_math_ops . add_v2 ( xVal , yTensor , name ) ;
55- break ;
56- case "sub" :
57- result = gen_math_ops . sub ( xVal , yTensor , name ) ;
58- break ;
59- case "mul" :
60- result = gen_math_ops . mul ( xVal , yTensor , name : name ) ;
61- break ;
62- case "less" :
63- result = gen_math_ops . less ( xVal , yTensor , name ) ;
64- break ;
65- case "greater" :
66- result = gen_math_ops . greater ( xVal , yTensor , name ) ;
67- break ;
68- default :
69- throw new NotImplementedException ( "" ) ;
70- }
71-
72- // x.assign(result);
73- // result.ResourceVar = x;
74- return result ;
75- } ) ;
25+ public static Tensor operator + ( ResourceVariable x , int y ) => x . value ( ) + y ;
26+ public static Tensor operator + ( ResourceVariable x , float y ) => x . value ( ) + y ;
27+ public static Tensor operator + ( ResourceVariable x , double y ) => x . value ( ) + y ;
28+ public static Tensor operator + ( ResourceVariable x , ResourceVariable y ) => x . value ( ) + y . value ( ) ;
29+ public static Tensor operator - ( ResourceVariable x , int y ) => x . value ( ) - y ;
30+ public static Tensor operator - ( ResourceVariable x , float y ) => x . value ( ) - y ;
31+ public static Tensor operator - ( ResourceVariable x , double y ) => x . value ( ) - y ;
32+ public static Tensor operator - ( ResourceVariable x , Tensor y ) => x . value ( ) - y ;
33+ public static Tensor operator - ( ResourceVariable x , ResourceVariable y ) => x . value ( ) - y . value ( ) ;
34+
35+ public static Tensor operator * ( ResourceVariable x , ResourceVariable y ) => x . value ( ) * y . value ( ) ;
36+ public static Tensor operator * ( ResourceVariable x , NDArray y ) => x . value ( ) * y ;
37+
38+ public static Tensor operator < ( ResourceVariable x , Tensor y ) => x . value ( ) < y ;
39+
40+ public static Tensor operator > ( ResourceVariable x , Tensor y ) => x . value ( ) > y ;
7641 }
7742}
0 commit comments