()
| 502 | |
| 503 | |
| 504 | def test_removeAxis(): |
| 505 | x_np = np.random.rand(3, 3, 1, 1).astype("float32") |
| 506 | x = mge.Tensor(x_np) |
| 507 | |
| 508 | with Grad() as grad: |
| 509 | grad.wrt(x, callback=save_to(x)) |
| 510 | refs = {} |
| 511 | |
| 512 | def f(x): |
| 513 | x = x * 1 |
| 514 | y = F.squeeze(x, [2, 3]) |
| 515 | refs["x"] = TensorWeakRef(x) |
| 516 | return y |
| 517 | |
| 518 | y = f(x) |
| 519 | for _, r in refs.items(): |
| 520 | assert r() is None |
| 521 | grad(y, F.ones_like(y)) |
| 522 | |
| 523 | np.testing.assert_equal(np.ones((3, 3, 1, 1), dtype=np.float32), x.grad.numpy()) |
| 524 | |
| 525 | |
| 526 | def test_dot(): |