()
| 225 | |
| 226 | |
| 227 | def test_identity(): |
| 228 | x_np = np.random.rand(10).astype("float32") |
| 229 | x = mge.Tensor(x_np) |
| 230 | dy_np = np.random.rand(*x.shape).astype("float32") |
| 231 | dy = mge.Tensor(dy_np) |
| 232 | |
| 233 | with Grad() as grad: |
| 234 | grad.wrt(x, callback=save_to(x)) |
| 235 | (y,) = apply(Identity(), x) |
| 236 | grad(y, dy) |
| 237 | |
| 238 | np.testing.assert_array_equal(x.grad.numpy(), dy_np) |
| 239 | |
| 240 | |
| 241 | def test_elemwise_add(): |