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

Function test_AxisAddRemove

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

Source from the content-addressed store, hash-verified

408
409
410def test_AxisAddRemove():
411 x_np = np.random.rand(1, 5).astype("float32")
412 x = mge.Tensor(x_np)
413
414 with Grad() as grad:
415 grad.wrt(x, callback=save_to(x))
416 refs = {}
417
418 def f(x):
419 x = x * 1
420 y = F.squeeze(F.expand_dims(x, 2), 0)
421 refs["x"] = TensorWeakRef(x)
422 return y
423
424 y = f(x)
425 for _, r in refs.items():
426 assert r() is None
427 grad(y, F.ones_like(y))
428
429 np.testing.assert_equal(
430 np.array([[1, 1, 1, 1, 1]], dtype=np.float32), x.grad.numpy()
431 )
432
433
434def test_Broadcast():

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
arrayMethod · 0.80
fFunction · 0.70
astypeMethod · 0.45
TensorMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected