| 408 | |
| 409 | |
| 410 | def 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 | |
| 434 | def test_Broadcast(): |