MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / test_grad

Function test_grad

imperative/python/test/unit/core/test_autodiff.py:77–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

75
76
77def test_grad():
78 x_np = np.random.rand(10).astype("float32")
79 x = as_tensor(x_np)
80
81 with Grad() as grad:
82 grad.wrt(x, callback=save_to(x))
83 y = cos(x)
84 grad(y, as_tensor(np.ones_like(x_np)))
85
86 np.testing.assert_almost_equal(x.grad.numpy(), -np.sin(x_np))
87
88
89def test_grad_2():

Callers

nothing calls this directly

Calls 9

GradClass · 0.90
save_toFunction · 0.85
gradFunction · 0.85
wrtMethod · 0.80
as_tensorFunction · 0.70
cosFunction · 0.50
astypeMethod · 0.45
numpyMethod · 0.45
sinMethod · 0.45

Tested by

no test coverage detected