
    ёi                    &   S SK Jr  S SKJr  S SKrS SKrS SKJr  S SKJ	r	J
r
  S SKJrJrJr  S SKJr  S SKJr  S S	KJr  \(       a  S S
KJr  S SKJr  S SKJrJr  / r\R8                  R:                  R<                  \R8                  R:                  R>                  \R8                  R:                  R@                  \R8                  R:                  RB                  \R8                  R:                  RD                  \R8                  R:                  RF                  /r$S(S)S jjr%S(S)S jjr&S(S)S jjr' S(       S*S jjr(    S+           S,S jjr)S(S)S jjr*S(S)S jjr+S(S)S jjr,S(S)S jjr-S(S)S jjr.S(S)S jjr/S(S)S jjr0S(S)S jjr1   S-         S.S jjr2S(S/S jjr3S(S)S jjr4S(S)S jjr5S(S)S jjr6S(S)S  jjr7S(S)S! jjr8S(S)S" jjr9\" SS#/5      S(S0S$ jj5       r:S(S)S% jjr; S(           S1S& jjr<    S2           S3S' jjr=g)4    )annotations)TYPE_CHECKINGN)_C_ops)
check_typecheck_variable_and_dtype)convert_np_dtype_to_dtype_corein_dynamic_or_pir_mode)Variable)LayerHelper)param_one_alias)Sequence)Tensor)	DTypeLike	ShapeLikexc                Z    [        5       (       d   S5       e[        R                  " U 5      $ )aZ  
Calculate elementwise sin of SparseTensor, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = sin(x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.sin(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[-0.90929741,  0.84147102])
<Currently, Sparse API only support dynamic mode or pir mode.)r
   r   
sparse_sinr   names     S/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/sparse/unary.pysinr   5   0    : "## F# Q    c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )aX  
Calculate elementwise tan of SparseTensor, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = tan(x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.tan(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[2.18503976, 1.55740774])
r   )r
   r   
sparse_tanr   s     r   tanr   X   r   r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )a[  
Calculate elementwise asin of SparseTensor, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = asin(x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.asin(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[nan       , 1.57079625])
r   )r
   r   sparse_asinr   s     r   asinr!   {   0    : "## F# a  r   c                Z    [        5       (       d   S5       e[        R                  " X5      $ )a0  
Changes the perm order of ``x`` without changing its data, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = transpose(x, perm)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64.
    perm (list|tuple): Permute the input according to the data of perm.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A transposed Sparse Tensor with the same data type as ``x``.

Examples:
    .. code-block:: python

        >>> # doctest: +SKIP('indices overflow')
        >>> # doctest: +REQUIRES(env:GPU)
        >>> import paddle

        >>> dense_x = paddle.to_tensor([[-2., 0.], [1., 2.]])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.transpose(sparse_x, [1, 0])
        >>> out
        Tensor(shape=[2, 2], dtype=paddle.float32, place=Place(gpu:0), stop_gradient=True,
            indices=[[0, 0]],
            values=[[-2.,  0.],
                    [ 1.,  2.]])

r   )r
   r   sparse_transpose)r   permr   s      r   	transposer&      s1    H "## F# ""1++r   c           
        SnUb  Sn[        U5      n[        5       (       a  [        R                  " XX#5      $ Uc  / nOU/nXUS.nU(       a  UR	                  U R
                  US.5        [        U S/ SQS5        [        US	[        [        [        [        S5      [        4S5        Sn[        U5      nU(       a  UR                  US
9n	OUR                  U R
                  S
9n	UR                  USU 0SU	0US9  U	$ )ae	  
Computes the sum of sparse tensor elements over the given dimension, requiring x to be a SparseCooTensor or SparseCsrTensor.

Args:
    x (Tensor): An N-D Tensor, the data type is bool, float16, float32, float64, int32 or int64.
    axis (int|list|tuple|None, optional): The dimensions along which the sum is performed. If
        :attr:`None`, sum all elements of :attr:`x` and return a
        Tensor with a single element, otherwise must be in the
        range :math:`[-rank(x), rank(x))`. If :math:`axis[i] < 0`,
        the dimension to reduce is :math:`rank + axis[i]`.
    dtype (str|None, optional): The dtype of output Tensor. The default value is None, the dtype
        of output is the same as input Tensor `x`.
    keepdim (bool, optional): Whether to reserve the reduced dimension in the
        output Tensor. The result Tensor will have one fewer dimension
        than the :attr:`x` unless :attr:`keepdim` is true, default
        value is False.
    name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: Results of summation operation on the specified axis of input Tensor `x`.
    if `x.dtype='bool'` or `x.dtype='int32'`, it's data type is `'int64'`,
    otherwise it's data type is the same as `x`.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([[-2., 0.], [1., 2.]])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out1 = paddle.sparse.sum(sparse_x)
        >>> out1
        Tensor(shape=[1], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[0],
            values=1.)
        >>> out2 = paddle.sparse.sum(sparse_x, axis=0)
        >>> out2
        Tensor(shape=[1, 2], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0]],
            values=[[-1.,  2.]])
        >>> out3 = paddle.sparse.sum(sparse_x, axis=-1)
        >>> out3
        Tensor(shape=[2], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 1]],
            values=[-2.,  3.])
        >>> out4 = paddle.sparse.sum(sparse_x, axis=1, keepdim=True)
        >>> out4
        Tensor(shape=[2, 1], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 1]],
            values=[[-2.],
                    [ 3.]])
FNT)axisdtypekeepdim)in_dtype	out_dtyper   boolfloat32float64int16int32int64
sparse_sumr(   r)   outtypeinputsoutputsattrs)r   r
   r   r4   updater)   r   r   intlisttupler8   r   r   )create_sparse_variable_for_type_inference	append_op)
r   r(   r)   r*   r   
dtype_flagr;   op_typehelperr6   s
             r   sumrE      s   v J
*51  %99<D6D'BLLaggEBC  	
 	&3eT$ZBL	
 W%BBBOCBBgg C C 	#qE3<u 	 	
 
r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )a]  
Calculate elementwise atan of SparseTensor, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = atan(x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.atan(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[-1.10714877,  0.78539819])
r   )r
   r   sparse_atanr   s     r   atanrH   4  r"   r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )a]  
