| 307 | |
| 308 | |
| 309 | def test_scatter(): |
| 310 | x = Tensor(np.zeros(shape=(3, 5), dtype=np.float32)) |
| 311 | source = Tensor( |
| 312 | [ |
| 313 | [0.9935, 0.9465, 0.2256, 0.8926, 0.4396], |
| 314 | [0.7723, 0.0718, 0.5939, 0.357, 0.4576], |
| 315 | ] |
| 316 | ) |
| 317 | index = Tensor([[0, 2, 0, 2, 1], [2, 0, 1, 1, 2]]) |
| 318 | y = F.scatter(x, -2, index, source) |
| 319 | np.testing.assert_equal( |
| 320 | y.numpy().round(decimals=4), |
| 321 | np.array( |
| 322 | [ |
| 323 | [0.9935, 0.0718, 0.2256, 0.0, 0.0], |
| 324 | [0.0, 0.0, 0.5939, 0.357, 0.4396], |
| 325 | [0.7723, 0.9465, 0.0, 0.8926, 0.4576], |
| 326 | ] |
| 327 | ).astype(np.float32), |
| 328 | ) |
| 329 | |
| 330 | |
| 331 | @pytest.mark.parametrize("is_varnode", [True, False]) |