test_reshape_op.py 942 字节
Newer Older
Y
Yibing Liu 已提交
1 2
import unittest
import numpy as np
Y
Yibing Liu 已提交
3
from op_test import OpTest
Y
Yibing Liu 已提交
4 5


Y
Yibing Liu 已提交
6
class TestReshapeOp(OpTest):
Y
Yibing Liu 已提交
7
    def setUp(self):
Y
Yibing Liu 已提交
8 9 10
        self.op_type = "reshape"
        self.inputs = {'X': np.random.random((10, 20)).astype("float32")}
        self.attrs = {'shape': [10 * 20]}
Y
Yibing Liu 已提交
11 12
        self.outputs = {'Out': self.inputs['X'].reshape(self.attrs['shape'])}

Y
Yibing Liu 已提交
13 14
    def test_check_output(self):
        self.check_output()
Y
Yibing Liu 已提交
15

Y
Yibing Liu 已提交
16 17
    def test_check_grad(self):
        self.check_grad(["X"], "Out")
Y
Yibing Liu 已提交
18 19


20 21 22 23 24 25 26 27 28 29 30 31 32 33
class TestReshapeOpDimInfer(OpTest):
    def setUp(self):
        self.op_type = "reshape"
        self.inputs = {'X': np.random.random((10, 20)).astype("float32")}
        self.attrs = {'shape': [4, -1, 5]}
        self.outputs = {'Out': self.inputs['X'].reshape(self.attrs['shape'])}

    def test_check_output(self):
        self.check_output()

    def test_check_grad(self):
        self.check_grad(["X"], "Out")


Y
Yibing Liu 已提交
34 35
if __name__ == '__main__':
    unittest.main()