()
| 75 | |
| 76 | |
| 77 | def test_grad(): |
| 78 | x_np = np.random.rand(10).astype("float32") |
| 79 | x = as_tensor(x_np) |
| 80 | |
| 81 | with Grad() as grad: |
| 82 | grad.wrt(x, callback=save_to(x)) |
| 83 | y = cos(x) |
| 84 | grad(y, as_tensor(np.ones_like(x_np))) |
| 85 | |
| 86 | np.testing.assert_almost_equal(x.grad.numpy(), -np.sin(x_np)) |
| 87 | |
| 88 | |
| 89 | def test_grad_2(): |