test_transpose_op.py 1.2 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 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
        self.initTestCase()
        self.op_type = "transpose"
        self.inputs = {'Input': np.random.random(self.shape).astype("float32")}
        self.attrs = {'axis': list(self.axis)}
        self.outputs = {'Output': self.inputs['Input'].transpose(self.axis)}

    def test_check_output(self):
        self.check_output()

    def test_check_grad(self):
        self.check_grad(['Input'], 'Output')

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


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 已提交
36

37 38 39 40
class TestCase3(TestTransposeOp):
    def initTestCase(self):
        self.shape = (2, 3, 4, 5, 6)
        self.axis = (4, 2, 3, 1, 0)
X
xzl 已提交
41 42


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


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