@@ -814,6 +814,7 @@ def test_Sub_gpu(self):
814814 x1 .to_device (gpu_dev )
815815 dy .to_device (gpu_dev )
816816
817+
817818 result = autograd .sub (x0 , x1 )
818819 dx0 , dx1 = result .creator .backward (dy .data )
819820 DX0 = np .multiply (DY , 1.0 )
@@ -822,6 +823,56 @@ def test_Sub_gpu(self):
822823 np .testing .assert_array_almost_equal (tensor .to_numpy (result ), XT , decimal = 5 )
823824 np .testing .assert_array_almost_equal (tensor .to_numpy (tensor .from_raw_tensor (dx0 )), DX0 , decimal = 5 )
824825 np .testing .assert_array_almost_equal (tensor .to_numpy (tensor .from_raw_tensor (dx1 )), DX1 , decimal = 5 )
826+
827+ def test_Pow_cpu (self ):
828+ X0 = np .array ([7 , 5 , 0.2 , 0.1 , 0.3 , 4 ]).reshape (3 , 2 ).astype (np .float32 )
829+ X1 = np .array ([- 1.0 , 2.0 , - 1.0 , - 2.1 , 1.0 , - 2.0 ]).reshape (3 , 2 ).astype (np .float32 )
830+ XT = np .power (X0 , X1 )
831+
832+ DY = np .ones ((3 , 2 ), dtype = np .float32 )
833+ x0 = tensor .from_numpy (X0 )
834+ x1 = tensor .from_numpy (X1 )
835+ dy = tensor .from_numpy (DY )
836+ x0 .to_device (cpu_dev )
837+ x1 .to_device (cpu_dev )
838+ dy .to_device (cpu_dev )
839+
840+ result = autograd .pow (x0 , x1 )
841+ dx0 , dx1 = result .creator .backward (dy .data )
842+
843+ G0 = np .multiply (X1 , np .power (X0 , (X1 - 1.0 )) )
844+ DX0 = np .multiply (G0 , DY )
845+ G1 = np .multiply (np .power (X0 , X1 ), np .log (X0 ) )
846+ DX1 = np .multiply (G1 , DY )
847+
848+ np .testing .assert_array_almost_equal (tensor .to_numpy (result ), XT , decimal = 5 )
849+ np .testing .assert_array_almost_equal (tensor .to_numpy (tensor .from_raw_tensor (dx0 )), DX0 , decimal = 4 )
850+ np .testing .assert_array_almost_equal (tensor .to_numpy (tensor .from_raw_tensor (dx1 )), DX1 , decimal = 4 )
851+
852+ def test_Pow_gpu (self ):
853+ X0 = np .array ([7 , 5 , 0.2 , 0.1 , 0.3 , 4 ]).reshape (3 , 2 ).astype (np .float32 )
854+ X1 = np .array ([- 1.0 , 2.0 , - 1.0 , - 2.1 , 1.0 , - 2.0 ]).reshape (3 , 2 ).astype (np .float32 )
855+ XT = np .power (X0 , X1 )
856+
857+ DY = np .ones ((3 , 2 ), dtype = np .float32 )
858+ x0 = tensor .from_numpy (X0 )
859+ x1 = tensor .from_numpy (X1 )
860+ dy = tensor .from_numpy (DY )
861+ x0 .to_device (gpu_dev )
862+ x1 .to_device (gpu_dev )
863+ dy .to_device (gpu_dev )
864+
865+ result = autograd .pow (x0 , x1 )
866+ dx0 , dx1 = result .creator .backward (dy .data )
867+
868+ G0 = np .multiply (X1 , np .power (X0 , (X1 - 1.0 )) )
869+ DX0 = np .multiply (G0 , DY )
870+ G1 = np .multiply (np .power (X0 , X1 ), np .log (X0 ) )
871+ DX1 = np .multiply (G1 , DY )
872+
873+ np .testing .assert_array_almost_equal (tensor .to_numpy (result ), XT , decimal = 5 )
874+ np .testing .assert_array_almost_equal (tensor .to_numpy (tensor .from_raw_tensor (dx0 )), DX0 , decimal = 4 )
875+ np .testing .assert_array_almost_equal (tensor .to_numpy (tensor .from_raw_tensor (dx1 )), DX1 , decimal = 4 )
825876
826877 def test_SoftSign_cpu (self ):
827878 # y = x / (1 + np.abs(x))
0 commit comments