def _test_sin_backward(test_case, shape, device): x = flow.Tensor(np.random.randn(*shape), requires_grad=True, device=flow.device(device)) y = flow.sin(x) z = y.sum() z.backward() test_case.assertTrue( np.allclose(x.grad.numpy(), np.cos(x.numpy()), 1e-5, 1e-5))
def test_sin(test_case): input = flow.Tensor(np.random.randn(2, 6, 5, 3)) of_out = flow.sin(input) np_out = np.sin(input.numpy()) test_case.assertTrue(np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5))
def _test_sin(test_case, shape, device): input = flow.Tensor(np.random.randn(*shape), device=flow.device(device)) of_out = flow.sin(input) np_out = np.sin(input.numpy()) test_case.assertTrue(np.allclose(of_out.numpy(), np_out, 1e-5, 1e-5))