@@ -985,22 +985,39 @@ def run(place, x_shape, y_shape):
985985 input_x_np = np .random .random (x_shape ).astype (self .dtype )
986986 input_y_np = np .random .random (y_shape ).astype (self .dtype )
987987
988- tensor_input_x = paddle .to_tensor (input_x_np )
989- tensor_input_y = paddle .to_tensor (input_y_np )
988+ tensor_input_x = paddle .to_tensor (
989+ input_x_np , stop_gradient = False
990+ )
991+ tensor_input_y = paddle .to_tensor (
992+ input_y_np , stop_gradient = False
993+ )
990994
991995 numpy_output = np .linalg .solve (input_x_np , input_y_np )
992996 paddle_output = paddle .linalg .solve (
993- tensor_input_x , tensor_input_y , left = False
997+ tensor_input_x , tensor_input_y , left = True
994998 )
995999 np .testing .assert_allclose (
9961000 numpy_output , paddle_output .numpy (), rtol = 0.0001
9971001 )
9981002 self .assertEqual (
9991003 numpy_output .shape , paddle_output .numpy ().shape
10001004 )
1005+ loss = paddle .sum (paddle_output )
1006+ loss .backward ()
1007+ np .testing .assert_allclose (
1008+ tensor_input_x .grad .shape , tensor_input_x .shape
1009+ )
1010+ np .testing .assert_allclose (
1011+ tensor_input_y .grad .shape , tensor_input_y .shape
1012+ )
10011013
10021014 for place in self .place :
1015+ run (place , x_shape = [1 , 10 , 10 ], y_shape = [1 , 10 , 10 ])
1016+ run (place , x_shape = [0 , 10 , 10 ], y_shape = [0 , 10 , 10 ])
1017+ run (place , x_shape = [0 , 10 , 10 ], y_shape = [1 , 10 , 10 ])
10031018 run (place , x_shape = [10 , 0 , 0 ], y_shape = [10 , 0 , 0 ])
1019+ run (place , x_shape = [10 , 1 , 1 ], y_shape = [10 , 1 , 0 ])
1020+
10041021 with self .assertRaises (ValueError ) as context :
10051022 run (place , x_shape = [10 , 0 , 0 ], y_shape = [10 ])
10061023
0 commit comments