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

Function test_identity

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

Source from the content-addressed store, hash-verified

225
226
227def test_identity():
228 x_np = np.random.rand(10).astype("float32")
229 x = mge.Tensor(x_np)
230 dy_np = np.random.rand(*x.shape).astype("float32")
231 dy = mge.Tensor(dy_np)
232
233 with Grad() as grad:
234 grad.wrt(x, callback=save_to(x))
235 (y,) = apply(Identity(), x)
236 grad(y, dy)
237
238 np.testing.assert_array_equal(x.grad.numpy(), dy_np)
239
240
241def test_elemwise_add():

Callers

nothing calls this directly

Calls 9

GradClass · 0.90
save_toFunction · 0.85
gradFunction · 0.85
wrtMethod · 0.80
applyFunction · 0.50
IdentityClass · 0.50
astypeMethod · 0.45
TensorMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected