Exemple #1
0
def test_grad_net():
    x = np.array([1.0, 4.0, 9.0]).astype(np.float32)
    sens = np.array([1.0, 1.0, 1.0]).astype(np.float32)
    square = Net()
    dx = C.grad_with_sens(square)(Tensor(x), Tensor(sens))
    expect = np.array([2.0, 8.0, 18.0]).astype(np.float32)
    assert (dx.asnumpy() == expect).all()
Exemple #2
0
 def construct(self, *inputs):
     return C.grad_with_sens(self.net)(*inputs)