test_reshape_op.py 875 字节
Newer Older
Y
Yibing Liu 已提交
1 2
import unittest
import numpy as np
Y
Yibing Liu 已提交
3
from gradient_checker import GradientChecker, Operator
Y
Yibing Liu 已提交
4 5 6 7 8 9 10 11
from op_test_util import OpTestMeta


class TestReshapeOp(unittest.TestCase):
    __metaclass__ = OpTestMeta

    def setUp(self):
        self.type = "reshape"
Y
Yibing Liu 已提交
12
        self.inputs = {'X': np.random.random((37, 51)).astype("float32"), }
Y
Yibing Liu 已提交
13
        self.attrs = {'shape': [51 * 37]}
Y
Yibing Liu 已提交
14 15 16
        self.outputs = {'Out': self.inputs['X'].reshape(self.attrs['shape'])}


Y
Yibing Liu 已提交
17 18 19 20 21 22 23 24 25 26
class TestReshapeGradOp(GradientChecker):
    def setUp(self):
        self.op = Operator("reshape", X='X', Out='Out', shape=[5, 40])
        self.inputs = {"X": np.random.random((10, 20)).astype("float32")}

    def test_normal(self):
        self.check_grad(self.op, self.inputs, ["X"], "Out")

    def test_dev_compare(self):
        self.compare_grad(self.op, self.inputs)
Y
Yibing Liu 已提交
27 28 29 30


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