test_scatter_op.py 723 字节
Newer Older
Z
zchen0211 已提交
1
import unittest
Q
qijun 已提交
2 3
import numpy as np
from op_test import OpTest
Z
zchen0211 已提交
4 5


Q
qijun 已提交
6
class TestScatterOp(OpTest):
Z
zchen0211 已提交
7
    def setUp(self):
Q
qijun 已提交
8 9 10 11 12
        self.op_type = "scatter"
        ref_np = np.ones((3, 3)).astype("float32")
        index_np = np.array([1, 2]).astype("int32")
        updates_np = np.random.random((2, 3)).astype("float32")
        output_np = np.copy(ref_np)
Z
zchen0211 已提交
13 14 15 16
        output_np[index_np] += updates_np
        self.inputs = {'Ref': ref_np, 'Index': index_np, 'Updates': updates_np}
        self.outputs = {'Out': output_np}

Q
qijun 已提交
17 18
    def test_check_output(self):
        self.check_output()
Z
zchen0211 已提交
19

Q
qijun 已提交
20 21
    def test_check_grad(self):
        self.check_grad(['Updates', 'Ref'], 'Out', in_place=True)
Z
zchen0211 已提交
22 23 24 25


if __name__ == "__main__":
    unittest.main()