Exemplo n.º 1
0
def _test_atan2_forward(test_case, shape, scalar, device):
    np_input_x = 10 * np.random.rand(*shape)
    np_input_y = 10 * np.random.randn(*shape)
    of_input_x = flow.Tensor(np_input_x,
                             dtype=flow.float32,
                             device=flow.device(device))
    of_input_y = flow.Tensor(np_input_y,
                             dtype=flow.float32,
                             device=flow.device(device))
    of_out = flow.atan2(of_input_x, of_input_y)
    np_out = np.arctan2(np_input_x, np_input_y)
    test_case.assertTrue(np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5))
Exemplo n.º 2
0
 def test_y_grad():
     of_input_x = flow.Tensor(np_input_x,
                              dtype=flow.float32,
                              device=flow.device(device))
     of_input_y = flow.Tensor(
         np_input_y,
         dtype=flow.float32,
         device=flow.device(device),
         requires_grad=True,
     )
     of_out = flow.atan2(of_input_x, of_input_y)
     of_out_sum = of_out.sum()
     of_out_sum.backward()
     test_case.assertTrue(
         np.allclose(of_input_y.grad.numpy(), np_y_grad, 1e-4, 1e-4))