|
|
|
@ -75,7 +75,19 @@ def test_scatter_update_float16():
|
|
|
|
|
updates = Tensor(np.arange(6).reshape((2, 3)).astype(np.float16))
|
|
|
|
|
output = scatter_update_net(inputx, indices, updates)
|
|
|
|
|
expected = np.array([[0., 1., 2.],
|
|
|
|
|
[3., 4., 5.]])
|
|
|
|
|
[3., 4., 5.]]).astype(np.float16)
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
|
def test_scatter_update_int32():
|
|
|
|
|
inputx = Tensor(np.zeros((2, 3)).astype(np.int32))
|
|
|
|
|
indices = Tensor(np.array([0, 1]).astype(np.int32))
|
|
|
|
|
updates = Tensor(np.arange(6).reshape((2, 3)).astype(np.int32))
|
|
|
|
|
output = scatter_update_net(inputx, indices, updates)
|
|
|
|
|
expected = np.array([[0., 1., 2.],
|
|
|
|
|
[3., 4., 5.]]).astype(np.int32)
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
@ -89,7 +101,7 @@ def test_scatter_update_large_float16():
|
|
|
|
|
expected = np.array([[69., 70., 71.],
|
|
|
|
|
[66., 67., 68.],
|
|
|
|
|
[63., 64., 65.],
|
|
|
|
|
[72., 73., 74.]])
|
|
|
|
|
[72., 73., 74.]]).astype(np.float16)
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
@ -102,5 +114,52 @@ def test_scatter_update_disordered_float16():
|
|
|
|
|
output = scatter_update_net(inputx, indices, updates)
|
|
|
|
|
expected = np.array([[45., 44., 43., 42.],
|
|
|
|
|
[63., 64., 65., 66.],
|
|
|
|
|
[67., 68., 69., 70.]])
|
|
|
|
|
[67., 68., 69., 70.]]).astype(np.float16)
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
|
def test_scatter_update_disordered_int32():
|
|
|
|
|
inputx = Tensor(np.flip(np.arange(34, 46).reshape(3, 4).astype(np.int32)))
|
|
|
|
|
indices = Tensor(np.array([1, 2]).astype(np.int32))
|
|
|
|
|
updates = Tensor(np.arange(63, 71).reshape((2, 4)).astype(np.int32))
|
|
|
|
|
output = scatter_update_net(inputx, indices, updates)
|
|
|
|
|
expected = np.array([[45., 44., 43., 42.],
|
|
|
|
|
[63., 64., 65., 66.],
|
|
|
|
|
[67., 68., 69., 70.]]).astype(np.int32)
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|
|
|
|
|
|
@pytest.mark.level0
|
|
|
|
|
@pytest.mark.platform_x86_gpu_training
|
|
|
|
|
@pytest.mark.env_onecard
|
|
|
|
|
def test_scatter_update_large_shape_float16():
|
|
|
|
|
inputx = Tensor(np.arange(96).reshape((4, 2, 3, 4)).astype(np.float16))
|
|
|
|
|
indices = Tensor(np.array([1, 0]).astype(np.int32))
|
|
|
|
|
updates = Tensor(np.flip(np.arange(48).reshape((2, 2, 3, 4)).astype(np.float16)))
|
|
|
|
|
output = scatter_update_net(inputx, indices, updates)
|
|
|
|
|
expected = np.array([[[[23., 22., 21., 20.],
|
|
|
|
|
[19., 18., 17., 16.],
|
|
|
|
|
[15., 14., 13., 12.]],
|
|
|
|
|
[[11., 10., 9., 8.],
|
|
|
|
|
[7., 6., 5., 4.],
|
|
|
|
|
[3., 2., 1., 0.]]],
|
|
|
|
|
[[[47., 46., 45., 44.],
|
|
|
|
|
[43., 42., 41., 40.],
|
|
|
|
|
[39., 38., 37., 36.]],
|
|
|
|
|
[[35., 34., 33., 32.],
|
|
|
|
|
[31., 30., 29., 28.],
|
|
|
|
|
[27., 26., 25., 24.]]],
|
|
|
|
|
[[[48., 49., 50., 51.],
|
|
|
|
|
[52., 53., 54., 55.],
|
|
|
|
|
[56., 57., 58., 59.]],
|
|
|
|
|
[[60., 61., 62., 63.],
|
|
|
|
|
[64., 65., 66., 67.],
|
|
|
|
|
[68., 69., 70., 71.]]],
|
|
|
|
|
[[[72., 73., 74., 75.],
|
|
|
|
|
[76., 77., 78., 79.],
|
|
|
|
|
[80., 81., 82., 83.]],
|
|
|
|
|
[[84., 85., 86., 87.],
|
|
|
|
|
[88., 89., 90., 91.],
|
|
|
|
|
[92., 93., 94., 95.]]]]).astype(np.float16)
|
|
|
|
|
np.testing.assert_array_almost_equal(output.asnumpy(), expected)
|
|
|
|
|