test_transpose_op.py 810 字节
Newer Older
X
xzl 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import unittest
import numpy as np
from gradient_checker import GradientChecker
from op_test_util import OpTestMeta
from paddle.v2.framework.op import Operator


class TestTransposeOp(unittest.TestCase):
    __metaclass__ = OpTestMeta

    def setUp(self):
        self.type = "transpose"
        self.inputs = {'X': np.random.random((3, 4)).astype("float32"), }
        self.attrs = {'axis': [1, 0]}
        self.outputs = {'Out': self.inputs['X'].transpose((1, 0))}


class TransposeGradOpTest(GradientChecker):
    def test_transpose(self):
        op = Operator("transpose", X="X", Out="Out", axis=[1, 0])
        inputs = {'X': np.random.random((32, 84)).astype("float32"), }

        self.check_grad(op, inputs, set(["X"]), "Out", max_relative_error=0.5)


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