From 83d775fccb43bd71b74cf323a864ea000e8b336d Mon Sep 17 00:00:00 2001 From: pangyoki Date: Sat, 22 Aug 2020 04:05:09 -0500 Subject: [PATCH] add uniform op doc (#2439) * add uniform op doc * fix uniform en format * delete useless code --- doc/fluid/api/tensor/random.rst | 1 + doc/fluid/api/tensor/random/uniform.rst | 10 +++ doc/fluid/api_cn/tensor_cn.rst | 1 + doc/fluid/api_cn/tensor_cn/uniform_cn.rst | 77 +++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 doc/fluid/api/tensor/random/uniform.rst create mode 100644 doc/fluid/api_cn/tensor_cn/uniform_cn.rst diff --git a/doc/fluid/api/tensor/random.rst b/doc/fluid/api/tensor/random.rst index fdc985d3de0..9f65462a494 100644 --- a/doc/fluid/api/tensor/random.rst +++ b/doc/fluid/api/tensor/random.rst @@ -9,3 +9,4 @@ random random/randint.rst random/randn.rst random/randperm.rst + random/uniform.rst diff --git a/doc/fluid/api/tensor/random/uniform.rst b/doc/fluid/api/tensor/random/uniform.rst new file mode 100644 index 00000000000..b323d371212 --- /dev/null +++ b/doc/fluid/api/tensor/random/uniform.rst @@ -0,0 +1,10 @@ +.. THIS FILE IS GENERATED BY `gen_doc.{py|sh}` + !DO NOT EDIT THIS FILE MANUALLY! + +.. _api_tensor_random_uniform: + +uniform +------- + +.. autofunction:: paddle.tensor.random.uniform + :noindex: diff --git a/doc/fluid/api_cn/tensor_cn.rst b/doc/fluid/api_cn/tensor_cn.rst index 539bc95c91b..46ceef8b6ac 100644 --- a/doc/fluid/api_cn/tensor_cn.rst +++ b/doc/fluid/api_cn/tensor_cn.rst @@ -157,6 +157,7 @@ paddle.tensor tensor_cn/tril_cn.rst tensor_cn/triu_cn.rst tensor_cn/unbind_cn.rst + tensor_cn/uniform_cn.rst tensor_cn/unique_cn.rst tensor_cn/unique_with_counts_cn.rst tensor_cn/unsqueeze_cn.rst diff --git a/doc/fluid/api_cn/tensor_cn/uniform_cn.rst b/doc/fluid/api_cn/tensor_cn/uniform_cn.rst new file mode 100644 index 00000000000..f5996a72d4f --- /dev/null +++ b/doc/fluid/api_cn/tensor_cn/uniform_cn.rst @@ -0,0 +1,77 @@ +.. _cn_api_tensor_uniform: + +uniform +------------------------------- + +.. py:function:: paddle.uniform(shape, dtype='float32', min=-1.0, max=1.0, seed=0, name=None) + + + + +该OP返回数值服从范围[``min``, ``max``)内均匀分布的随机Tensor,形状为 ``shape``,数据类型为 ``dtype``。 + +:: + + 示例1: + 给定: + shape=[1,2] + 则输出为: + result=[[0.8505902, 0.8397286]] + +参数: + - **shape** (list|tuple|Tensor) - 生成的随机Tensor的形状。如果 ``shape`` 是list、tuple,则其中的元素可以是int,或者是形状为[1]且数据类型为int32、int64的Tensor。如果 ``shape`` 是Tensor,则是数据类型为int32、int64的1-D Tensor。 + - **dtype** (str|np.dtype, 可选) - 输出Tensor的数据类型,支持float32、float64。默认值为float32。 + - **min** (float|int,可选) - 要生成的随机值范围的下限,min包含在范围中。支持的数据类型:float、int。默认值为-1.0。 + - **max** (float|int,可选) - 要生成的随机值范围的上限,max不包含在范围中。支持的数据类型:float、int。默认值为1.0。 + - **seed** (int,可选) - 随机种子,用于生成样本。0表示使用系统生成的种子。注意如果种子不为0,该操作符每次都生成同样的随机数。支持的数据类型:int。默认为 0。 + - **name** (str, 可选) - 输出的名字。一般无需设置,默认值为None。该参数供开发人员打印调试信息时使用,具体用法请参见 :ref:`api_guide_Name` 。 + +返回: + Tensor:数值服从范围[``min``, ``max``)内均匀分布的随机Tensor,形状为 ``shape``,数据类型为 ``dtype``。 + +抛出异常: + - ``TypeError`` - 如果 ``shape`` 的类型不是list、tuple、Tensor。 + - ``TypeError`` - 如果 ``dtype`` 不是float32、float64。 + +**代码示例**: + +.. code-block:: python + + import numpy as np + import paddle + + paddle.disable_static() + + # example 1: + # attr shape is a list which doesn't contain Tensor. + result_1 = paddle.uniform(shape=[3, 4]) + # [[ 0.84524226, 0.6921872, 0.56528175, 0.71690357], + # [-0.34646994, -0.45116323, -0.09902662, -0.11397249], + # [ 0.433519, 0.39483607, -0.8660099, 0.83664286]] + + # example 2: + # attr shape is a list which contains Tensor. + dim_1 = paddle.fill_constant([1], "int64", 2) + dim_2 = paddle.fill_constant([1], "int32", 3) + result_2 = paddle.uniform(shape=[dim_1, dim_2]) + # [[-0.9951253, 0.30757582, 0.9899647 ], + # [ 0.5864527, 0.6607096, -0.8886161 ]] + + # example 3: + # attr shape is a Tensor, the data type must be int64 or int32. + shape = np.array([2, 3]) + shape_tensor = paddle.to_tensor(shape) + + result_3 = paddle.uniform(shape_tensor) + # if shape_tensor's value is [2, 3] + # result_3 is: + # [[-0.8517412, -0.4006908, 0.2551912 ], + # [ 0.3364414, 0.36278176, -0.16085452]] + + + + + + + +