diff --git a/python/paddle/incubate/sparse/binary.py b/python/paddle/incubate/sparse/binary.py index c2592e0beb15619fafb5218187ec5e90c9fc22b5..656e0fd8dddf8a2393ae7a26299d22321b1ab3c3 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 5a013930776326b65c44ef15ff3a846a62fc9705..dd65b1bdeef797a77c3b4b909c69eb4440287b87 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 f3c2e1456c4ec06655b0632e1ec1c006fdc6a020..bcbf27fab9d6b4495f6b700164ae4839cf218536 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 62ab27d0c04c6a01b5cad355b8fba03bd15ee7f7..3ebd84d8ed0de18a2a34b30d436ed59812b8aceb 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::