Calculate elementwise sinh of SparseTensor, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = sinh(x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.sinh(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[-3.62686038,  1.17520118])
r   )r
   r   sparse_sinhr   s     r   sinhrK   W  r"   r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )a`  
Calculate elementwise asinh of SparseTensor, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = asinh(x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.asinh(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[-1.44363546,  0.88137358])
r   )r
   r   sparse_asinhr   s     r   asinhrN   z  0    : "## F# q!!r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )aR  
Calculate elementwise atanh of SparseTensor, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = atanh(x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.atanh(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[nan , inf.])
r   )r
   r   sparse_atanhr   s     r   atanhrR     rO   r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )a]  
Calculate elementwise tanh of SparseTensor, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = tanh(x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.tanh(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[-0.96402758,  0.76159418])
r   )r
   r   sparse_tanhr   s     r   tanhrU     r"   r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )aQ  
Calculate elementwise square of SparseTensor, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = square(x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.square(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[4., 1.])
r   )r
   r   sparse_squarer   s     r   squarerX     s0    : "## F# ""r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )a6  
Calculate elementwise sqrt of SparseTensor, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = sqrt(x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.sqrt(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[nan, 1. ])
r   )r
   r   sparse_sqrtr   s     r   sqrtr[     r"   r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )ab  
Calculate the natural log of (1+x), requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = ln(1+x)

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2, 0, 1], dtype='float32')
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.log1p(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[nan       , 0.69314718])
r   )r
   r   sparse_log1pr   s     r   log1pr^   )  rO   r   c                   [        5       (       d   S5       eU(       aD  [        U[        R                  R                  [        R
                  45      (       d  [        U5      nU(       aD  [        U[        R                  R                  [        R
                  45      (       d  [        U5      n[        R                  " XU5      $ )a  
cast non-zero-index of SparseTensor to `index_dtype`, non-zero-element of SparseTensor to
`value_dtype` , requiring x to be a SparseCooTensor or SparseCsrTensor.

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64.
    index_dtype (np.dtype|str, optional): Data type of the index of SparseCooTensor,
        or crows/cols of SparseCsrTensor. Can be uint8, int8, int16, int32, int64.
    value_dtype (np.dtype|str, optional): Data type of the value of SparseCooTensor,
        SparseCsrTensor. Can be bool, float16, float32, float64, int8, int32, int64, uint8.
    name (str|core.VarDesc.VarType|core.DataType|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2, 0, 1])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.cast(sparse_x, 'int32', 'float64')
        >>> out
        Tensor(shape=[3], dtype=paddle.float64, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[-2.,  1.])
r   )	r
   
isinstancer	   VarDescVarTypeDataTyper   r   sparse_cast)r   index_dtypevalue_dtyper   s       r   castrg   L  s    F "## F# :dll**DMM:  1=:dll**DMM:  1=ak::r   c                n    [        5       (       d   S5       e[        R                  " U [        U5      5      $ )ab  
Calculate elementwise pow of x, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = x^{factor}

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64.
    factor (float|int): factor of pow.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2, 0, 3], dtype='float32')
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.pow(sparse_x, 2)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[4., 9.])
r   )r
   r   
sparse_powfloat)r   factorr   s      r   powrl   }  s6    < "## F# Qf..r   c                `    [        5       (       d   S5       e[        R                  " U SSS5      $ )a7  
Calculate elementwise negative of x, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = -x

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2, 0, 3], dtype='float32')
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.neg(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[ 2., -3.])
r   g              T)r
   r   sparse_scaler   s     r   negrp     s6    : "## F# q$T22r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )aS  
Calculate elementwise absolute value of x, requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = |x|

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2, 0, 3], dtype='float32')
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.abs(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[2., 3.])
r   )r
   r   
