MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / test_scatter

Function test_scatter

imperative/python/test/unit/functional/test_tensor.py:309–328  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

307
308
309def 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])

Callers

nothing calls this directly

Calls 8

TensorClass · 0.90
scatterMethod · 0.80
assert_equalMethod · 0.80
arrayMethod · 0.80
zerosMethod · 0.45
roundMethod · 0.45
numpyMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected