示例#1
0
文件: test_sign.py 项目: zzk0/oneflow
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)