()
| 298 | |
| 299 | |
| 300 | def 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 | |
| 322 | def test_subtensor(): |