From a89b33ff02fc87874624a25472471bb235adc6a5 Mon Sep 17 00:00:00 2001 From: Zhou Wei <1183042833@qq.com> Date: Tue, 18 Oct 2022 12:55:54 +0800 Subject: [PATCH] fix doc of some sparse api (#47020) --- python/paddle/incubate/sparse/binary.py | 58 +++++++++---------- python/paddle/incubate/sparse/multiary.py | 10 ++-- .../incubate/sparse/nn/layer/activation.py | 6 +- python/paddle/incubate/sparse/unary.py | 4 +- 4 files changed, 38 insertions(+), 40 deletions(-) diff --git a/python/paddle/incubate/sparse/binary.py b/python/paddle/incubate/sparse/binary.py index c2592e0beb1..656e0fd8ddd 100644 --- a/python/paddle/incubate/sparse/binary.py +++ b/python/paddle/incubate/sparse/binary.py @@ -38,7 +38,7 @@ def matmul(x, y, name=None): Applies matrix multiplication of two Tensors. - The supported input/output Tensor layout are as follows: + The supported input/output Tensor type are as follows: Note: x[SparseCsrTensor] @ y[SparseCsrTensor] -> out[SparseCsrTensor] @@ -53,12 +53,12 @@ def matmul(x, y, name=None): is zero or more batch dimensions. Args: - x (Tensor): The input tensor. It can be SparseCooTensor/SparseCsrTensor. The data type can be float32 or float64. - y (Tensor): The input tensor. It can be SparseCooTensor/SparseCsrTensor/DenseTensor. The data type can be float32 or float64. + x (SparseTensor): The input tensor. It can be SparseCooTensor/SparseCsrTensor. The data type can be float32 or float64. + y (SparseTensor|DenseTensor): The input tensor. It can be SparseCooTensor/SparseCsrTensor/DenseTensor. The data type can be float32 or float64. name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. Returns: - Tensor: Its layout is determined by that of `x` and `y` . + SparseTensor|DenseTensor: Determined by `x` and `y` . Examples: @@ -121,13 +121,13 @@ def masked_matmul(x, y, mask, name=None): where `*` is zero or more batch dimensions. Args: - x (Tensor): The input tensor. It is DenseTensor. The data type can be float32 or float64. - y (Tensor): The input tensor. It is DenseTensor. The data type can be float32 or float64. - mask (Tensor): The mask tensor, which can be SparseCooTensor/SparseCsrTensor. It specify sparse coordinates. The data type can be float32 or float64. + x (DenseTensor): The input tensor. It is DenseTensor. The data type can be float32 or float64. + y (DenseTensor): The input tensor. It is DenseTensor. The data type can be float32 or float64. + mask (SparseTensor): The mask tensor, which can be SparseCooTensor/SparseCsrTensor. It specify sparse coordinates. The data type can be float32 or float64. name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. Returns: - Tensor: SparseCoo or SparseCsr, which is determined by that of `mask` . + SparseTensor: SparseCooTensor or SparseCsrTensor, which is same with `mask` . Examples: @@ -171,46 +171,44 @@ def mv(x, vec, name=None): The supported input/output Tensor layout are as follows: Note: - x[SparseCsrTensor] @ y[DenseTensor] -> out[SparseCsrTensor] - x[SparseCooTensor] @ y[DenseTensor] -> out[SparseCooTensor] + x[SparseCsrTensor] @ vec[DenseTensor] -> out[DenseTensor] + x[SparseCooTensor] @ vec[DenseTensor] -> out[DenseTensor] It supports backward propagation. - The shape of `x` should be `[M, N]` , and the shape of `y` should be `[N]` , + The shape of `x` should be `[M, N]` , and the shape of `vec` should be `[N]` , and the shape of `out` will be `[M]` . Args: - x (Tensor): The input 2D tensor. It must be SparseCooTensor/SparseCsrTensor. The data type can be float32 or float64. - y (Tensor): The input 1D tensor. It must be DenseTensor vector. The data type can be float32 or float64. + x (SparseTensor): The input 2D tensor. It must be SparseCooTensor/SparseCsrTensor. The data type can be float32 or float64. + vec (DenseTensor): The input 1D tensor. It must be DenseTensor vector. The data type can be float32 or float64. name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. Returns: - Tensor: 1D Tensor. + DenseTensor: 1D DenseTensor whose dtype is same with input. Examples: .. code-block:: python import paddle - from paddle.fluid.framework import _test_eager_guard paddle.seed(100) # csr @ dense -> dense - with _test_eager_guard(): - crows = [0, 2, 3, 5] - cols = [1, 3, 2, 0, 1] - values = [1., 2., 3., 4., 5.] - dense_shape = [3, 4] - csr = paddle.incubate.sparse.sparse_csr_tensor(crows, cols, values, dense_shape) - # Tensor(shape=[3, 4], dtype=paddle.float32, place=Place(gpu:0), stop_gradient=True, - # crows=[0, 2, 3, 5], - # cols=[1, 3, 2, 0, 1], - # values=[1., 2., 3., 4., 5.]) - vec = paddle.randn([4]) - - out = paddle.incubate.sparse.mv(csr, vec) - # Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True, - # [-3.85499096, -2.42975140, -1.75087738]) + crows = [0, 2, 3, 5] + cols = [1, 3, 2, 0, 1] + values = [1., 2., 3., 4., 5.] + dense_shape = [3, 4] + csr = paddle.incubate.sparse.sparse_csr_tensor(crows, cols, values, dense_shape) + # Tensor(shape=[3, 4], dtype=paddle.float32, place=Place(gpu:0), stop_gradient=True, + # crows=[0, 2, 3, 5], + # cols=[1, 3, 2, 0, 1], + # values=[1., 2., 3., 4., 5.]) + vec = paddle.randn([4]) + + out = paddle.incubate.sparse.mv(csr, vec) + # Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True, + # [-3.85499096, -2.42975140, -1.75087738]) """ return _C_ops.sparse_mv(x, vec) diff --git a/python/paddle/incubate/sparse/multiary.py b/python/paddle/incubate/sparse/multiary.py index 5a013930776..dd65b1bdeef 100644 --- a/python/paddle/incubate/sparse/multiary.py +++ b/python/paddle/incubate/sparse/multiary.py @@ -29,7 +29,7 @@ def addmm(input, x, y, beta=1.0, alpha=1.0, name=None): .. math:: - Out = alpha * x * y + beta * input + out = alpha * x * y + beta * input The supported input/output Tensor layout are as follows: @@ -44,15 +44,15 @@ def addmm(input, x, y, beta=1.0, alpha=1.0, name=None): Dimensions `input` , `x` , `y` must be same and >= 2D. Automatic broadcasting of Tensor is not supported. Args: - input (Tensor): The input tensor. Shape is [*, M, N]. The data type can be float32 or float64. - x (Tensor): The input tensor. Shape is [*, M, K]. The data type can be float32 or float64. - y (Tensor): The input tensor. Shape is [*, K, N]. The data type can be float32 or float64. + input (SparseTensor|DenseTensor): The input tensor. Shape is [*, M, N]. The data type can be float32 or float64. + x (SparseTensor): The input SparseTensor. Shape is [*, M, K]. The data type can be float32 or float64. + y (SparseTensor|DenseTensor): The input tensor. Shape is [*, K, N]. The data type can be float32 or float64. beta (float, optional): Coefficient of `input` . Default: 1.0 alpha (float, optional): Coefficient of `x * y` . Default: 1.0 name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. Returns: - Tensor: Its layout is determined by that of `x` and `y` . dtype and shape is the same with `input` + SparseTensor|DenseTensor: Tensor type, date type and shape is the same with `input` . Examples: diff --git a/python/paddle/incubate/sparse/nn/layer/activation.py b/python/paddle/incubate/sparse/nn/layer/activation.py index f3c2e1456c4..bcbf27fab9d 100644 --- a/python/paddle/incubate/sparse/nn/layer/activation.py +++ b/python/paddle/incubate/sparse/nn/layer/activation.py @@ -66,8 +66,8 @@ class Softmax(Layer): Only support axis=-1 for SparseCsrTensor, which is faster when read data by row (axis=-1). - From the point of view of dense matrix, for each row :math:`i` and each column :math:`j` - in the matrix, we have: + Transform x to dense matix, and :math:`i` is row index, :math:`j` is column index. + If axis=-1, We have: .. math:: @@ -130,7 +130,7 @@ class ReLU6(Layer): .. math:: - ReLU(x) = min(max(0,x), 6) + ReLU6(x) = min(max(0,x), 6) Parameters: name (str, optional): Name for the operation (optional, default is None). diff --git a/python/paddle/incubate/sparse/unary.py b/python/paddle/incubate/sparse/unary.py index 62ab27d0c04..3ebd84d8ed0 100644 --- a/python/paddle/incubate/sparse/unary.py +++ b/python/paddle/incubate/sparse/unary.py @@ -549,7 +549,7 @@ def coalesce(x): @dygraph_only def rad2deg(x, name=None): """ - Convert each of the elements of input x from angles in radians to degrees, + Convert each of the elements of input x from radian to degree, requiring x to be a SparseCooTensor or SparseCsrTensor. .. math:: @@ -582,7 +582,7 @@ def rad2deg(x, name=None): @dygraph_only def deg2rad(x, name=None): """ - Convert each of the elements of input x from degrees to angles in radians, + Convert each of the elements of input x from degree to radian, requiring x to be a SparseCooTensor or SparseCsrTensor. .. math:: -- GitLab