test_transpose_op.py 1.3 KB
Newer Older
X
xzl 已提交
1 2
import unittest
import numpy as np
3
from op_test import OpTest
X
xzl 已提交
4 5


6
class TestTransposeOp(OpTest):
X
xzl 已提交
7
    def setUp(self):
8 9
        self.initTestCase()
        self.op_type = "transpose"
X
xzl 已提交
10
        self.inputs = {'X': np.random.random(self.shape).astype("float32")}
11
        self.attrs = {'axis': list(self.axis)}
X
xzl 已提交
12
        self.outputs = {'Out': self.inputs['X'].transpose(self.axis)}
13 14 15 16 17

    def test_check_output(self):
        self.check_output()

    def test_check_grad(self):
X
xzl 已提交
18
        self.check_grad(['X'], 'Out')
19 20 21 22 23 24

    def initTestCase(self):
        self.shape = (3, 4)
        self.axis = (1, 0)


25 26 27 28 29 30
class TestCase0(TestTransposeOp):
    def initTestCase(self):
        self.shape = (3, )
        self.axis = (0, )


31 32 33 34 35 36 37 38 39 40 41
class TestCase1(TestTransposeOp):
    def initTestCase(self):
        self.shape = (3, 4, 5)
        self.axis = (0, 2, 1)


class TestCase2(TestTransposeOp):
    def initTestCase(self):
        self.shape = (2, 3, 4, 5)
        self.axis = (0, 2, 3, 1)

X
xzl 已提交
42

43 44 45 46
class TestCase3(TestTransposeOp):
    def initTestCase(self):
        self.shape = (2, 3, 4, 5, 6)
        self.axis = (4, 2, 3, 1, 0)
X
xzl 已提交
47 48


49 50 51 52
class TestCase4(TestTransposeOp):
    def initTestCase(self):
        self.shape = (2, 3, 4, 5, 6, 1)
        self.axis = (4, 2, 3, 1, 0, 5)
X
xzl 已提交
53 54 55 56


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