()
| 524 | |
| 525 | |
| 526 | def test_dot(): |
| 527 | x = np.random.rand(2, 2).astype("float32") |
| 528 | x = mge.Tensor(x) |
| 529 | u = F.ones((2,)) |
| 530 | v = F.ones((2,)) |
| 531 | |
| 532 | with Grad() as grad: |
| 533 | grad.wrt(x, callback=save_to(x)) |
| 534 | |
| 535 | def f(x): |
| 536 | return F.dot(u, F.matmul(x, v)) |
| 537 | |
| 538 | y = f(x) |
| 539 | grad(y, F.ones_like(y)) |
| 540 | |
| 541 | np.testing.assert_equal(np.ones((2, 2), dtype=np.float32), x.grad.numpy()) |
| 542 | |
| 543 | |
| 544 | def test_pixel_shuffle(): |