test_protobuf.py 869 字节
Newer Older
Q
Qiao Longfei 已提交
1
import paddle.v2.fluid.proto.framework_pb2 as framework_pb2
2 3 4 5 6
import unittest


class TestFrameworkProto(unittest.TestCase):
    def test_all(self):
Y
Yu Yang 已提交
7
        op_proto = framework_pb2.OpProto()
8 9 10 11 12 13 14 15 16 17 18 19 20
        ipt0 = op_proto.inputs.add()
        ipt0.name = "a"
        ipt0.comment = "the input of cosine op"
        ipt1 = op_proto.inputs.add()
        ipt1.name = "b"
        ipt1.comment = "the other input of cosine op"
        opt = op_proto.outputs.add()
        opt.name = "output"
        opt.comment = "the output of cosine op"
        op_proto.comment = "cosine op, output = scale*cos(a, b)"
        attr = op_proto.attrs.add()
        attr.name = "scale"
        attr.comment = "scale of cosine op"
Y
Yu Yang 已提交
21
        attr.type = framework_pb2.FLOAT
22 23
        op_proto.type = "cos"
        self.assertTrue(op_proto.IsInitialized())
24 25 26 27


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