Пример #1
0
def _test_sign_impl(test_case, shape, device):
    np_input = np.random.randn(*shape)
    of_input = flow.tensor(np_input,
                           dtype=flow.float32,
                           device=flow.device(device),
                           requires_grad=True)
    of_out = flow.sign(of_input)
    np_out = np.sign(np_input)
    test_case.assertTrue(np.allclose(of_out.numpy(), np_out, 0.0001, 0.0001))
    of_out = of_out.sum()
    of_out.backward()
    np_grad = np.zeros_like(np_input)
    test_case.assertTrue(
        np.allclose(of_input.grad.numpy(), np_grad, 0.0001, 0.0001))
Пример #2
0
def _sign(self):
    return flow.sign(self)
Пример #3
0
 def forward(self, x):
     return flow.sign(x)