sparse_absr   s     r   absrs     r   r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )a  
the coalesced operator include sorted and merge, after coalesced, the indices of x is sorted and unique.

Parameters:
    x (Tensor): the input SparseCooTensor.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: return the SparseCooTensor after coalesced.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> indices = [[0, 0, 1], [1, 1, 2]]
        >>> values = [1.0, 2.0, 3.0]
        >>> sp_x = paddle.sparse.sparse_coo_tensor(indices, values)
        >>> sp_x = paddle.sparse.coalesce(sp_x)
        >>> print(sp_x.indices())
        Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
        [[0, 1],
         [1, 2]])
        >>> print(sp_x.values())
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [3., 3.])
r   )r
   r   sparse_coalescer   s     r   coalescerv     s0    : "## F# !!!$$r   c                   [        5       (       d   S5       eU R                  [        ;   a:  [        R                  " U S[
        R                  R                  R                  5      n [        R                  " U S[        R                  -  SS5      $ )a  
Convert each of the elements of input x from radian to degree,
requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    rad2deg(x) = 180/ \pi * x

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, int32, int64.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([3.142, 0., -3.142])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.rad2deg(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[ 180.02334595, -180.02334595])
r   N     f@rn   Tr
   r)   _int_dtype_r   rd   r	   ra   rb   FP32ro   nppir   s     r   rad2degr~   
  sn    < "## F# 	ww+q$(<(<(A(ABq%"%%-d;;r   c                   [        5       (       d   S5       eU R                  [        ;   a:  [        R                  " U S[
        R                  R                  R                  5      n [        R                  " U [        R                  S-  SS5      $ )ax  
Convert each of the elements of input x from degree to radian,
requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    deg2rad(x) = \pi * x / 180

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, int32, int64.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-180, 0, 180])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.deg2rad(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[-3.14159274,  3.14159274])
r   Nrx   rn   Try   r   s     r   deg2radr   0  sn    < "## F# 	ww+q$(<(<(A(ABq"%%%-d;;r   c                Z    [        5       (       d   S5       e[        R                  " U 5      $ )aX  
Calculate elementwise `exp(x)-1` , requiring x to be a SparseCooTensor or SparseCsrTensor.

.. math::

    out = exp(x) - 1

Parameters:
    x (Tensor): The input Sparse Tensor with data type float32, float64, complex64, complex128.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same data type and shape as ``x`` .

Examples:
    .. code-block:: python

        >>> import paddle

        >>> dense_x = paddle.to_tensor([-2., 0., 1.])
        >>> sparse_x = dense_x.to_sparse_coo(1)
        >>> out = paddle.sparse.expm1(sparse_x)
        >>> out
        Tensor(shape=[3], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
            indices=[[0, 2]],
            values=[-0.86466473,  1.71828187])
r   )r
   r   sparse_expm1r   s     r   expm1r   V  rO   r   inputc                $   [        5       (       a  [        R                  " X5      $ [        U S/ SQS5        [	        US[
        [        4S5        SU 0nSU0n[        S5      nUR                  U R                  5      nUR                  SUSU0US9  U$ )aF  
Changes the shape of ``x`` without changing its value, requiring x to be a SparseCooTensor or SparseCsrTensor.
Currently this function can only reshape the sparse dims of ``x`` , but ``shape`` argument must be specified
as the shape of the reshaped tensor.

Note that if x is a SparseCsrTensor, then len(shape) must be 2 or 3.

There are some tricks when specifying the target shape.

    - 1. -1 means the value of this dimension is inferred from the total element number of x and remaining dimensions. Thus one and only one dimension can be set -1.

    - 2. 0 means the actual dimension value is going to be copied from the corresponding dimension of x. The indices of 0 in the target shape can not exceed the rank of x.

Here are some examples to explain it.

    - 1. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape is [6, 8], the reshape operator will transform x into a 2-D tensor with shape [6, 8] and leaving x's data unchanged.

    - 2. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape is [2, 3, -1, 2], the reshape operator will transform x into a 4-D tensor with shape [2, 3, 4, 2] and leaving x's data unchanged. In this case, one dimension of the target shape is set to -1, the value of this dimension is inferred from the total element number of x and remaining dimensions.

    - 3. Given a 3-D tensor x with a shape [2, 4, 6], and the target shape is [-1, 0, 3, 2], the reshape operator will transform x into a 4-D tensor with shape [2, 4, 3, 2] and leaving x's data unchanged. In this case, besides -1, 0 means the actual dimension value is going to be copied from the corresponding dimension of x.

.. note::
    Alias Support: The parameter name ``input`` can be used as an alias for ``x``.
    For example, ``reshape(input=tensor_x, ...)`` is equivalent to ``reshape(x=tensor_x, ...)``.

Args:
    x (Tensor): The input sparse tensor with data type ``float32``, ``float64``, ``int32``, ``int64`` or ``bool``.
    shape (list|tuple): Define the target shape. At most one dimension of the target shape can be -1.
                    The data type is ``int32``.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: A reshaped Tensor with the same data type as ``x``.

Examples:
    .. code-block:: pycon

        >>> import paddle

        >>> x_shape = [6, 2, 3]
        >>> new_shape = [1, 0, 2, -1, 3]
        >>> format = "coo"

        >>> dense_x = paddle.randint(-100, 100, x_shape) * paddle.randint(0, 2, x_shape)

        >>> if format == "coo":
        ...     sp_x = dense_x.to_sparse_coo(len(x_shape))
        >>> else:
        ...     sp_x = dense_x.to_sparse_csr()
        >>> sp_out = paddle.sparse.reshape(sp_x, new_shape)

        >>> print(sp_out.shape)
        paddle.Size([1, 2, 2, 3, 3])

r   )float16r/   r0   r1   r2   r3   r.   uint16reshapeshapesparse_reshaper6   r7   )r
   r   r   r   r   r>   r?   r   r@   r)   rA   )r   r   r   r9   r;   rD   r6   s          r   r   r   y  s    t $$Q.. 	 	
 	5'D%=)<q% -.>>qwwG!CL	 	 	
 
r   c                    [        5       (       a  [        R                  " U 5      $ Sn[        U5      nUR	                  U R
                  5      nUR                  USU 0SU00 S9  U$ )a+  

Return whether every element of input tensor is `NaN` or not, requiring x to be a SparseCooTensor or SparseCsrTensor.

Args:
    x (Tensor): The input tensor (SparseCooTensor or SparseCsrTensor), it's data type should be float16, float32, float64, int32, int64.
    name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Returns:
    A Sparse Tensor with the same shape as ``x``,  the bool result which shows every element of `x` whether it is `NaN` or not.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> import numpy as np

        >>> format = "coo"
        >>> np_x = np.asarray([[[0., 0], [1., 2.]], [[0., 0], [3., float('nan')]]])
        >>> dense_x = paddle.to_tensor(np_x)

        >>> if format == "coo":
        ...     sparse_x = dense_x.to_sparse_coo(len(np_x.shape))
        >>> else:
        ...     sparse_x = dense_x.to_sparse_csr()
        ...
        >>> sparse_out = paddle.sparse.isnan(sparse_x)
        >>> print(sparse_out)
        Tensor(shape=[2, 2, 2], dtype=paddle.bool, place=Place(gpu:0), stop_gradient=True,
               indices=[[0, 0, 1, 1],
                        [1, 1, 1, 1],
                        [0, 1, 0, 1]],
               values=[False, False, False, True ])

sparse_isnanr   r6   r7   )r
   r   r   r   r@   r)   rA   )r   r   rC   rD   r6   s        r   isnanr     sm    H ""1%% W%>>qwwG#qE3<r 	 	
 
r   c                   [        5       (       a  [        R                  " XX#5      $ XUS.n[        U S/ SQS5        [	        US[
        [        4S5        [	        US[
        [        4S5        [	        US[
        [        4S5        Sn[        U5      nUR                  U R                  S9nUR                  USU 0S	U0US
9  U$ )ab
  
This operator produces a slice of ``x`` along multiple axes for sparse tensors.
Slice uses ``axes``, ``starts`` and ``ends`` attributes to specify the start and
end dimension for each axis in the list of axes and Slice uses this information
to slice the input sparse tensor (x). If a negative value is passed to
``starts`` or ``ends`` such as :math:`-i`, it represents the reverse position of
the axis :math:`i-1` (here 0 is the initial position).
If the value passed to ``starts`` or ``ends`` is greater than the number of elements
in the dimension (n), it represents n.
For slicing to the end of a dimension with unknown size, it is recommended to pass
in INT_MAX. The size of ``axes`` must be equal to ``starts`` and ``ends``.

Args:
    x (Tensor): The input Tensor (``SparseCooTensor`` or ``SparseCsrTensor``), it's data type should be ``float16``, ``float32``, ``float64``, ``int32``, ``int64``.
    axes (list|tuple|Tensor): The data type is ``int32``.If ``axes`` is a list or tuple, the elements of
            it should be integers or a 0-D Tensor with shape []. If ``axes`` is a Tensor, it should be a 1-D Tensor.
            Axes that `starts` and `ends` apply to.
    starts (list|tuple|Tensor): The data type is ``int32``. If ``starts`` is a list or tuple, the elements of
            it should be integers or a 0-D Tensor with shape []. If ``starts`` is a Tensor, it should be a 1-D Tensor.
            It represents starting indices of corresponding axis in ``axes``.
    ends (list|tuple|Tensor): The data type is ``int32``. If ``ends`` is a list or tuple, the elements of
            it should be integers or a 0-D Tensor with shape []. If ``ends`` is a Tensor, it should be a 1-D Tensor.
            It represents ending indices of corresponding axis in ``axes``.

Returns:
    A Sparse Tensor. The data type is same as ``x``.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> import numpy as np

        >>> format = 'coo'
        >>> np_x = np.asarray([[4, 0, 7, 0], [0, 0, 5, 0], [-4, 2, 0, 0]])
        >>> dense_x = paddle.to_tensor(np_x)
        >>> if format == 'coo':
        ...     sp_x = dense_x.to_sparse_coo(len(np_x.shape))
        >>> else:
        ...     sp_x = dense_x.to_sparse_csr()
        ...
        >>> axes = [0, 1]
        >>> starts = [1, 0]
        >>> ends = [3, -2]
        >>> sp_out = paddle.sparse.slice(sp_x, axes, starts, ends)
        >>> # sp_out is x[1:3, 0:-2]

        >>> print(sp_out)
        Tensor(shape=[2, 2], dtype=paddle.int64, place=Place(cpu), stop_gradient=True,
               indices=[[1, 1],
                        [0, 1]],
               values=[-4,  2])

)axesstartsendsr   r-   sparse_slicer   r   r   r5   r6   r7   )r
   r   r   r   r   r>   r?   r   r@   r)   rA   )	r   r   r   r   r   r;   rC   rD   r6   s	            r   slicer     s    z ""1F99>  	
 	4$?68dE]NC4$? W%>>QWW>M#qE3<u 	 	
 
r   c           	     l  ^^^^ S nS mS mUU4S jmSUUU4S jjmSUUUU4S	 jjn[         R                  " U 5      (       d  [        S
[        U 5       35      eU R	                  5       (       d  [        S5      e[         R
                  R                  5       nUb'  US:X  d!  [        UR                  S5      S   5      S:  a  [        S5      eU R                  SS u  pUc  [        SX5      nO/US:  a  U[        X5      ::  d  [        SU S[        X5       35      eUS:  d  [        SU S35      eU" U 5      n
U(       d  U" XUSS9$ [        U R                  5      S:w  a  [        S5      e[         R                  R                  U SS9nUR                  5       U-  n[         R                  R                  UR!                  5       XR"                  UR$                  S9nUR!                  5       S   n[         R&                  " S[        U5      4UR"                  S9nXS'   [         R                  R                  XR                  5       U	S4XR$                  S9n[         R(                  " / U R                  SS QSPUPU
S9nT" [         R*                  " UR-                  5       U5      5      nU" XUUS9$ )aN  
Performs linear Principal Component Analysis (PCA) on a sparse matrix.

Let :math:`X` be the input matrix or a batch of input matrices, the output should satisfies:

.. math::
    X = U * diag(S) * V^{T}

Args:
    x (Tensor): The input tensor. Its shape should be `[N, M]`,
        N and M can be arbitrary positive number.
        The data type of x should be float32 or float64.
    q (int|None, optional): a slightly overestimated rank of :math:`X`.
        Default value is :math:`q=min(6,N,M)`.
    center (bool, optional): if True, center the input tensor.
        Default value is True.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    - Tensor U, is N x q matrix.
    - Tensor S, is a vector with length q.
    - Tensor V, is M x q matrix.

    tuple (U, S, V): which is the nearly optimal approximation of a singular value decomposition of a centered matrix :math:`X`.

Examples:
    .. code-block:: python

        >>> # doctest: +REQUIRES(env:GPU)
        >>> import paddle
        >>> paddle.device.set_device('gpu')

        >>> format = "coo"
        >>> paddle.seed(2023)
        >>> dense_x = paddle.randn((5, 5), dtype='float64')

        >>> if format == "coo":
        ...     sparse_x = dense_x.to_sparse_coo(len(dense_x.shape))
        >>> else:
        ...     sparse_x = dense_x.to_sparse_csr()

        >>> print("sparse.pca_lowrank API only support CUDA 11.x")
        >>> # U, S, V = None, None, None
        >>> # use code blow when your device CUDA version >= 11.0
        >>> U, S, V = paddle.sparse.pca_lowrank(sparse_x)

        >>> print(U)
        Tensor(shape=[5, 5], dtype=float64, place=Place(gpu:0), stop_gradient=True,
               [[-0.31412600,  0.44814876,  0.18390454, -0.19967630, -0.79170452],
                [-0.31412600,  0.44814876,  0.18390454, -0.58579808,  0.56877700],
                [-0.31412600,  0.44814876,  0.18390454,  0.78547437,  0.22292751],
                [-0.38082462,  0.10982129, -0.91810233,  0.00000000,  0.00000000],
                [ 0.74762770,  0.62082796, -0.23585052,  0.00000000, -0.00000000]])

        >>> print(S)
        Tensor(shape=[5], dtype=float64, place=Place(gpu:0), stop_gradient=True,
               [1.56031096, 1.12956227, 0.27922715, 0.00000000, 0.00000000])

        >>> print(V)
        Tensor(shape=[5, 5], dtype=float64, place=Place(gpu:0), stop_gradient=True,
               [[ 0.88568469, -0.29081908,  0.06163676,  0.19597228, -0.29796422],
                [-0.26169364, -0.27616183,  0.43148760, -0.42522796, -0.69874939],
                [ 0.28587685,  0.30695344, -0.47790836, -0.76982533, -0.05501437],
                [-0.23958121, -0.62770647, -0.71141770,  0.11463224, -0.17125926],
                [ 0.08918713, -0.59238761,  0.27478686, -0.41833534,  0.62498824]])
c                    U R                   nU[        R                  [        R                  [        R                  4;   a  U$ [        R                  $ N)r)   paddler   r/   r0   )r   r)   s     r   get_floating_dtype'pca_lowrank.<locals>.get_floating_dtype  s5    V^^V^^V^^DDL~~r   c                P    U R                  5       (       a  U R                  5       $ U $ r   )
is_complexconj)r   s    r   	conjugatepca_lowrank.<locals>.conjugate  s    <<>>668Or   c                   U R                   n[        [        S[        U5      5      5      n/ US S QUS   PUS   PnU R	                  5       (       a  [
        R                  R                  X5      $ [
        R                  " X5      $ )Nr   )r   r>   rangelen	is_sparser   sparser&   )r   r   r%   s      r   r&   pca_lowrank.<locals>.transpose  ss    E!SZ()/cr/DH/d2h/;;====**133((r   c                    > T" T" U 5      5      $ r    )r   r   r&   s    r   transjugate pca_lowrank.<locals>.transjugate  s    1&&r      Nc                  > Uc  SOUnU R                   SS  u  pE[        R                  R                  n[        R                  " XQ4U R
                  S9nT" U 5      nT" U5      n	Uc  U" [        R                  R                  X5      5      S   n
[        U5       HS  nU" [        R                  R                  X5      5      S   n
U" [        R                  R                  X
5      5      S   n
MU     U
$ T" U5      nU" [        R                  R                  X5      [        R                  " X75      -
  5      S   n
[        U5       H  nU" [        R                  R                  X5      [        R                  " X5      -
  5      S   n
U" [        R                  R                  X
5      [        R                  " X:5      -
  5      S   n
M     U
$ )Nr   r   r5   r   )	r   r   linalgqrrandnr)   r   matmulr   )r   qniterMmnr   RA_tA_HQiM_Hr   r   r&   s                r   get_approximate_basis*pca_lowrank.<locals>.get_approximate_basis  sn   ]wwrs|]]LL!qww/ln96==''-.q1A5\v}}++C34Q7v}}++A1215 "  a.C6==''-a0CCDQGA5\v}}++C3fmmC6KKLQOv}}++A1FMM!4GGHK " r      c                  > Uc  SOUnU R                   SS  u  pEUc  S nOT" U5      nT" U 5      nXE:  d  XQ:  Ga!  T" XqX&S9nT" U5      n	Uc   [        R                  R                  X	5      n
O6[        R                  R                  X	5      [        R                  " X95      -
  n
U
R                   S   U:X  d   U
R                   U45       eU
R                   S   U:X  d   U
R                   U45       eU
R                   S   U
R                   S   ::  d   U
R                   5       e[        R                  R                  U
SS9u  pnT" U5      nUR                  U5      nGO'T" XX#S9nT" U5      n	Uc   [        R                  R                  Xy5      nO6[        R                  R                  Xy5      [        R                  " Xi5      -
  nT" U5      n
U
R                   S   U:X  d   U
R                   U45       eU
R                   S   U:X  d   U
R                   U45       eU
R                   S   U
R                   S   ::  d   U
R                   5       e[        R                  R                  U
SS9u  pnT" U5      nUR                  U5      nXU4$ )Nr   r   r   r   r   F)full_matrices)r   r   r   r   r   svd)r   r   r   r   r   r   M_tr   r   Q_cB_tUSVhVBr   r   r   r&   s                   r   svd_lowrank pca_lowrank.<locals>.svd_lowrank  s6   Awwrs|9CA,Cl5AE%cEAAA,Cymm**12mm**12V]]15JJ99R=A%5		1~5%99R=A%5		1~5%99R=CIIbM1<399<1}}((E(BHA"BAA%a%=AA,CyMM((2MM((2V]]35LLA,C99R=A%5		1~5%99R=A%5		1~5%99R=CIIbM1<399<1}}((E(BHA"BAAQwr   zInput must be tensor, but got z#Input must be sparse, but got denseFalse.r      z-sparse.pca_lowrank API only support CUDA 11.xr   zq(=z>) must be non-negative integer and not greater than min(m, n)=zniter(=z) must be non-negative integerr   z,input is expected to be 2-dimensional tensor)r(   )r)   placer5      )r   N)r   r   N)r   	is_tensor
ValueErrorr8   r   versioncudar=   splitr   minr   r   rE   valuessparse_coo_tensorindicesr)   r   zerosonesr   to_dense)r   r   centerr   r   r   r   cuda_versionr   r   r)   s_sums_valccolumn_indicesr   C_t	ones_m1_tr   r   r   r   r&   s                      @@@@r   pca_lowrankr   _  s{   V
)' .% %N A9$q'CDD;;==>??>>&&(L7"|!!#&q)*R/HIIWWRS\FQy1L1fc!i! //21yk;
 	
 QJ75')GHIIq!E1u55
177|qGHH MMab)ELLNQE''kk 	( 	A YY[^NllAs>23>;O;OPGAJ
--
)
)aV5 * C 1aggcrl1A1q1?I&--	:;Aq5A..r   r   )r   r   r   
str | Nonereturnr   )r   r   r%   zSequence[int]r   r   r   r   )NNFN)r   r   r(   zint | Sequence[int] | Noner)   DTypeLike | Noner*   r.   r   r   r   r   )NNN)
r   r   re   r   rf   r   r   r   r   r   )r   r   rk   rj   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   )Sequence[int] | Sequence[Tensor] | Tensorr   r   r   r   r   r   r   r   )NTr   N)r   r   r   z
int | Noner   r.   r   r=   r   r   r   ztuple[Tensor, Tensor, Tensor])>
__future__r   typingr   numpyr|   r   r   paddle.base.data_feederr   r   paddle.base.frameworkr   r	   r
   paddle.common_ops_importr   paddle.frameworkr   paddle.utils.decorator_utilsr   collections.abcr   r   paddle._typingr   r   __all__ra   rb   UINT8INT8INT16INT32INT64BOOLrz   r   r   r!   r&   rE   rH   rK   rN   rR   rU   rX   r[   r^   rg   rl   rp   rs   rv   r~   r   r   r   r   r   r   r   r   r   <module>r      s   #      H 
 . ( (3
 	LLLLLLLLLLLL  F  F !H 8<',',"',*4',',X (,"ii
$i i 	i
 i iX !F !F "F "F !F #F !F "J %)$(	.;.;!.; ".; 	.;
 .;b!/H 3F  F %F#<L#<L "F #w X !Xv-j WW
3W 6W 4	W
 W Wx P/P/P/ P/ 	P/
 P/ #P/r   