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

Function test_addAxis

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

Source from the content-addressed store, hash-verified

480
481
482def test_addAxis():
483 x_np = np.random.rand(3, 3).astype("float32")
484 x = mge.Tensor(x_np)
485
486 with Grad() as grad:
487 grad.wrt(x, callback=save_to(x))
488 refs = {}
489
490 def f(x):
491 x = x * 1
492 y = F.expand_dims(x, [2, 3])
493 refs["x"] = TensorWeakRef(x)
494 return y
495
496 y = f(x)
497 for _, r in refs.items():
498 assert r() is None
499 grad(y, F.ones_like(y))
500
501 np.testing.assert_equal(np.ones((3, 3), dtype=np.float32), x.grad.numpy())
502
503
504def test_removeAxis():

Callers

nothing calls this directly

Calls 11

GradClass · 0.90
save_toFunction · 0.85
gradFunction · 0.85
wrtMethod · 0.80
itemsMethod · 0.80
assert_equalMethod · 0.80
onesMethod · 0.80
fFunction · 0.70
astypeMethod · 0.45
TensorMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected