
    Αi                       S SK Jr  S SKJrJrJrJr  S SKJr  S SK	r	S SK	J
r
  S SKJr  S SKJr  S SKJr  S S	KJr  S
SKJr  S
SKJrJrJrJrJr  S
SKJr  \(       a  S SKJr  S SK	Jr  / SQr S r!\	RD                  \	RF                  \	RH                  \	RJ                  \	RL                  \	RN                  \	RP                  \	RR                  \	RT                  \	RV                  /
r,\,u
  r-r.r/r0r1r2r3r4r5r6\-\/\/\0\1\2\3\4\-\6/
\/\.\/\0\1\2\3\4\.\6/
\/\/\/\0\1\2\3\4\/\6/
\0\0\0\0\1\2\3\4\0\6/
\1\1\1\1\1\2\3\4\1\6/
\2\2\2\2\2\2\3\4\2\3/
\3\3\3\3\3\3\3\4\3\3/
\4\4\4\4\4\4\4\4\4\4/
\-\.\/\0\1\2\3\4\5\6/
\6\6\6\6\6\3\3\4\6\6/
/
r7\8" \,5       V VVVs0 s H!  u  p\8" \,5        H  u  p#X4\7U    U   _M     M#     snnnn r9\" SS1SSS9      SAS j5       r: " S S\5      r;\" SS1SSS9  SBSS.         SCS jjj5       r<\" SS1SS S9  SBSS.         SCS! jjj5       r=SDS" jr> " S# S$\5      r?SES% jr@SFS& jrASFS' jrB\" SS1S(S)S9SS.         SGS* jj5       rC\" SS1S+S,S9SS.         SGS- jj5       rD " S. S/\5      rESHSIS0 jjrF " S1 S2\5      rG\" SS1S3S4S9    SJ         SKS5 jj5       rH\    SL           SMS6 jj5       rI\    SL           SNS7 jj5       rI\    SL           SOS8 jj5       rI\    SL           SPS9 jj5       rI\" SS1S:S;S9    SQS< j5       rI\" 1 S=kS>S?S9 SR       SSS@ jj5       rJgs  snnnn f )T    )annotations)TYPE_CHECKINGAnyLiteral
NamedTuple)overloadN)_C_ops)core)Variable)in_dynamic_mode)ForbidKeywordsDecorator   )nn)disable_torch_proxyenable_torch_proxy"extend_torch_proxy_blocked_modulespaddle_triton_funuse_torch_proxy_guard)_check_out_status)Sequence)Tensor)
equalslogdetsortsplitminmaxuniquemedian	nanmedianseedc                $    U S:X  a
  [        5       $ g )Npaddle_triton)r   )names    V/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/compat/__init__.py__getattr__r&   ;   s     ""     xyzpaddle.compat.equalzpaddle.equal)illegal_keys	func_namecorrect_namec                   U R                   UR                   :X  a$  [        R                  " X5      R                  5       $ [        R                  U R                   UR                   5      nU R                   U:w  a  U R                  U5      n UR                   U:w  a  UR                  U5      n[        R                  " X5      R                  5       $ )a`  

``True`` if two tensors have the same size and elements, ``False`` otherwise.

Note:
    Tensors containing NaNs are never equal to each other. Additionally, this function does not differentiate between the data types of the tensors during comparison.

Args:
    input (Tensor): Tensor, data type is bool, float16, float32, float64, uint8, int8, int16, int32, int64, complex64, complex128.
    other (Tensor): Tensor, data type is bool, float16, float32, float64, uint8, int8, int16, int32, int64, complex64, complex128.

Returns:
    Bool: ``True`` if two tensors have the same size and elements, ``False`` otherwise.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([1, 2, 3])
        >>> y = paddle.to_tensor([1, 3, 2])
        >>> result1 = paddle.compat.equal(x, y)
        >>> print(result1)
        False
)dtypepaddle	equal_allitemPROMOTE_DICTgetcast)inputothercommon_dtypes      r%   r   r   b   s    D {{ekk!-2244##EKK=L{{l"

<({{l"

<(E)..00r'   c                  *    \ rS rSr% S\S'   S\S'   Srg)MedianRetType   r   valuesindices N__name__
__module____qualname____firstlineno____annotations____static_attributes__r=   r'   r%   r9   r9          NOr'   r9   axiszpaddle.compat.medianzpaddle.medianoutc                  Uc?  [        US5        [        R                  " XUSS9nUb  [        R                  " XC5        U$ U$ [        US5        [        R                  " XUSUS9u  pVUb  [	        US   US   S9$ [	        XVS9$ )	a  
Returns the median of the values in input.

Args:
    input (Tensor): The input tensor.
    dim (int|None, optional): The dimension to reduce. If None, computes the median over all elements. Default is None.
    keepdim (bool, optional): Whether the output tensor has dim retained or not. Default is False.
    out (Tensor|tuple[Tensor, Tensor], optional): If provided, the result will be written into this tensor.
        For global median (dim=None), out must be a single tensor.
        For median along a dimension (dim specified, including dim=-1), out must be a tuple of two tensors (values, indices).

Returns:
    Tensor|MedianRetType: If dim is None, returns a single tensor. If dim is specified (including dim=-1),
    returns a named tuple MedianRetType(values: Tensor, indices: Tensor).

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        >>> result = paddle.compat.median(x)
        >>> print(result)
        Tensor(shape=[], dtype=int64, place=Place(cpu), stop_gradient=True, 5)

        >>> ret = paddle.compat.median(x, dim=1)
        >>> print(ret.values)
        Tensor(shape=[3], dtype=int64, place=Place(cpu), stop_gradient=True, [2, 5, 8])
        >>> print(ret.indices)
        Tensor(shape=[3], dtype=int64, place=Place(cpu), stop_gradient=True, [1, 1, 1])

        >>> # Using out parameter
        >>> out_values = paddle.zeros([3], dtype='int64')
        >>> out_indices = paddle.zeros([3], dtype='int64')
        >>> paddle.compat.median(x, dim=1, out=(out_values, out_indices))
        >>> print(out_values)
        Tensor(shape=[3], dtype=int64, place=Place(cpu), stop_gradient=True, [2, 5, 8])
Fr   rF   keepdimmodeT)rF   rK   rL   rH   r   r   r;   r<   )r   r/   r   assignr9   r5   dimrK   rH   resultr;   r<   s          r%   r   r      s    d {#u%ueL?MM&&J#t$ --W5c
 ? AA??F<<r'   zpaddle.compat.nanmedianzpaddle.nanmedianc                  Uc?  [        US5        [        R                  " XUSS9nUb  [        R                  " XC5        U$ U$ [        US5        [        R                  " XUSS9u  pV[        R                  " U[        R
                  " U5      5      nUbB  [        R                  " XSS   5        [        R                  " XcS   5        [        US   US   S9$ [        XVS9$ )aW  
Returns the median of the values in input, ignoring NaN values.

Args:
    input (Tensor): The input tensor.
    dim (int|None, optional): The dimension to reduce. If None, computes the nanmedian over all elements. Default is None.
    keepdim (bool, optional): Whether the output tensor has dim retained or not. Default is False.
    out (Tensor|tuple[Tensor, Tensor], optional): If provided, the result will be written into this tensor.
        For global nanmedian (dim=None), out must be a single tensor.
        For nanmedian along a dimension (dim specified, including dim=-1), out must be a tuple of two tensors (values, indices).

Returns:
    Tensor|MedianRetType: The median values, ignoring NaN. If dim is None, returns a single tensor. If dim is specified (including dim=-1),
    returns a named tuple MedianRetType(values: Tensor, indices: Tensor).

Examples:
    .. code-block:: python

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

        >>> x = paddle.to_tensor([[1, float('nan'), 3], [4, 5, 6], [float('nan'), 8, 9]], dtype='float32')
        >>> result = paddle.compat.nanmedian(x)
        >>> print(result)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True, 5.0)

        >>> ret = paddle.compat.nanmedian(x, dim=1)
        >>> print(ret.values)
        Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, [1.0, 5.0, 8.0])
        >>> print(ret.indices)
        Tensor(shape=[3], dtype=int64, place=Place(cpu), stop_gradient=True, [0, 1, 1])

        >>> # Using out parameter
        >>> out_values = paddle.zeros([3], dtype='float32')
        >>> out_indices = paddle.zeros([3], dtype='int64')
        >>> paddle.compat.nanmedian(x, dim=1, out=(out_values, out_indices))
        >>> print(out_values)
        Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, [1.0, 5.0, 8.0])
Fr   rJ   Tr   r   rM   )r   r/   r    rN   maximum
zeros_liker9   rO   s          r%   r    r       s    f {#u%!!%7O?MM&&J#t$ **W5

 ..&*;*;G*DE?MM&a&)MM'q6* AA??F<<r'   c                 x    [         R                  " 5       R                  5       n [        R                  " U 5        U $ )a3  Sets the seed for generating random numbers to a non-deterministic
random number on all devices. Returns a 64 bit number used to seed the RNG.
Returns:
    Returns: int64, the seed used to seed the RNG.
Examples:
    .. code-block:: python

        >>> import paddle
        >>> seed = paddle.compat.seed()
)r
   default_cpu_generatorr!   r/   )r!   s    r%   r!   r!   "  s,     %%',,.D
KKKr'   c                  *    \ rS rSr% S\S'   S\S'   Srg)MinMaxRetTypei2  r   r;   r<   r=   Nr>   r=   r'   r%   rX   rX   2  rE   r'   rX   c                  ^ ^^^ SUU U4S jjmUU4S jnS nSn[        T5      nU[        T5      -   nUS:  a  T" 5       eUS:X  ai  US:X  a  Tu  pEO$US:X  a  TS   nU" S5      nOU" S5      nU" S5      nUb/  [        U[        [        R                  R
                  45      (       a  T" 5       eOjUS:X  ad  U(       a  TS   nOMST;   a  TS   nOAS	T;   a;  TS	   n[        U[        [        R                  R
                  45      (       d  T" 5       eUc  T" 5       eUbY  [        U[        [        R                  R
                  45      (       d*  [        U5      [        La  T" S
T  S[        U5       S35      eXE4$ )Nc                X  > T Vs/ s H  n[        U5      R                  PM     nnUR                  TR                  5        VVs/ s H  u  p1U S[        U5      R                   3PM!     snn5        SR	                  U5      nST SU  SU ST ST S3n[        U5      $ s  snf s  snnf )	N=, z%Invalid arguments for `paddle.compat.z`:
zGot: (paddle.Tensor input, z;), but expect one of:
 - (input: paddle.Tensor) for reduce_zL on all dims.
 - (input: paddle.Tensor, other: paddle.Tensor) -> see paddle.zOimum
 - (input: paddle.Tensor, int dim (cannot be None), bool keepdim = False)
)typer?   extenditemsjoin	TypeError)	error_prefixv	type_strsk	signature	error_msgargsr+   kwargss	         r%   invalid_arguments_exception;_min_max_param_checker.<locals>.invalid_arguments_exception8  s    /34t!T!W%%t	4OQCqa!1!1 23OPIIi(	 4I;d<.)) 544=; ?MMVK XZ[ 	 ## 5Os   B!&B&
c                D   > S n TU    nU$ ! [          a	    T" 5       S ef = fN)KeyError)keyresrj   ri   s     r%   try_get_keys,_min_max_param_checker.<locals>.try_get_keysF  s9    	:+C 
  	:-/T9	:s    F   r   r   rK   rP   r6   zBThe second input must be int or Tensor or implicit None in compat.z, but received z.
) )len
isinstancer   r/   pirValuer]   int)	r+   rh   ri   rq   dim_or_otherrK   num_argstotal_arg_numrj   s	   ```     @r%   _min_max_param_checkerr}   7  s   $ $ LG4yHs6{*Mq)++	!	q=$(!L']7L"9-G'.L"9-G:8VZZ%5%56$
 $
 .//$
 
!	7L%e}F"%g!,6::;K;K0LMM577-// 	 <(FJJ4D4D)EFFc))PQZP[[jkop|k}j~  B  C
 	
   r'   c                    U R                   nU[        R                  :X  d<  U[        R                  :X  d(  U[        R                  :X  d  U[        R
                  :X  a!  U R                  (       d  [        SU S35      egg)z@Prevent integral input tensor type to have `stop_gradient=False`zTensors with integral type: 'z' should stop gradient.N)r.   r/   int32int64uint8int16stop_gradientra   r5   in_dtypes     r%   _min_max_tensor_allow_gradr   {  sh    {{HFLL v||#v||#v||#""/z9PQ  # $r'   c                    U R                   nU[        R                  :X  d(  U[        R                  :X  d  U[        R                  :X  a  [        SU S35      eg)zPpaddle.min/argmin(max/argmax), paddle.take_along_axis reject the following typesz*Non-CUDA GPU placed Tensor does not have 'zZ' op registered.
Paddle support following DataTypes: int32, int64, float64, float32, uint8N)r.   r/   float16bfloat16r   ra   r   s     r%   _min_max_allow_cpu_compositer     sU    {{HFNN"v&v||#8
 CX X
 	
 $r'   zpaddle.compat.minz
paddle.minc          	        [        U [        R                  R                  [        R                  45      (       d"  [        S[        U 5      R                   S35      e[        U 5        [        S/UQ70 UD6u  pESnUc$  [        US5        [        R                  " U 5      nGOP[        U[        5      (       Ga  [        US5        U R                  (       a  [        5       (       a  U R                  R!                  5       (       dk  [#        U 5        [        R$                  " XSS9n[        R&                  " XUS9nU(       a
  [)        XS	9nO[)        UR+                  US9UR+                  US9S	9nO[,        R.                  " XUS5      u  pSU
l        [)        XS	9nOY[)        U [        R2                  " / [        R4                  U R                  S
9S	9nO"[        US5        [,        R6                  " X5      nUbu  [        U[(        5      (       aJ  [        R8                  " UR:                  US   5        [        R8                  " UR<                  US   5        U$ [        R8                  " Xa5        U$ )a  

Computes the minimum of tensor elements. There are mainly 3 cases (functionalities):

1. paddle.compat.min(input: Tensor): reduce min over all dims, return a single value Tensor
2. paddle.compat.min(input: Tensor, dim: int (cannot be None), keepdim=False): reduce min over the given dim,
    returns a named tuple MinMaxRetType(values: Tensor, indices: Tensor)
3. paddle.compat.min(input: Tensor, other: Tensor): see `paddle.minimum`

Special warning: the gradient behavior is NOT well-documented by PyTorch, the actual behavior should be:

1. Case 1: the same as `min`
2. Case 2: NOT evenly distributing the gradient for equal minimum elements! PyTorch actually only propagates to the elements with indices,
    for example: Tensor([1, 1, 1]) -> min(..., dim=0) -> values=Tensor(0, ...), indices=Tensor(0), the gradient for input tensor won't be
    Tensor([1/3, 1/3, 1/3]) as stated in their documentation, but will be Tensor([1, 0, 0]). This API implements a similar backward kernel.
3. Case 3: the same as `minimum`

Args:
    input (Tensor): A tensor, the data type is bfloat16, float16, float32, float64, int32, int64 on GPU.
        uint8, int32, int64, float32, float64 are allowed on CPU.
    dim (int, optional): The dim along which the minimum is computed.
        If this is not specified: see case 1, note that: `None` cannot be passed to this (TypeError will be thrown)
        compute the minimum over all elements of `input` and return a Tensor with a single element,
        otherwise must be in the range :math:`[-input.ndim, input.ndim)`.
        If :math:`dim < 0`, the axis to reduce is :math:`input.ndim + dim`.
        Warning: if `dim` is specified, execute static graph will throw exceptions
        when not on a GPU device, since max_with_index is not implemented for non-GPU devices
    keepdim (bool, optional): Whether to reserve the reduced dimension in the
        output Tensor. The result tensor will have one fewer dimension
        than the `input` unless :attr:`keepdim` is true, default
        value is False. Note that if `dim` does not appear in neither (`*args`) or (`**kwargs`), this parameter cannot be passed alone
    other (Tensor, optional): the other tensor to perform `paddle.minimum` with. This Tensor should
        have the same or broadcast-able shape as the `input`. Note that (`dim` & `keepdim`) and `other` are mutually exclusive
        meaning that trying to composite both will result in TypeError
    out (Tensor|tuple[Tensor, Tensor], optional): the output Tensor or tuple of (Tensor, int64 Tensor) that can be optionally
        given to be used as output buffers. For case 1 and 3 out is just a Tensor, while for case 2 we expect a tuple


Returns:
    - For case 1. A single value Tensor (0-dim)
    - For case 2. A named tuple MinMaxRetType(values: Tensor, indices: Tensor), `values` has the same data type as the `input`,
        while indices is always an int64 Tensor, with exactly the same shape as `values`.
        MinMaxRetType can be used (indexed, packed, unpacked) in the same way as a regular tuple
    - For case 3. See `paddle.minimum` (:ref:`api_paddle_minimum`)


Examples:
    .. code-block:: python

        >>> import paddle

        >>> # data_x is a Tensor with shape [2, 4]
        >>> # the axis is a int element
        >>> x = paddle.to_tensor([[0.2, 0.3, 0.5, 0.9],
        ...                       [0.1, 0.2, 0.6, 0.7]],
        ...                       dtype='float64', stop_gradient=False)
        >>> # Case 1: reduce over all dims
        >>> result1 = paddle.compat.min(x)
        >>> result1
        Tensor(shape=[], dtype=float64, place=Place(gpu:0), stop_gradient=False,
        0.10000000)

        >>> # Case 2: reduce over specified dim
        >>> x.clear_grad()
        >>> result2 = paddle.compat.min(x, dim=1)
        >>> result2
        MinMaxRetType(values=Tensor(shape=[2], dtype=float64, place=Place(gpu:0), stop_gradient=False,
            [0.20000000, 0.10000000]), indices=Tensor(shape=[2], dtype=int64, place=Place(gpu:0), stop_gradient=True,
            [0, 0]))
        >>> result2[0].backward()
        >>> x.grad
        Tensor(shape=[2, 4], dtype=float64, place=Place(gpu:0), stop_gradient=False,
            [[1., 0., 0., 0.],
             [1., 0., 0., 0.]])

        >>> # Case 3: equivalent to `paddle.minimum`
        >>> x.clear_grad()
        >>> y = paddle.to_tensor([[0.5, 0.4, 0.1, 0.2],
        ...                       [0.3, 0.1, 0.6, 0.7]],
        ...                       dtype='float64', stop_gradient=False)
        >>> result3 = paddle.compat.min(x, y)
        >>> result3
        Tensor(shape=[2, 4], dtype=float64, place=Place(gpu:0), stop_gradient=False,
            [[0.20000000, 0.30000000, 0.10000000, 0.20000000],
             [0.10000000, 0.10000000, 0.60000000, 0.70000000]])
9input should be a tensor, but got an instance with type ''r   NFTrF   rK   rF   rM   r.   devicer   r   )rv   r/   rw   rx   r   ra   r]   r?   r   r}   r   r   ry   ndimr   placeis_gpu_placer   argmintake_along_axisrX   squeeze_r	   min_with_indexr   zerosr   minimumrN   r;   r<   r5   rH   rh   ri   rz   rK   retr<   r;   valsindss              r%   r   r     s   B efjj..>??GUH\H\G]]^_
 	
 u%25J4J6JL
C#u%jj	L#	&	&#t$::  )A)A)C)C,U3 !--$O// 'vGC'%LA ' 0 0l 0 CC
 $22%
 &*"#4>fll5;;C 	#u%nnU1
c=))MM#**c!f-MM#++s1v. J MM##Jr'   zpaddle.compat.maxz
paddle.maxc          	        [        U [        R                  R                  [        R                  45      (       d"  [        S[        U 5      R                   S35      e[        U 5        [        S/UQ70 UD6u  pESnUc$  [        US5        [        R                  " U 5      nGOP[        U[        5      (       Ga  [        US5        U R                  (       a  [        5       (       a  U R                  R!                  5       (       dk  [#        U 5        [        R$                  " XSS9n[        R&                  " XUS9nU(       a
  [)        XS	9nO[)        UR+                  US9UR+                  US9S	9nO[,        R.                  " XUS5      u  pSU
l        [)        XS	9nOY[)        U [        R2                  " / [        R4                  U R                  S
9S	9nO"[        US5        [,        R6                  " X5      nUbu  [        U[(        5      (       aJ  [        R8                  " UR:                  US   5        [        R8                  " UR<                  US   5        U$ [        R8                  " Xa5        U$ )a  

Computes the maximum of tensor elements. There are mainly 3 cases (functionalities):

1. paddle.compat.max(input: Tensor): reduce max over all dims, return a single value Tensor
2. paddle.compat.max(input: Tensor, dim: int (cannot be None), keepdim=False): reduce max over the given dim,
    returns a named tuple MinMaxRetType(values: Tensor, indices: Tensor)
3. paddle.compat.max(input: Tensor, other: Tensor): see `paddle.maximum`

Special warning: the gradient behavior is NOT well-documented by PyTorch, the actual behavior should be:

1. Case 1: the same as `max`
2. Case 2: NOT evenly distributing the gradient for equal maximum elements! PyTorch actually only propagates to the elements with indices,
    for example: Tensor([1, 1, 1]) -> max(..., dim=0) -> values=Tensor(0, ...), indices=Tensor(0), the gradient for input tensor won't be
    Tensor([1/3, 1/3, 1/3]) as stated in their documentation, but will be Tensor([1, 0, 0]). This API implements a similar backward kernel.
3. Case 3: the same as `maximum`

Args:
    input (Tensor): A tensor, the data type is bfloat16, float16, float32, float64, int32, int64 on GPU.
        uint8, int32, int64, float32, float64 are allowed on CPU.
    dim (int, optional): The dim along which the maximum is computed.
        If this is not specified: see case 1, note that: `None` cannot be passed to this (TypeError will be thrown)
        compute the maximum over all elements of `input` and return a Tensor with a single element,
        otherwise must be in the range :math:`[-input.ndim, input.ndim)`.
        If :math:`dim < 0`, the axis to reduce is :math:`input.ndim + dim`.
        Warning: if `dim` is specified, execute static graph will throw exceptions
        when not on a GPU device, since max_with_index is not implemented for non-GPU devices
    keepdim (bool, optional): Whether to reserve the reduced dimension in the
        output Tensor. The result tensor will have one fewer dimension
        than the `input` unless :attr:`keepdim` is true, default
        value is False. Note that if `dim` does not appear in neither (`*args`) or (`**kwargs`), this parameter cannot be passed alone
    other (Tensor, optional): the other tensor to perform `paddle.maximum` with. This Tensor should
        have the same or broadcast-able shape as the `input`. Note that (`dim` & `keepdim`) and `other` are mutually exclusive
        meaning that trying to composite both will result in TypeError
    out (Tensor|tuple[Tensor, Tensor], optional): the output Tensor or tuple of (Tensor, int64 Tensor) that can be optionally
        given to be used as output buffers. For case 1 and 3 out is just a Tensor, while for case 2 we expect a tuple


Returns:
    - For case 1. A single value Tensor (0-dim)
    - For case 2. A named tuple MinMaxRetType(values: Tensor, indices: Tensor), `values` has the same data type as the `input`,
        while indices is always an int64 Tensor, with exactly the same shape as `values`.
        MinMaxRetType can be used (indexed, packed, unpacked) in the same way as a regular tuple
    - For case 3. See `paddle.maximum` (:ref:`api_paddle_maximum`)


Examples:
    .. code-block:: python

        >>> import paddle

        >>> # data_x is a Tensor with shape [2, 4]
        >>> # the axis is a int element
        >>> x = paddle.to_tensor([[0.2, 0.3, 0.5, 0.9],
        ...                       [0.1, 0.2, 0.6, 0.7]],
        ...                       dtype='float64', stop_gradient=False)
        >>> # Case 1: reduce over all dims
        >>> result1 = paddle.compat.max(x)
        >>> result1
        Tensor(shape=[], dtype=float64, place=Place(gpu:0), stop_gradient=False,
        0.90000000)

        >>> # Case 2: reduce over specified dim
        >>> x.clear_grad()
        >>> result2 = paddle.compat.max(x, dim=1)
        >>> result2
        MinMaxRetType(values=Tensor(shape=[2], dtype=float64, place=Place(gpu:0), stop_gradient=False,
            [0.90000000, 0.70000000]), indices=Tensor(shape=[2], dtype=int64, place=Place(gpu:0), stop_gradient=True,
            [3, 3]))
        >>> result2[0].backward()
        >>> x.grad
        Tensor(shape=[2, 4], dtype=float64, place=Place(gpu:0), stop_gradient=False,
            [[0., 0., 0., 1.],
             [0., 0., 0., 1.]])

        >>> # Case 3: equivalent to `paddle.maximum`
        >>> x.clear_grad()
        >>> y = paddle.to_tensor([[0.5, 0.4, 0.1, 0.2],
        ...                       [0.3, 0.1, 0.6, 0.7]],
        ...                       dtype='float64', stop_gradient=False)
        >>> result3 = paddle.compat.max(x, y)
        >>> result3
        Tensor(shape=[2, 4], dtype=float64, place=Place(gpu:0), stop_gradient=False,
            [[0.50000000, 0.40000000, 0.50000000, 0.90000000],
             [0.30000000, 0.20000000, 0.60000000, 0.70000000]])
r   r   r   NFTr   r   rM   r   r   r   )rv   r/   rw   rx   r   ra   r]   r?   r   r}   r   r   ry   r   r   r   r   r   argmaxr   rX   r   r	   max_with_indexr   r   r   rS   rN   r;   r<   r   s              r%   r   r   2  s   B efjj..>??GUH\H\G]]^_
 	
 u%25J4J6JL
C#u%jj	L#	&	&#t$::  )A)A)C)C,U3 --$O// 'vGC'%LA ' 0 0l 0 CC
 $22%
 &*"#4>fll5;;C 	#u%nnU1
c=))MM#**c!f-MM#++s1v. J MM##Jr'   c                  *    \ rS rSr% S\S'   S\S'   Srg)SlogdetResulti  r   sign	logabsdetr=   Nr>   r=   r'   r%   r   r     s    
Lr'   r   c                    [         R                  " XS9u  p#Ub2  [        R                  " X!S   5        [        R                  " X1S   5        [	        X#5      $ )a  
(PyTorch Compatible API) Calculates the sign and natural logarithm of the absolute value of a square matrix's or batches square matrices' determinant.
The determinant can be computed with ``sign * exp`` (logabsdet).

Supports input of float, double, complex64, complex128.

Notes:
    1. For matrices that have zero determinant, this returns ``(0, -inf)``.

    2. For matrices with complex value, the :math:`abs(det)` is the modulus of the determinant,
    and therefore :math:`sign = det / abs(det)`.

    3. The return structure of this API has been revised **from a single stacked Tensor of shape `[2, *]` (where index 0 was sign and index 1 was logabsdet) to a tuple of two independent Tensors `(sign, logabsdet)`** (see `PR #72505 <https://github.com/PaddlePaddle/Paddle/pull/72505>`_).
    This modification may cause incompatibility with models previously exported for inference that relied on the old return structure.

Args:
    x (Tensor): the batch of matrices of size :math:`(*, n, n)`
        where math:`*` is one or more batch dimensions.
    out(SlogdetResult, optional): The tuple of output tensor, contains ``abs`` and ``logabsdet``.

Returns:
    SlogdetResult: A tuple containing two Tensors: (sign, logabsdet).
    The first Tensor represents the signs of the determinants and the second Tensor
    represents the natural logarithms of the absolute values of the determinants.
    Each output Tensor has a shape of :math:`(*)`, where :math:`*` matches the
    batch dimensions of the input `x`.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> x = paddle.to_tensor([[1., 0.], [0., 1.]])
        >>> A = paddle.compat.slogdet(x)
        >>> print(A.sign)
        Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               1.)
        >>> print(A.logabsdet)
        Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               0.)
rG   r   r   )r	   
slogdet_v2r/   rN   r   )r(   rH   r   r   s       r%   r   r     sG    R ''3OD
dF#iQ())r'   c                  *    \ rS rSr% S\S'   S\S'   Srg)SortRetTypei  r   r;   r<   r=   Nr>   r=   r'   r%   r   r     rE   r'   r   zpaddle.compat.sortzpaddle.sortc                    [        USS9  [        R                  " XX#5      u  pVUb2  [        R                  " XTS   5        [        R                  " XdS   5        [        XVS9$ )a	  

Sorts the input along the given dimension, and returns the sorted output and indices tensor. The default sort algorithm is ascending, if you want the sort algorithm to be descending, you must set the :attr:`descending` as True.

Args:
    input (Tensor): An input N-D Tensor with type float32, float64, int16,
        int32, int64, uint8, float16, bfloat16
    dim (int, optional): Dimension to compute indices along. The effective range
        is [-R, R), where R is Rank(x). when dim<0, it works the same way
        as dim+R. Default is -1.
    descending (bool, optional) : Descending is a flag, if set to true,
        algorithm will sort by descending order, else sort by
        ascending order. Default is false.
    stable (bool, optional): Whether to use stable sorting algorithm or not.
        When using stable sorting algorithm, the order of equivalent elements
        will be preserved. Default is False.
    out (tuple, optional) : the output tuple/list of (Tensor, Tensor) that
        can be optionally given to be used as output buffers

Returns:
    SortRetType, a named tuple which contains `values` and `indices`, can be accessed through either indexing
    (e.g. `result[0]` for values and `result[1]` for indices), or by `result.values` & `result.indices`

Examples:

.. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[5,8,9,5],
        ...                       [0,0,1,7],
        ...                       [6,9,2,4]],
        ...                      dtype='float32')
        >>> out1 = paddle.compat.sort(input=x, dim=-1)
        >>> out2 = paddle.compat.sort(x, 1, descending=True)
        >>> out1
        SortRetType(values=Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
               [[5., 5., 8., 9.],
                [0., 0., 1., 7.],
                [2., 4., 6., 9.]]), indices=Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
               [[0, 3, 1, 2],
                [0, 1, 2, 3],
                [2, 3, 0, 1]]))
        >>> out2
        SortRetType(values=Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
               [[9., 8., 5., 5.],
                [7., 1., 0., 0.],
                [9., 6., 4., 2.]]), indices=Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
               [[2, 1, 0, 3],
                [3, 2, 0, 1],
                [1, 0, 3, 2]]))
T)expect_multipler   r   rM   )r   r	   argsortr/   rN   r   )r5   rP   
descendingstablerH   outputsr<   s          r%   r   r     sR    @ c40~~e*EG
g1v&g1v&g77r'   c                    g rm   r=   r5   sortedreturn_inversereturn_countsrP   s        r%   r   r   K  s     %(r'   c                    g rm   r=   r   s        r%   r   r   U        r'   c                    g rm   r=   r   s        r%   r   r   _  r   r'   c                    g rm   r=   r   s        r%   r   r   i  s     r'   zpaddle.compat.uniquezpaddle.uniquec                2    [         R                  " U UUUUS9$ )a  
Returns the unique elements of `input` in ascending order.

Args:
    input(Tensor): The input tensor, it's data type should be float32, float64, int32, int64.
    sorted(bool, optional): Does not affect the return result, same as PyTorch.
    return_inverse(bool, optional): If True, also return the indices for where elements in
        the original input ended up in the returned unique tensor.
    return_counts(bool, optional): If True, also return the counts for each unique element.
    dim(int, optional): The axis to apply unique. If None, the input will be flattened.
        Default: None.

Returns:
    tuple (output, inverse_indices, counts). `output` is the unique tensor for `input`. \
        `inverse_indices` is provided only if `return_inverse` \
        is True. `counts` is provided only if `return_counts` is True.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([2, 3, 3, 1, 5, 3])
        >>> unique = paddle.compat.unique(x)
        >>> print(unique)
        Tensor(shape=[4], dtype=int64, place=Place(cpu), stop_gradient=True,
        [1, 2, 3, 5])

        >>> _, inverse_indices, counts = paddle.compat.unique(x, return_inverse=True, return_counts=True)
        >>> print(inverse_indices)
        Tensor(shape=[6], dtype=int64, place=Place(cpu), stop_gradient=True,
        [1, 2, 2, 0, 3, 2])
        >>> print(counts)
        Tensor(shape=[4], dtype=int64, place=Place(cpu), stop_gradient=True,
        [1, 1, 3, 1])

        >>> x = paddle.to_tensor([[2, 1, 3], [3, 0, 1], [2, 1, 3]])
        >>> unique = paddle.compat.unique(x)
        >>> print(unique)
        Tensor(shape=[4], dtype=int64, place=Place(cpu), stop_gradient=True,
        [0, 1, 2, 3])

        >>> unique = paddle.compat.unique(x, dim=0)
        >>> print(unique)
        Tensor(shape=[2, 3], dtype=int64, place=Place(cpu), stop_gradient=True,
        [[2, 1, 3],
         [3, 0, 1]])
)r   r   rF   r   )r/   r   r   s        r%   r   r   s  s%    x ==%# r'   >   r(   rF   r$   num_or_sectionszpaddle.compat.splitzpaddle.splitc                (	  ^ U4S jnSS jn[        T[        [        45      (       a_  [        T5       HP  u  pVSn[        U[        5      (       a  [        UR                  S5      5      nOUnUS:  d  MA  [        SU SU 35      e   [        5       (       Ga  [        U[        5      (       a  UR                  S5      nU[        U R                  5      -   S:  d   S5       eUS:  a  U[        U R                  5      -   OUn[        T[        [        45      (       af  [        R                  R                  T5      (       aA  [        T5       H2  u  p[        U	[        5      (       d  M  TU   R                  5       TU'   M4     O-[        T[
        5      (       d  [        S[        T5       S35      e[        T[
        5      (       a~  TS:  d   S	5       eU" TU" U R                  U5      5      m[        T[        5      (       a!  [        [         R"                  " U TU5      5      $ [        [         R$                  " U TU5      5      $ [        [         R"                  " U TU5      5      $ [        U[        R&                  R(                  5      (       a  [        S
5      e[        U[
        5      (       aC  [        U R                  5      U-   S:  d   S5       eUS:  a  [        U R                  5      U-   OUnU R                  n
[        T[
        [        [        45      (       d  [        S5      e[        T[
        5      (       a  TS:  d   S	5       eU" TU" U R                  U5      5      m[        T[        5      (       ad  [        R                  R                  T5      (       a  [        R                  R+                  T5      m[        [         R"                  " U TU5      5      $ [        [         R$                  " U TU5      5      $ [        U[
        5      (       a   X   S:  a  [        T5      X   ::  d   S5       e[        R                  R                  T5      (       a  [        R                  R+                  T5      m[        [         R"                  " U TU5      5      $ )aN	  
(PyTorch Compatible API) Split the input tensor into multiple sub-Tensors.

Args:
    tensor (Tensor): A N-D Tensor. The data type is bool, bfloat16, float16, float32, float64, uint8, int8, int32 or int64.
    split_size_or_sections (int|list|tuple):
        If split_size_or_sections is an integer type, then tensor will be split into equally sized chunks (if possible).
        Last chunk will be smaller if the tensor size along the given dimension dim is not divisible by split_size.
        If split_size_or_sections is a list, then tensor will be split into len(split_size_or_sections) chunks with sizes
        in dim according to split_size_or_sections. Negative inputs are not allowed. For example: for a dim with 9 channels,
        [2, 3, -1] will not be interpreted as [2, 3, 4], but will be rejected and an exception will be thrown.
    dim (int|Tensor, optional): The dim along which to split, it can be a integer or a ``0-D Tensor``
        with shape [] and data type  ``int32`` or ``int64``.
        If :math::`dim < 0`, the dim to split along is :math:`rank(x) + dim`. Default is 0.
Returns:
    tuple(Tensor), The tuple of segmented Tensors.

Note:
    This is a pytorch compatible API that follows the function signature and behavior of torch.split.
    To use the original split of paddle, please consider `paddle.split`

Examples:

    .. code-block:: pycon

        >>> import paddle

        >>> # x is a Tensor of shape [3, 8, 5]
        >>> x = paddle.rand([3, 8, 5])

        >>> out0, out1, out2 = paddle.compat.split(x, split_size_or_sections=3, dim=1)
        >>> print(out0.shape)
        paddle.Size([3, 3, 5])
        >>> print(out1.shape)
        paddle.Size([3, 3, 5])
        >>> print(out2.shape)
        paddle.Size([3, 2, 5])

        >>> out0, out1, out2 = paddle.compat.split(x, split_size_or_sections=[1, 2, 5], dim=1)
        >>> print(out0.shape)
        paddle.Size([3, 1, 5])
        >>> print(out1.shape)
        paddle.Size([3, 2, 5])
        >>> print(out2.shape)
        paddle.Size([3, 5, 5])

        >>> # dim is negative, the real dim is (rank(x) + dim)=1
        >>> out0, out1, out2 = paddle.compat.split(x, split_size_or_sections=3, dim=-2)
        >>> print(out0.shape)
        paddle.Size([3, 3, 5])
        >>> print(out1.shape)
        paddle.Size([3, 3, 5])
        >>> print(out2.shape)
        paddle.Size([3, 2, 5])
c                   > UT-  nUT-  nUS:X  a  U$ [        U5       Vs/ s H  nTPM     nnUR                  U5        U$ s  snf )Nr   )rangeappend)
split_sizeshape_on_dimremaining_numnum_complete_section_sectionssplit_size_or_sectionss         r%   GetSplitSizesplit.<locals>.GetSplitSize  sf    $'==+/EEA'' 166J0K0K1&0K   OOM*O	s   Ac                    [        U 5      n[        U[        5      (       a  X* :  d  X:  a  [        SU SU SU 35      eX   $ )Nz:(InvalidArgument) The dim is expected to be in range of [-r\   z), but got )ru   rv   ry   
ValueError)shaperP   shape_ranges      r%   GetShapeOnDimInRange#split.<locals>.GetShapeOnDimInRange  sZ    %jc3\!S%7 PQ\P]]_`k_llwx{w|}  zr'   r   zWpaddle.compat.split expects split_sizes have only non-negative entries, but got size = z on dim z(rank(x) + dim) must >= 0zjThe type of 'split_size_or_sections' in split must be int, list or tuple in imperative mode, but received .z.split_size_or_sections must be greater than 0.zv'dim' is not allowed to be a pir.Value in a static graph: 
pir.Value can not be used for indexing python lists/tuples.z\The type of 'split_size_or_sections' in split must be int, list or tuple in imperative mode.zClen(split_size_or_sections) must not be more than input.shape[dim].)rP   ry   returnry   )rv   listtuple	enumerater   ry   r1   r   r   ru   r   r/   utils_contain_varra   r]   r	   r   split_with_numrw   rx   get_int_tensor_list)tensorr   rP   r   r   isection_size	shape_valindexr1   input_shapes    `         r%   r   r     s(   @
 (4-88()?@OAI,11 1 1! 45	(	a mnzm{  |D  EF  DG  H   A c8$$((1+CS&&!+H-HH++.7sS&&,tUm<<||(()?@@#,-C#DKE!$118N!9$& /u5 $E
 2C88 !789< 
 ,c22)A- @- &2&(<V\\3(O&" 0$77V\\&2H#NOO))&2H#N  f.DcJKKc6::++,,P  c3v||$s*a/L1LL//2Qw3v||$s*CCll03e2DEEn  ,c22)A- @- &2&(<V\\3(O&" 0$77<<,,-CDD-3\\-M-M..* V\\&2H#NOO))&2H#N  #s##(81(<12k6FF YF ||(()?@@)/)I)I**& f.DcJKKr'   )r5   r   r6   r   r   bool)NF)
r5   r   rP   
int | NonerK   r   rH   z%tuple[Tensor, Tensor] | Tensor | Noner   zTensor | MedianRetType)r   ry   )r+   strrh   r   ri   r   )r5   r   )
r5   r   rh   r   rH   z-Tensor | tuple[Tensor, Tensor] | list[Tensor]ri   r   r   zTensor | MinMaxRetTyperm   )r(   r   rH   zSlogdetResult | Noner   r   )FFN)
r5   r   rP   ry   r   r   r   r   r   r   )....)r5   r   r   r   r   Literal[True]r   r   rP   r   r   ztuple[Tensor, Tensor, Tensor])r5   r   r   r   r   Literal[False]r   r   rP   r   r   tuple[Tensor, Tensor])r5   r   r   r   r   r   r   r   rP   r   r   r   )r5   r   r   r   r   r   r   r   rP   r   r   r   )TFFN)r   )r   r   r   zint | Sequence[int]rP   ry   r   ztuple[Tensor, ...])K
__future__r   typingr   r   r   r   typing_extensionsr   r/   r	   paddle.baser
   paddle.base.frameworkr   paddle.frameworkr   paddle.utils.decorator_utilsr   rt   r   proxyr   r   r   r   r   r   r   collections.abcr   r   __all__r&   r   int8r   r   r   r   float32float64r   r   _typesu1i1i2i4i8f2f4f8b1bf_promote_matrixr   r2   r   r9   r   r    r!   rX   r}   r   r   r   r   r   r   r   r   r   r   )r   t1jt2s   0000r%   <module>r      s   # : : &    * A   %(# LL
KK
LL
LL
LL
NN
NN
NN
KK
OO
 *0 &BBBBB RRRR,RRRR,RRRR,RRRR,RRRR,RRRR,RRRR,RRRR,RRRR,RRRR, 6""6" Hoa ##" " s#
&1&1&1 
&1
&1RJ 
 v$  ;=
 26;=;=	;= ;=
 
/;= ;=
;=| v'# B=
 26B=B=	B= B=
 
/B= B=
B=J J 
A!H
 v! :>RRR 
7R 	R
 R
Rj v! :>OOO 
7O 	O
 O
OdJ 
-*`* 
 v" @8@8	@8 @8 	@8 @8
@8F 
 $'#&((( "( !	(
 
( #( 
( 
 %(#&    #  !	 
 
    
  
 $'$'    "  "	 
 
    
  
 %($' # "	
 
  
 v$  =
=@ 9# MNlLlL,?lLFIlLlL
lLEs   )(L:
