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

Function test_reshape

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

Source from the content-addressed store, hash-verified

298
299
300def test_reshape():
301 x_np = np.random.rand(2, 5).astype("float32")
302 x = mge.Tensor(x_np)
303
304 with Grad() as grad:
305 grad.wrt(x, callback=save_to(x))
306 refs = {}
307
308 def f(x):
309 x = x * 1
310 y = x.reshape(5, 2)
311 refs["x"] = TensorWeakRef(x)
312 return y
313
314 y = f(x)
315 for _, r in refs.items():
316 assert r() is None
317 grad(y, F.ones_like(y))
318
319 np.testing.assert_equal(np.ones((2, 5), dtype=np.float32), x.grad.numpy())
320
321
322def test_subtensor():

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