From 057d782d51cfb2d7ed4ec40559b09719d492275b Mon Sep 17 00:00:00 2001 From: Pei Yang Date: Thu, 10 Oct 2019 17:05:28 +0800 Subject: [PATCH] fix en api doc of [round, sin, sqrt], test=develop, test=document_fix (#20296) --- paddle/fluid/API.spec | 40 +++++++++---------- paddle/fluid/operators/activation_op.cc | 25 ++++++++---- .../fluid/layers/layer_function_generator.py | 19 +++++++-- 3 files changed, 54 insertions(+), 30 deletions(-) mode change 100755 => 100644 paddle/fluid/operators/activation_op.cc diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 8a3f8ccfba..602ed805db 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -387,26 +387,26 @@ paddle.fluid.layers.StaticRNN.update_memory (ArgSpec(args=['self', 'mem', 'var'] paddle.fluid.layers.reorder_lod_tensor_by_rank (ArgSpec(args=['x', 'rank_table'], varargs=None, keywords=None, defaults=None), ('document', '5b552a1f0f7eb4dacb768a975ba15d08')) paddle.fluid.layers.Print (ArgSpec(args=['input', 'first_n', 'message', 'summarize', 'print_tensor_name', 'print_tensor_type', 'print_tensor_shape', 'print_tensor_lod', 'print_phase'], varargs=None, keywords=None, defaults=(-1, None, 20, True, True, True, True, 'both')), ('document', '3130bed32922b9fd84ce2dea6250f635')) paddle.fluid.layers.is_empty (ArgSpec(args=['x', 'cond'], varargs=None, keywords=None, defaults=(None,)), ('document', '3011dc695f490afdf504dc24f628319a')) -paddle.fluid.layers.sigmoid (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '6e5a9645817c781e936da11c20395909')) -paddle.fluid.layers.logsigmoid (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '846e66903386aadb31a68c8226ac4880')) -paddle.fluid.layers.exp (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'f96f7fbb3af9816d9960c14737682ee5')) -paddle.fluid.layers.tanh (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '78df12509dddc43baa9cd3d9bb051e8d')) -paddle.fluid.layers.atan (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'f9ad8c2d64119bf4025ffe371bfbc3ad')) -paddle.fluid.layers.tanh_shrink (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '1c9a12739f34385ecd94b03690fffe0b')) -paddle.fluid.layers.sqrt (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '2bfcce8ed36f46973b384db8d229b6f5')) -paddle.fluid.layers.rsqrt (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '27b079cd8002e07dffb4334eba5b3c96')) -paddle.fluid.layers.abs (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '940e2c21a0dab0f035b71eae9d71adec')) -paddle.fluid.layers.ceil (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'a8e6a72192ea5f433a0a150de8152354')) -paddle.fluid.layers.floor (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'ad6c7fc037b433753729f47c7765034f')) -paddle.fluid.layers.cos (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '4f4b15408ae927112e8793441c165709')) -paddle.fluid.layers.acos (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '685761a55d82355ff3421e99b2bc710d')) -paddle.fluid.layers.asin (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '9a2272c67f32c5e662dd96ed21d0b22a')) -paddle.fluid.layers.sin (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'b5226c5b623ecc8bf893990e3b190f7d')) -paddle.fluid.layers.round (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '16fdd1d5a03b9c3f8c436156c0cd508b')) -paddle.fluid.layers.reciprocal (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '50b76cb575a1a09fe1b53ffc06a77e3f')) -paddle.fluid.layers.square (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'b283c4eb9a975d5289d4f53500aa50fa')) -paddle.fluid.layers.softplus (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '0e619a20fa04d2d997b7757dd246eeb2')) -paddle.fluid.layers.softsign (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'bf02c7440088ebb934217c92f001a09d')) +paddle.fluid.layers.sigmoid (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '7bd26680989f33301a4a68000d5af4b0')) +paddle.fluid.layers.logsigmoid (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '047c2af83166a69728be73fc44e9ad9f')) +paddle.fluid.layers.exp (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'f6b0cc458acf7ad822a0c26e72fc22a1')) +paddle.fluid.layers.tanh (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'a4d7e467c3a6607caab89d53bd5099d2')) +paddle.fluid.layers.atan (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '29250d1f3af5144ba039197215df2131')) +paddle.fluid.layers.tanh_shrink (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '1db8f617031c17e60d428f01168d92eb')) +paddle.fluid.layers.sqrt (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '13892ce3aa521fcabb29260bd65414e9')) +paddle.fluid.layers.rsqrt (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '9648ccd87867053537a54dbf0416ad6d')) +paddle.fluid.layers.abs (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '18ecb9dc8efbdce519a3a96c94b462e0')) +paddle.fluid.layers.ceil (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '668ba28052c91056ad055ed058790f1c')) +paddle.fluid.layers.floor (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'd103f8b661776349ed61087c048994a3')) +paddle.fluid.layers.cos (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '748bd06996177acfe11fb5b302c24256')) +paddle.fluid.layers.acos (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'afa3db0f45c74da6c1a1c646abc27dee')) +paddle.fluid.layers.asin (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '0179b8944cc74610a55b148629287090')) +paddle.fluid.layers.sin (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'b331a771d6d2204c7139c79a9213acf2')) +paddle.fluid.layers.round (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '5df0b9eacbbb0b91f0eb39e37446ec57')) +paddle.fluid.layers.reciprocal (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '35f89ad821fbdf8a50ad26cd9f31b7cf')) +paddle.fluid.layers.square (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'a684ce5a61c2c046aa5639d98aaa3acc')) +paddle.fluid.layers.softplus (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', '76c853f8a013466b7f443ad166e259bd')) +paddle.fluid.layers.softsign (ArgSpec(args=['x', 'name'], varargs=None, keywords=None, defaults=(None,)), ('document', 'e52b23bc455c708d7a26501db4ab8971')) paddle.fluid.layers.softshrink (ArgSpec(args=['x', 'alpha'], varargs=None, keywords=None, defaults=(None,)), ('document', '958c7bfdfb0b5e92af6ca4a90d24e5ef')) paddle.fluid.layers.hard_shrink (ArgSpec(args=['x', 'threshold'], varargs=None, keywords=None, defaults=(None,)), ('document', '386a4103d2884b2f1312ebc1e8ee6486')) paddle.fluid.layers.cumsum (ArgSpec(args=['x', 'axis', 'exclusive', 'reverse'], varargs=None, keywords=None, defaults=(None, None, None)), ('document', '5ab9d5721a6734fe127069e4314e1309')) diff --git a/paddle/fluid/operators/activation_op.cc b/paddle/fluid/operators/activation_op.cc old mode 100755 new mode 100644 index c827c692a3..bfd456d2fa --- a/paddle/fluid/operators/activation_op.cc +++ b/paddle/fluid/operators/activation_op.cc @@ -41,8 +41,11 @@ static constexpr bool CanInplaceAct() { : public ::paddle::framework::OpProtoAndCheckerMaker { \ public: \ void Make() override { \ - AddInput("X", "Input of " #OP_NAME " operator"); \ - AddOutput("Out", "Output of " #OP_NAME " operator"); \ + AddInput("X", "Input of " #OP_NAME \ + " operator, an N-D Tensor, with data type float32, " \ + "float64 or float16."); \ + AddOutput("Out", "Output of " #OP_NAME \ + " operator, a Tensor with shape same as input."); \ AddAttr("use_mkldnn", \ "(bool, default false) Only used in mkldnn kernel") \ .SetDefault(false); \ @@ -210,10 +213,10 @@ $$out = x - \\frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}$$ UNUSED constexpr char SqrtDoc[] = R"DOC( Sqrt Activation Operator. -Please make sure legal input, when input a negative value closed to zero, -you should add a small epsilon(1e-12) to avoid negative number caused by numerical errors. +.. math:: out=\sqrt x=x^{1/2} -$out = \sqrt{x}$ +**Note**: + input value must be greater than or equal to zero. )DOC"; @@ -262,9 +265,17 @@ $out = sin(x)$ )DOC"; UNUSED constexpr char RoundDoc[] = R"DOC( -Round Activation Operator. +The OP rounds the values in the input to the nearest integer value. -$out = [x]$ +.. code-block:: python + + input: + x.shape = [4] + x.data = [1.2, -0.9, 3.4, 0.9] + + output: + out.shape = [4] + out.data = [1., -1., 3., 1.] )DOC"; diff --git a/python/paddle/fluid/layers/layer_function_generator.py b/python/paddle/fluid/layers/layer_function_generator.py index 5589dee275..27643143f8 100755 --- a/python/paddle/fluid/layers/layer_function_generator.py +++ b/python/paddle/fluid/layers/layer_function_generator.py @@ -255,14 +255,27 @@ def generate_activation_fn(op_type): return output func.__name__ = op_type - func.__doc__ = _generate_doc_string_(op_proto) + func.__doc__ = _generate_doc_string_( + op_proto, + additional_args_lines=[ + "name(str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` ." + ]) func.__doc__ = func.__doc__ + """ Examples: .. code-block:: python import paddle.fluid as fluid - data = fluid.layers.data(name="input", shape=[None, 32, 784]) - result = fluid.layers.%s(data) + import numpy as np + + inputs = fluid.layers.data(name="x", shape = [1], dtype='float32') + output = fluid.layers.%s(inputs) + + exe = fluid.Executor(fluid.CPUPlace()) + exe.run(fluid.default_startup_program()) + + img = np.array([1.0, 1.0, 1.0, 1.0]).astype(np.float32) + res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output]) + print(res) """ % op_type return func -- GitLab