
    ёiNN                   	   % S SK Jr  S SKrS SKJrJr  S SKrS SKJ	r	J
r
  S SKrS SKJr  S SKJrJrJr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  S SKJr  SSKJ r J!r!J"r"J#r#  SSK$J%r%  SSK&J'r'J(r(J)r)J*r*  SSK+J,r,  SSK-J.r.  SSKJ/r/  \(       a  S SK0J1r1  S SKJ2r2  \S   r3S\4S'   / r5Sr6\" 5        Sq       SrS jj5       r7\SqS j5       r8\" S5      SsS j5       r9 Sq     StS  jjr:       SuS" jr;\" S#/S$/S%.5          SvSSS&.               SwS( jjj5       r<S)S*S+/S!S4           SxS, jjr=\" SS-/S#/S$/S..5            Sy               SzS/ jj5       r>S{S|S1 jjr?  S}       S~S2 jjr@  S         SS3 jjrA     S             SS4 jjrBSqSS5 jjrC\SqS6 j5       rD\" S'S$/05        S         SS7 jj5       rESSS8 jjrF     S             SS9 jjrG      S               SS: jjrH    S           SS; jjrI   S         SS< jjrJSqSS= jjrKSqSS> jjrLSqSS? jjrM  SSS@.         SSA jjjrNSqSSB jjrOSC rPSD rQSE rRS{SF jrS    S           SSG jjrT    S           SSH jjrU Sq       SSI jjrV\
  S       SSJ jj5       rW\
  S       SSK jj5       rW  S SSL jjrW\
   S         SSM jj5       rX\
   S         SSN jj5       rX\
 S         SSO jj5       rX S SSP jjrX  S         SSQ jjrY   S           SSR jjrZSqSSS jjr[SqSST jjr\SqSSU jjr] S       SSV jjr^   S         SSW jjr_SX r`SY ra\" SS-/S0SZ/5        SSS@.           SS[ jjj5       rb    S             SS\ jjrc S         SS] jjrd S       SS^ jjre   S           SS_ jjrfSSS` jjrg   S           SSa jjrh Sq       SSb jjriS}SSc.Sd jjrj SSSc.Se jjrk SSSc.Sf jjrl     SSSc.Sg jjrm SSSc.Sh jjrnSi roSj rpSk rqSl rrSqSSm jjrs     S             SSn jjrt   S             SSo jjru S       SSp jjrvg)    )annotationsN)TYPE_CHECKINGLiteral)	TypeAliasoverload)_C_ops)bmmdiagonaldotmatmul)DataType)VarDesc)broadcast_shape)ParamAliasDecoratorVariableArgsDecoratorparam_two_aliastranspose_decorator)inplace_apis_in_dygraph_only   )check_dtype
check_typecheck_variable_and_dtypeconvert_dtype)Variable)LayerHelperin_dynamic_modein_dynamic_or_pir_modein_pir_mode   )full)cast)_get_reduce_axis)Sequence)Tensor)fronucr   _POrder	   xc                   [        5       (       a  [        R                  " X5      $ [        U S/ SQS5        [	        US[
        [        4S5        [        U[        5      (       a  [        U5      n[        U5      [        U R                  5      :w  a.  [        S[        U R                  5       S[        U5       S35      e[        U5       HH  u  p4U[        U R                  5      :  d  M   [        SU S	X    S
[        U R                  5       S35      e   [        S0 [        5       D6nUR                  U R                  5      nUR                  U R                  5      nUR!                  SSU /0U/U/S.SU0S9  U$ )aE
  
Permute the data dimensions of `input` according to `perm`.

The `i`-th dimension  of the returned tensor will correspond to the
perm[i]-th dimension of `input`.

.. note::
    Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim0`` & ``dim1`` can replace ``perm``.
    For example, ``transpose(input=x, dim0=0, dim1=1)`` is equivalent to ``transpose(x=x, perm=[1, 0, 2])``.

Args:
    x (Tensor): The input Tensor. It is a N-D Tensor of data types bool, float16, bfloat16, float32, float64, int8, int16, int32, int64, uint8, uint16, complex64, complex128.
        alias: ``input``.
    perm (list|tuple): Permute the input according to the data of perm.
    name (str|None, optional): The name of this layer. For more information, please refer to :ref:`api_guide_Name`. Default is None.

Returns:
    Tensor: A transposed n-D Tensor, with data type being bool, float32, float64, int32, int64.

Examples:

    .. code-block:: text

        # The following codes in this code block are pseudocode, designed to show the execution logic and results of the function.

        x = to_tensor([[[ 1  2  3  4] [ 5  6  7  8] [ 9 10 11 12]]
                       [[13 14 15 16] [17 18 19 20] [21 22 23 24]]])
        shape(x): return [2,3,4]

        # Example 1
        perm0 = [1,0,2]
        y_perm0 = transpose(x, perm0) # Permute x by perm0

        # dim:0 of y_perm0 is dim:1 of x
        # dim:1 of y_perm0 is dim:0 of x
        # dim:2 of y_perm0 is dim:2 of x
        # The above two lines can also be understood as exchanging the zeroth and first dimensions of x

        y_perm0.data = [[[ 1  2  3  4]  [13 14 15 16]]
                        [[ 5  6  7  8]  [17 18 19 20]]
                        [[ 9 10 11 12]  [21 22 23 24]]]
        shape(y_perm0): return [3,2,4]

        # Example 2
        perm1 = [2,1,0]
        y_perm1 = transpose(x, perm1) # Permute x by perm1

        # dim:0 of y_perm1 is dim:2 of x
        # dim:1 of y_perm1 is dim:1 of x
        # dim:2 of y_perm1 is dim:0 of x
        # The above two lines can also be understood as exchanging the zeroth and second dimensions of x

        y_perm1.data = [[[ 1 13]  [ 5 17]  [ 9 21]]
                        [[ 2 14]  [ 6 18]  [10 22]]
                        [[ 3 15]  [ 7 19]  [11 23]]
                        [[ 4 16]  [ 8 20]  [12 24]]]
        shape(y_perm1): return [4,3,2]

Examples:

    .. code-block:: pycon

        >>> import paddle

        >>> x = paddle.randn([2, 3, 4])
        >>> x_transposed = paddle.transpose(x, perm=[1, 0, 2])
        >>> print(x_transposed.shape)
        paddle.Size([3, 2, 4])

r)   )boolfloat16bfloat16float32float64int8uint8int16int32int64uint16	complex64
complex128float8_e5m2float8_e4m3fn	transposepermzInput(perm) is the permutation of dimensions of Input(x), its length should be equal to dimensions of Input(x), but received dimension of Input(x) is z, the length of Input(perm) is .zJEach element in Input(perm) should be less than Input(x)'s dimension, but z-th element in Input(perm) is z$ which exceeds Input(x)'s dimension 
transpose2XOutXShapeaxistypeinputsoutputsattrsr:   )r   r   r:   r   r   listtuple
isinstancelenshape
ValueError	enumerater   locals"create_variable_for_type_inferencedtype	append_op)r)   r;   nameidxdimhelperoutx_shapes           T/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/tensor/linalg.pyr:   r:   C   sx   T (( " )	
, 	4$<dE"":Dt9AGG$99<QWW G003D	{!=  "$HCc!''l" %=di[ I!!$QWWa1  ( 5FH577@;;AGGD!: EgY74.	 	 	
 
    c                N    [        5       (       a  [        R                  " X5      $ g)z
Inplace version of ``transpose`` API, the output Tensor will be inplaced with input ``x``.
Please refer to :ref:`api_paddle_transpose`.
N)r   r   
transpose_)r)   r;   rT   s      rZ   r]   r]      s#       )) r[   dimsinputc                    [        XS9$ )a  
Permute the dimensions of a tensor.

Args:
    input (Tensor): the input tensor.
    *dims (tuple|list|int): The desired ordering of dimensions. Supports passing as variable-length
        arguments (e.g., permute(x, 1, 0, 2)) or as a single list/tuple (e.g., permute(x, [1, 0, 2])).

Returns:
    Tensor: A tensor with permuted dimensions.

Examples:
    .. code-block:: pycon

        >>> import paddle

        >>> x = paddle.randn([2, 3, 4])
        >>> y = paddle.permute(x, (1, 0, 2))
        >>> print(y.shape)
        paddle.Size([3, 2, 4])

        >>> y = x.permute([1, 0, 2])
        >>> print(y.shape)
        paddle.Size([3, 2, 4])
)r)   r;   rH   )r_   r^   s     rZ   permutera      s    6 u((r[   c                    U R                   $ )a3  
Transpose the last two dimensions of the input tensor `x`.

Note:
    If `n` is the number of dimensions of `x`, `paddle.matrix_transpose(x)` is equivalent to `x.transpose([0, 1, ..., n-2, n-1])`.

Args:
    x (Tensor): The input tensor to be transposed. `x` must be an N-dimensional tensor (N >= 2) of any data type supported by Paddle.
    name (str|None, optional): The name of this layer. For more information, please refer to :ref:`api_guide_Name`. Default is None.

Returns:
    Tensor: A new tensor with the same shape as `x`, except that the last two dimensions are transposed.

Examples:
    .. code-block:: pycon

        >>> import paddle
        >>> x = paddle.ones(shape=[2, 3, 5])
        >>> x_transposed = paddle.matrix_transpose(x)
        >>> print(x_transposed.shape)
        paddle.Size([2, 5, 3])
)mTr)   rT   s     rZ   matrix_transposere      s    4 44Kr[   Fc	           
        [        5       (       a  [        R                  " XXBX5Xg5      $ UUUUUS.n	Ucm  S n
U
" X5        [        S0 [	        5       D6nUS:X  a  UR                  SS9nO!US:X  a  UR                  SS9nO[        S5      eUR                  SXS.S	U0U	S
9  U$ S n
U
" X5        US:X  a  [        USS/S5        O!US:X  a  [        USS/S5        O[        S5      e[        S0 [	        5       D6nUS:X  a  UR                  SS9nO!US:X  a  UR                  SS9nO[        S5      eUR                  SXUS.S	U0U	S
9  U$ )N)transpose_xtranspose_yscaleoutput_dtypeactc                ^    XS.nUR                  5        H  u  p4[        UUSS/S5        M     g Nr)   yr8   r9   fp8_fp8_half_gemm_fuseditemsr   r)   ro   	var_namesrT   vals        rZ   __check_input.fp8_fp8_half_gemm_fused.<locals>.__check_input"  ;    "#,	!*!2ID,)+ 2 "3r[   rp   r,   rR   r-   z,The output_dtype must be float16 or bfloat16rn   rX   rC   c                ^    XS.nUR                  5        H  u  p4[        UUSS/S5        M     g rm   rq   rs   s        rZ   rv   rw   D  rx   r[   bias)r)   ro   r{   )rp   )	r   r   rp   r   rP   rQ   rN   rS   r   )r)   ro   rg   rh   r{   ri   rj   rk   rT   rG   rv   rW   rX   s                rZ   rp   rp   	  s    --$[
 	

 '&(
 < ! GfhGFy(??i?P+??$ @  !!OPP.'	   J !y((&9+/H +(&:,0I !!OPP GfhGFy(??i?P+??$ @  !!OPP.5	   Jr[   ordrV   prB   )rR   rX   rB   c          	       ^  SUSSS4S jnSUSSS4U 4S jjn SU 4S jjn	 SS jn
[        U[        [        45      (       d  [        S[	        U5       35      eUb  T R                  U5      m SnUc  SnS	n[        U[        5      (       a  [        U5      n[        U[        5      (       a  [        U5      S
:X  a  US   n[        R                  " T 5      (       a  [        R                  " T 5      nOT n[        U[        5      (       a  U
" UUUUUUS9nO^[        U[        5      (       aI  U[        R                  :X  d  U[        R                  * :X  a	  U" XX#US9nOUS:X  a	  U" XX#US9nOU	" XX#US9nUb  [        R                  " WUS9  W$ )a	  
Calculate the p-order vector norm for certain  dimension of Tensor `input`.
Returns the vector norm (the 1-norm, the Euclidean or 2-norm, and in general the p-norm)
of a given tensor.

Args:
    x (Tensor): Tensor, data type float32, float64.
    p (int|float, optional): None for porder=2.0. Default None.
    axis (int|list|tuple, optional): None for last dimension. Default None.
    keepdim (bool, optional): Whether keep the dimensions as the `input`, Default False.
    name (str|None, optional): The default value is None. Normally there is no need for
        user to set this property. For more information, please refer to :ref:`api_guide_Name`.
    dtype (paddle._typing.DTypeLike, optional): It may be used to perform the computation in a more precise dtype. It is semantically equivalent to calling linalg.vector_norm(x.to(dtype)) but it is faster in some cases. Default None.
    out (Tensor| None, optional): output tensor. Ignored if None. Default: None.

Returns:
    Tensor: results of vector_norm operation on the specified axis of input tensor,
    it's data type is the same as input's Tensor.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> import numpy as np
        >>> x = paddle.arange(24, dtype="float32").reshape([2, 3, 4]) - 12
        >>> print(x)
        Tensor(shape=[2, 3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[-12., -11., -10., -9. ],
          [-8. , -7. , -6. , -5. ],
          [-4. , -3. , -2. , -1. ]],
         [[ 0. ,  1. ,  2. ,  3. ],
          [ 4. ,  5. ,  6. ,  7. ],
          [ 8. ,  9. ,  10.,  11.]]])
        >>> out_vector_norm = paddle.linalg.vector_norm(x=x,p=2,axis=None,keepdim=False)
        >>> print(out_vector_norm)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        34.)
        >>> out_vector_norm = paddle.linalg.vector_norm(x=x,p=0,axis=[0,1],keepdim=False)
        >>> print(out_vector_norm)
        Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [5., 6., 6., 6.])
        >>> out_vector_norm = paddle.linalg.vector_norm(x=x,p=float("inf"),axis=[1,2],keepdim=False)
        >>> print(out_vector_norm)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [12., 11.])
        >>> out_vector_norm = paddle.linalg.vector_norm(x=x,p=1,axis=1,keepdim=False)
        >>> print(out_vector_norm)
        Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[24., 21., 18., 15.],
         [12., 15., 18., 21.]])
NFc                ^    [         R                  " XX5S9R                  U R                  5      $ )NrB   keepdimrT   )paddlecount_nonzeroastyperR   )r_   porderrB   r   asvectorrT   s         rZ   	zero_normvector_norm.<locals>.zero_norm  s*     ##g

&
	r[   c           	     2  > [        5       (       a^  [        R                  " U 5      nU[        R                  " S5      :X  a  [        R
                  " XbU5      $ [        R                  " XbU5      $ [        S0 [        5       D6nUR                  UR                  5       S9nUR                  SSU 0SU0S9  UR                  UR                  5       S9n[        UT5      u  pU[        R                  " S5      :X  a  SOSn
UR                  U
SU0SU0UUU	S	.S
9  U$ )Ninfry   absr>   r@   rD   rE   rF   
reduce_max
reduce_minrV   keep_dim
reduce_allrC   )inf_norm)r   r   r   npr/   maxminr   rP   rQ   input_dtyperS   r"   )r_   r   rB   r   r   rT   rX   rW   
reduce_outr   reduce_typer)   s              rZ   r   vector_norm.<locals>.inf_norm  s/    "##**U#CE**zz#W55zz#W55 8vx8F;;((* < C C<%    BB((* C J  0a8J &"**U*; ;   Sz
+ '",	  	 r[   c           
       > [        5       (       ai  [        R                  " U 5      n[        R                  " Xa5      n[        R                  " XrSU5      n[        R                  " U[        SU-  5      5      n	U	$ [        S0 [        5       D6n
U
R                  U
R                  5       S9n	U
R                  U
R                  5       S9nU
R                  SSU 0SU0S9  U
R                  U
R                  5       S9nU
R                  SSU0SU0S	U0S
9  U
R                  U
R                  5       S9n[        UT5      u  pU
R                  SSU0SU0UUUS.S
9  U
R                  SSU0SU	0S	[        SU-  5      0S
9  U	$ )zB
NOTE:
    This function calculates the vector norm for dim >= 2.
N      ?ry   r   r>   r@   r   powfactorrC   
reduce_sumr   norm)r   r   r   r   sumfloatr   rP   rQ   r   rS   r"   )r_   r   rB   r   r   rT   abs_outpow_outsum_outrX   blockr   r)   s               rZ   vector_norm_axis_tuple+vector_norm.<locals>.vector_norm_axis_tuple  s    "##jj'Gjj1Gjjg>G**WeC&L&9:CJ/fh/66##% 7 
 ::##% ; 
 	U|eW5E 	 	
 ::##% ; 
 	>G$V$	 	 	
 ::##% ; 
 ,D!4
>G$#(	 	 		
 	>CLU3<01	 	 	
 
r[   c                   [        5       (       a  Uc  Sn[        R                  " XUSX45      $ Ub  [        US[        [
        4S5        Ub  [        US[
        S5        [        U S/ SQS5        Ub  UOSUb  [	        U5      OSUUSS	.n[        S0 [        5       D6nUR                  UR                  5       S
9nUR                  SSU 0SU0US9  U$ )zH
NOTE:
    This function calculates the vector norm for len(axis) == 1.
-q=r   p_normrB   r_   r,   r5   r.   r/          @rB   r   r   r   epsilonry   r>   r@   rC   )r   )r   r   r   r   r   intr   r   rP   rQ   r   rS   )	r_   r   rB   r   r   rT   rG   rW   rX   s	            rZ   vector_norm_axis_int)vector_norm.<locals>.vector_norm_axis_int  s     "##|==eWOO!68eS\8D4#9$;	 !% 0b+1+=%-3"$ E !6VX6F;;((* < C U|	   Jr[   z*only valid p type is int and float, found r   Tr   r   )rB   r   r   r   rT   r   rB   r   rT   output)r   NFFN)rK   r   r   rN   rD   r   rJ   rI   rL   r   
is_complexr   r   r   assign)r)   r~   rB   r   rT   rR   rX   r   r   r   r   r   abs_xtensors   `             rZ   vector_normr   q  s   @ uu4 uu4#L IM6r IM)V a#u&&Ed1gYOPPHHUOH|$Dz$#d)q.Aw

1 $%
 
D$		;!w,d$F !Vd$F ,d$F fS)Mr[   r%   r   c                :  ^ ^^	 S mS m	   S         SS jjnUSS4         SUU	4S jjjnSUSS4           SUU	U 4S jjjn[        U[        5      (       a  [        U5      n[        U[        5      (       a  [        U5      S	:X  as  US
:X  a  U" T X#US9$ US:X  a  U" T X#US9$ U[        R
                  :X  d-  U[        R
                  * :X  d  US:X  d  US:X  d  US	:X  d  US:X  a  U" T XX4S9$ [        SU 35      e[        S[        U5       35      e)a	  
Calculate the p-order matrix norm for certain  dimension of Tensor `input`.

Args:
    x (Tensor): Tensor, data type float32, float64.
    p (int|float|string, optional): Default 'fro'.
    axis (int|list|tuple, optional): The axis is a list(int)/tuple(int) with two elements. Default last two dimensions.
    keepdim (bool, optional): Whether keep the dimensions as the `input`, Default False.
    name (str|None, optional): The default value is None. Normally there is no need for
        user to set this property. For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: results of matrix_norm operation on the specified axis of input tensor,
    it's data type is the same as input's Tensor.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> x = paddle.arange(24, dtype="float32").reshape([2, 3, 4]) - 12
        >>> print(x)
        Tensor(shape=[2, 3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[-12., -11., -10., -9. ],
          [-8. , -7. , -6. , -5. ],
          [-4. , -3. , -2. , -1. ]],
         [[ 0. ,  1. ,  2. ,  3. ],
          [ 4. ,  5. ,  6. ,  7. ],
          [ 8. ,  9. ,  10.,  11.]]])

        >>> out_matrix_norm = paddle.linalg.matrix_norm(x=x,p=2,axis=[0,1],keepdim=False)
        >>> print(out_matrix_norm)
        Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [15.75857544, 14.97978878, 14.69693947, 14.97978973])

        >>> out_matrix_norm = paddle.linalg.matrix_norm(x=x,p='fro',axis=[0,1],keepdim=False)
        >>> print(out_matrix_norm)
        Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [17.43559647, 16.91153526, 16.73320007, 16.91153526])

        >>> out_matrix_norm = paddle.linalg.matrix_norm(x=x,p=float('inf'),axis=[1,2],keepdim=False)
        >>> print(out_matrix_norm)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [42., 38.])

        >>> out_matrix_norm = paddle.linalg.matrix_norm(x=x,p=-1,axis=[0,1],keepdim=False)
        >>> print(out_matrix_norm)
        Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [12., 12., 12., 12.])

        >>> out_matrix_norm = paddle.linalg.matrix_norm(x=x,p='nuc',axis=[0,1],keepdim=False)
        >>> print(out_matrix_norm)
        Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [23.21962357, 22.82873154, 22.69693947, 22.82873154])

c                    X-  nX-  n[        U5       Vs/ s H  oUU:w  d  M
  XT:w  d  M  UPM     nnUR                  X445        U$ s  snf )zm
Auxiliary function for matrix_norm
Computes the permutation that moves the two given dimensions to the back
)rangeextend)dim0dim1dimnpos_dim0pos_dim1irets          rZ   _backshift_permutation+matrix_norm.<locals>._backshift_permutation  sN    
 ;;+I+Qhq1=q+I

H'(
 Js   	AAAc                `    [        [        U 5      S S9 VVs/ s H  u  pUPM	     snn$ s  snnf )zR
Given a permutation, returns its inverse. It's equivalent to argsort on an array
c                    U S   $ Nr    )ijs    rZ   <lambda>;matrix_norm.<locals>._inverse_permutation.<locals>.<lambda>  s    RUr[   )key)sortedrO   )r;   r   js      rZ   _inverse_permutation)matrix_norm.<locals>._inverse_permutation  s,     %Yt_:JKLKdaKLLLs   *NFc                   Ub/  [        U[        5      (       a  [        U5      S:X  d  [        S5      e[	        5       (       a4  Uc  [
        R                  " U / US5      $ [
        R                  " XUS5      $ XSS.nUc  SUS'   [        U SSS	/S
5        [        S0 [        5       D6nUR                  UR                  5       S9nUR                  S
SU 0SU0US9  U$ )a  
The frobenius norm OP is to calculate the frobenius norm of certain two dimensions of Tensor `input`.
Args:
  input (Variable): Tensor, data type float32, float64, complex64, complex128.
  dim (list, optional): None for last two dimensions. Default None.
  keepdim (bool, optional): Whether keep the dimensions as the `input`, Default False.
  name (str, optional): The default value is None. Normally there is no need for
      user to set this property. For more information, please refer to :ref:`api_guide_Name`.
r   zAThe dim of frobenius norm op should be None or two elements list!TFr   r   r_   r.   r/   frobenius_normry   r>   r@   rC   )r   )rK   rI   rL   rN   r   r   r   r   r   rP   rQ   r   rS   )r_   rV   r   rT   rG   rW   rX   s          rZ   r   #matrix_norm.<locals>.frobenius_norm  s     ?JsD$9$9c#h!mS  "##{,,UBFF((WeDDEJE{&*l#$wI 68H !>VX>F;;((* < C %U|	   Jr[   c           	       > T" US   US   [        U R                  5      5      nT" U5      n[        5       (       a~  [        R                  " X5      n[        R
                  " US5      u  pxn	[        R                  " USSU5      n
U(       a,  [        R                  " [        R                  " U
S5      U5      n
U
$ XS.n[        U SSS	/S
5        [        S0 [        5       D6nUR                  UR                  5       S9nUR                  UR                  5       S9nUR                  UR                  5       S9nUR                  SSU /0U/U/S.SU0S9  UR                  UR                  5       S9nUR                  UR                  5       S9nUR                  UR                  5       S9nUR                  SSU/0UUUS.SS0S9  [        SU5      u  nnUR                  SSU0SU0UUUS.S9  U(       aV  UR                  UR                  5       S9nUR                  SSU/0U/U/S.SS/0S9  UR                  SSU/0U/U/S.SU0S9  U$ )a  
The nuclear norm OP is to calculate the nuclear norm of certain two dimensions of Tensor `input`.
Args:
  input (Variable): Tensor, data type float32, float64.
  axis (list): Two dimensions.
  keepdim (bool, optional): Whether keep the dimensions as the `input`, Default False.
  name (str|None, optional): The default value is None. Normally there is no need for
      user to set this property. For more information, please refer to :ref:`api_guide_Name`.
r   r   Fr   NrB   r   r_   r.   r/   nuclear_normry   r=   r>   r?   rB   rC   svdUVHSfull_matricesr   r@   r   
unsqueeze2axes)r   )rL   rM   r   r   r:   r   r   	unsqueezer   r   rP   rQ   r   rS   r"   )r_   rB   r   rT   r;   inv_perm
transposedusvhresultrG   r   rX   transpose_outinput_shapevtr   sum_axisunsqueeze_outr   r   s                       rZ   r   !matrix_norm.<locals>.nuclear_norm  s     &d1gtAwEKK8HI'-!##))%6Jzz*e4HA"ZZ2tW5F))$$VR0( M2 7Y	2N	
 7fh766##% 7 
 @@##% A 
 >>##% ? 
 	%>*O}E4.	 	 	
 445;L;L;N4O445;L;L;N4O55E<M<M<O5P-)2A."E*	 	 	
  0A6
H8CL#(	 	 		
 !DD'') E M OO!cU|!.K=Itn	   OO!m_-!$+?x(	   
r[   r   c           	       >^ T" US   US   [        U R                  5      5      nT" U5      n[        5       (       Ga	  [        U5      nUS:  a  [        R
                  O[        R                  nUS:X  ao  [        R                  " X5      n	[        R                  " U	S5      u  pnU" USU5      nU(       a,  [        R                  " [        R                  " US5      U5      nU$ [        TR                  5      mU4S jU 5       u  pU[        R                  " S5      :X  a  XpU(       d
  X:  a  US-  nU" [        U S	XS
9UU5      $ [        U S/ SQS5        [        S!0 [        5       D6nUR!                  UR#                  5       S9n[        U5      nUS:X  Gay  UR!                  UR#                  5       S9n	UR!                  UR#                  5       S9nUR%                  SSU /0U	/U/S.SU0S9  UR!                  UR#                  5       S9n
UR!                  UR#                  5       S9nUR!                  UR#                  5       S9nUR%                  SSU	/0U
UUS.SS0S9  US:  a  SOSnUR!                  UR#                  5       S9n['        SU5      u  nnUR%                  USU0SU0UUUS.S9  U(       aX  UR!                  UR#                  5       S9nUR%                  SSU/0U/U/S.SS/0S9  UR%                  SSU/0U/U/S.SU0S9  U$ U$ [        TR                  5      mU4S jU 5       u  pU[        R                  " S5      :X  a  XpU(       d
  X:  a  US-  nUR!                  UR#                  5       S9nUSUSSS.nUR%                  S SU 0SU0US9  US:  a  SOSnUR!                  UR#                  5       S9n['        UU5      u  nnUR%                  USU0SU0UUUS.S9  U$ )"u  
Calculate the p-order matrix norm for certain  dimension of Tensor `input`.
Args:
  input (Variable): Tensor, data type float32, float64.
  porder (int|float,str): p in ['fro', 'nuc', ±1, ±2, ±inf] Default 1.
  axis (list): Two dimensions.
  keepdim (bool, optional): Whether keep the dimensions as the `input`, Default False.
  name (str, optional): The default value is None. Normally there is no need for
      user to set this property. For more information, please refer to :ref:`api_guide_Name`.
r   r           r   Fr   c              3  ,   >#    U  H	  oT-  v   M     g 7fNr   .0dranks     rZ   	<genexpr>5matrix_norm.<locals>.p_matrix_norm.<locals>.<genexpr>u  s     51$h   r   r   r   r_   r   p_matrix_normry   r=   r>   r?   rB   rC   r   r   r   r   r   r@   r   r   r   c              3  ,   >#    U  H	  oT-  v   M     g 7fr   r   r   s     rZ   r   r     s     1Dqd(Dr   r   r   r   )r   )rL   rM   r   r   r   r   r   r:   r   r   r   r/   r   r   r   rP   rQ   r   rS   r"   )r_   r   rB   r   rT   r;   r   abs_ordmax_minr   r   r   r   r   r   r   r   rX   r   r   r   r   r   max_min_axisr   
vector_outrG   r   r   r   r)   s                              @rZ   r   "matrix_norm.<locals>.p_matrix_normP  s   $ &d1gtAwEKK8HI'-!##&kG$*SLfjjfjjG#~ & 0 0 =!::mU;b B0#--((4hF 177|55
bjj//!%$DKAIDsG  	!7		
 8vx866##% 7 
 f+c>!DD'') E M  BB'') C K OO!eW~!.K=Itn	   88'') 9 A 88'') 9 A 99'') : B OOm_-r2&.	   +11*,,KAA'') B J (8A'>$JOO Qx
+' '",	  	  % H H++- !I ! %*.%2O}M!B4.	    %-1%(Ek]C!8,	    
 qww<D1D1JD"**U++!d	AA'') B J
 "! E OOU|
+	   +11*,,KAA'') B J (8j'I$JOO Z(
+' '",	  	 r[   r   r%   )rV   r   rT   r&   r   r   r   r   r   zIjust support p value 'fro','nuc',1,-1,inf,-inf,2,-2 if axis is 2D, found z:except axis type int or list (length of list == 2), found )NFN)
r_   r$   rV   list[int] | Noner   r+   rT   
str | Nonereturnr$   )
r_   r$   rB   !int | list[int] | tuple[int, int]r   r+   rT   r  r  r$   )r_   r$   r   float | _POrderrB   r  r   r+   rT   r  r  r$   )rK   rJ   rI   rL   r   r   rN   )
r)   r~   rB   r   rT   r   r   r   r   r   s
   `       @@rZ   matrix_normr	  r  s   ~	M !%	+++ + 	+
 
+^ 37	__/_ _ 	_
 
_ _F #&26mmm 0m 	m
 m 
m m^ $Dz$#d)q.:!!TJJ%ZDIIKRVVG|AvBwAvBw !  [\][^_ 
 HTT
 	
r[   A)r)   r~   rB   c                T   [        U[        5      (       a  [        U5      nO)[        U[        5      (       a  [        U5      S:X  a  US   nUb  U R	                  U5      n [        U[
        5      (       aY  US:X  a&  Ub  [        U[        5      (       a  [        U SUUUS9nOqUc  [        [        U R                  5      5      n[        XX#US9nODUc  SOUn[        U[        5      (       a  [        U5      S:X  a  [        XX#US9nO[        U UUUUS9nUb  [        R                  " XtS9  U$ )	u  

Returns the matrix norm (the Frobenius norm, the nuclear norm and p-norm) or vector norm (the 1-norm, the Euclidean
or 2-norm, and in general the p-norm) of a given tensor.

Whether the function calculates the vector norm or the matrix norm is determined as follows:

- If axis is of type int, calculate the vector norm.

- If axis is a two-dimensional array, calculate the matrix norm.

- If axis is None, x is compressed into a one-dimensional vector and the vector norm is calculated.

Paddle supports the following norms:

+----------------+--------------------------------+--------------------------------+
|     porder     |        norm for matrices       |        norm for vectors        |
+================+================================+================================+
|  None(default) |         frobenius norm         |            2_norm              |
+----------------+--------------------------------+--------------------------------+
|       fro      |         frobenius norm         |          not support           |
+----------------+--------------------------------+--------------------------------+
|       nuc      |          nuclear norm          |          not support           |
+----------------+--------------------------------+--------------------------------+
|       inf      |     max(sum(abs(x), dim=1))    |          max(abs(x))           |
+----------------+--------------------------------+--------------------------------+
|      -inf      |     min(sum(abs(x), dim=1))    |          min(abs(x))           |
+----------------+--------------------------------+--------------------------------+
|       0        |          not support           |          sum(x != 0)           |
+----------------+--------------------------------+--------------------------------+
|       1        |     max(sum(abs(x), dim=0))    |           as below             |
+----------------+--------------------------------+--------------------------------+
|      -1        |     min(sum(abs(x), dim=0))    |           as below             |
+----------------+--------------------------------+--------------------------------+
|       2        |The maximum singular value      |           as below             |
|                |of a matrix consisting of axis. |                                |
+----------------+--------------------------------+--------------------------------+
|      -2        |The minimum singular value      |           as below             |
|                |of a matrix consisting of axis. |                                |
+----------------+--------------------------------+--------------------------------+
|    other int   |           not support          | sum(abs(x)^{porder})^          |
|     or float   |                                | {(1 / porder)}                 |
+----------------+--------------------------------+--------------------------------+

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

Args:
    x (Tensor): The input tensor could be N-D tensor, and the input data
        type could be float32 or float64.
        alias: ``input``.
    p (int|float|string|None, optional): Order of the norm. Supported values are `fro`, `nuc`, `0`, `±1`, `±2`,
        `±inf` and any real number yielding the corresponding p-norm.
        Default value is None.
    axis (int|list|tuple, optional): The axis on which to apply norm operation. If axis is int
        or list(int)/tuple(int)  with only one element, the vector norm is computed over the axis.
        If `axis < 0`, the dimension to norm operation is rank(input) + axis.
        If axis is a list(int)/tuple(int) with two elements, the matrix norm is computed over the axis.
        Default value is `None`.
        alias: ``dim``.
    keepdim (bool, optional): Whether to reserve the reduced dimension in the
        output Tensor. The result tensor will have fewer dimension
        than the :attr:`input` unless :attr:`keepdim` is true, default
        value is False.
    out (Tensor, optional): The output tensor. Ignored out = None.
    dtype (DTypeLike | None, optional): The data type of the output tensor. If specified, the input tensor is casted to `dtype` while performing the operation. Default value is None.
    name (str|None, optional): The default value is None. Normally there is no need for
        user to set this property. For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: results of norm operation on the specified axis of input tensor,
    it's data type is the same as input's Tensor.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> x = paddle.arange(24, dtype="float32").reshape([2, 3, 4]) - 12
        >>> print(x)
        Tensor(shape=[2, 3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[-12., -11., -10., -9. ],
          [-8. , -7. , -6. , -5. ],
          [-4. , -3. , -2. , -1. ]],
         [[ 0. ,  1. ,  2. ,  3. ],
          [ 4. ,  5. ,  6. ,  7. ],
          [ 8. ,  9. ,  10.,  11.]]])

        >>> # compute frobenius norm along last two dimensions.
        >>> out_fro = paddle.linalg.norm(x, p='fro', axis=[0,1])
        >>> print(out_fro)
        Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [17.43559647, 16.91153526, 16.73320007, 16.91153526])

        >>> # compute 2-order vector norm along last dimension.
        >>> out_pnorm = paddle.linalg.norm(x, p=2, axis=-1)
        >>> print(out_pnorm)
        Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[21.11871147, 13.19090557, 5.47722578 ],
         [3.74165750 , 11.22497177, 19.13112640]])

        >>> # compute 2-order  norm along [0,1] dimension.
        >>> out_pnorm = paddle.linalg.norm(x, p=2, axis=[0,1])
        >>> print(out_pnorm)
        Tensor(shape=[4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [15.75857544, 14.97978878, 14.69693947, 14.97978973])

        >>> # compute inf-order  norm
        >>> out_pnorm = paddle.linalg.norm(x, p=float("inf"))
        >>> print(out_pnorm)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        12.)

        >>> out_pnorm = paddle.linalg.norm(x, p=float("inf"), axis=0)
        >>> print(out_pnorm)
        Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[12., 11., 10., 9. ],
         [8. , 7. , 6. , 7. ],
         [8. , 9. , 10., 11.]])

        >>> # compute -inf-order  norm
        >>> out_pnorm = paddle.linalg.norm(x, p=-float("inf"))
        >>> print(out_pnorm)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.)

        >>> out_pnorm = paddle.linalg.norm(x, p=-float("inf"), axis=0)
        >>> print(out_pnorm)
        Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[0., 1., 2., 3.],
         [4., 5., 6., 5.],
         [4., 3., 2., 1.]])
r   r   r%   r   )r~   rB   r   rT   )r)   r~   rB   r   rT   r   r   )rK   rJ   rI   rL   r   strr   r   r   ndimr	  r   r   )r)   r~   rB   r   rX   rR   rT   r   s           rZ   r   r     s   ` $Dz	D$		CINAwHHUO!S:4<:dC+@+@ F |E!&&M* t4F 9C!dD!!c$i1n t4F !F f)Mr[   ro   c                x   [        5       (       a  [        R                  " XU5      $ [        U S/ SQS5        [        US/ SQS5        [	        US[
        [        4S5        [        S0 [        5       D6nUR                  U R                  5      nU /U/S.nSU/0nS[        U5      0nUR                  SUSU0US9  U$ )	aH  

Returns the p-norm of (x - y). It is not a norm in a strict sense, only as a measure
of distance. The shapes of x and y must be broadcastable. The definition is as follows, for
details, please refer to the `Introduction to Tensor <../../guides/beginner/tensor_en.html#chapter5-broadcasting-of-tensor>`_:

- Each input has at least one dimension.
- Match the two input dimensions from back to front, the dimension sizes must either be equal, one of them is 1, or one of them does not exist.

Where, z = x - y, the shapes of x and y are broadcastable, then the shape of z can be
obtained as follows:

1. If the number of dimensions of x and y are not equal, prepend 1 to the dimensions of the
tensor with fewer dimensions.

For example, The shape of x is [8, 1, 6, 1], the shape of y is [7, 1, 5], prepend 1 to the
dimension of y.

x (4-D Tensor):  8 x 1 x 6 x 1

y (4-D Tensor):  1 x 7 x 1 x 5

2. Determine the size of each dimension of the output z: choose the maximum value from the
two input dimensions.

z (4-D Tensor):  8 x 7 x 6 x 5

If the number of dimensions of the two inputs are the same, the size of the output can be
directly determined in step 2. When p takes different values, the norm formula is as follows:

When p = 0, defining $0^0=0$, the zero-norm of z is simply the number of non-zero elements of z.

.. math::

    ||z||_{0}=\lim_{p \\rightarrow 0}\sum_{i=1}^{m}|z_i|^{p}

When p = inf, the inf-norm of z is the maximum element of the absolute value of z.

.. math::

    ||z||_\infty=\max_i |z_i|

When p = -inf, the negative-inf-norm of z is the minimum element of the absolute value of z.

.. math::

    ||z||_{-\infty}=\min_i |z_i|

Otherwise, the p-norm of z follows the formula,

.. math::

    ||z||_{p}=(\sum_{i=1}^{m}|z_i|^p)^{\\frac{1}{p}}

Args:
    x (Tensor): 1-D to 6-D Tensor, its data type is bfloat16, float16, float32 or float64.
    y (Tensor): 1-D to 6-D Tensor, its data type is bfloat16, float16, float32 or float64.
    p (float, optional): The norm to be computed, its data type is float32 or float64. Default: 2.
    name (str|None, optional): The default value is `None`. Normally there is no need for
        user to set this property. For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: Tensor that is the p-norm of (x - y).

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[3, 3],[3, 3]], dtype="float32")
        >>> y = paddle.to_tensor([[3, 3],[3, 1]], dtype="float32")
        >>> out = paddle.dist(x, y, 0)
        >>> print(out)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        1.)

        >>> out = paddle.dist(x, y, 2)
        >>> print(out)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        2.)

        >>> out = paddle.dist(x, y, float("inf"))
        >>> print(out)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        2.)

        >>> out = paddle.dist(x, y, float("-inf"))
        >>> print(out)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.)
rR   )r-   r,   r.   r/   distr~   r>   Yr@   rC   )r  )r   r   r  r   r   r   r   r   rP   rQ   rR   rS   )	r)   ro   r~   rT   rW   rX   rE   rF   rG   s	            rZ   r  r    s    x {{1##	7A6 	7A6 q#s|V,,68,F

3
3AGG
<C3aS!FsenG%(OE
FUCL   Jr[   c                x  ^   S       SU 4S jjjnSS/4       SU 4S jjjnS/4       SU 4S jjjnS n[        T R                  5      n[        U5      S:  d  [        SS	[        U5       3-   5      eUc  SnS
U;   a  S
OSnUSSSS[        R
                  [        R
                  * 4;   a  U[        U5      S-
     U[        U5      S-
     :X  a  US
:X  a  U" T USS 5      $ T R                  5       n	US:X  a  U" T 5      U" U	5      -  $ US:X  a  U" T U5      U" X5      -  $ US;   a  U" T US/S9U" XS/S9-  $ U[        R
                  [        R
                  * 4;   a  U" T US/S9U" XS/S9-  $ g[        SU S3S-   5      eUS;   a  US
:X  a  U" T USS 5      $ U" T US9$ [        SU S3S-   5      e)a  

Computes the condition number of a matrix or batches of matrices with respect to a matrix norm ``p``.

Args:
    x (Tensor): The input tensor could be tensor of shape ``(*, m, n)`` where ``*`` is zero or more batch dimensions
        for ``p`` in ``(2, -2)``, or of shape ``(*, n, n)`` where every matrix is invertible for any supported ``p``.
        And the input data type could be ``float32`` or ``float64``.
    p (float|string, optional): Order of the norm. Supported values are `fro`, `nuc`, `1`, `-1`, `2`, `-2`,
        `inf`, `-inf`. Default value is `None`, meaning that the order of the norm is `2`.
    name (str, optional): The default value is `None`. Normally there is no need for
        user to set this property. For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: computing results of condition number, its data type is the same as input Tensor ``x``.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)
        >>> x = paddle.to_tensor([[1., 0, -1], [0, 1, 0], [1, 0, 1]])

        >>> # compute conditional number when p is None
        >>> out = paddle.linalg.cond(x)
        >>> print(out)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        1.41421378)

        >>> # compute conditional number when order of the norm is 'fro'
        >>> out_fro = paddle.linalg.cond(x, p='fro')
        >>> print(out_fro)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        3.16227770)

        >>> # compute conditional number when order of the norm is 'nuc'
        >>> out_nuc = paddle.linalg.cond(x, p='nuc')
        >>> print(out_nuc)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        9.24264145)

        >>> # compute conditional number when order of the norm is 1
        >>> out_1 = paddle.linalg.cond(x, p=1)
        >>> print(out_1)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        2.)

        >>> # compute conditional number when order of the norm is -1
        >>> out_minus_1 = paddle.linalg.cond(x, p=-1)
        >>> print(out_minus_1)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        1.)

        >>> # compute conditional number when order of the norm is 2
        >>> out_2 = paddle.linalg.cond(x, p=2)
        >>> print(out_2)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        1.41421378)

        >>> # compute conditional number when order of the norm is -1
        >>> out_minus_2 = paddle.linalg.cond(x, p=-2)
        >>> print(out_minus_2)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.70710671)

        >>> # compute conditional number when order of the norm is inf
        >>> out_inf = paddle.linalg.cond(x, p=float("inf"))
        >>> print(out_inf)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        2.)

        >>> # compute conditional number when order of the norm is -inf
        >>> out_minus_inf = paddle.linalg.cond(x, p=-float("inf"))
        >>> print(out_minus_inf)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        1.)

        >>> a = paddle.randn([2, 4, 4])
        >>> print(a)
        Tensor(shape=[2, 4, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[ 0.06132207,  1.11349595,  0.41906244, -0.24858207],
          [-1.85169315, -1.50370061,  1.73954511,  0.13331604],
          [ 1.66359663, -0.55764782, -0.59911072, -0.57773495],
          [-1.03176904, -0.33741450, -0.29695082, -1.50258386]],
         [[ 0.67233968, -1.07747352,  0.80170447, -0.06695852],
          [-1.85003340, -0.23008066,  0.65083790,  0.75387722],
          [ 0.61212337, -0.52664012,  0.19209868, -0.18707706],
          [-0.00711021,  0.35236868, -0.40404350,  1.28656745]]])

        >>> a_cond_fro = paddle.linalg.cond(a, p='fro')
        >>> print(a_cond_fro)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [6.37173700 , 35.15114594])

        >>> b = paddle.randn([2, 3, 4])
        >>> print(b)
        Tensor(shape=[2, 3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[ 0.03306439,  0.70149767,  0.77064633, -0.55978841],
          [-0.84461296,  0.99335045, -1.23486686,  0.59551388],
          [-0.63035583, -0.98797107,  0.09410731,  0.47007179]],
         [[ 0.85850012, -0.98949534, -1.63086998,  1.07340240],
          [-0.05492965,  1.04750168, -2.33754158,  1.16518629],
          [ 0.66847134, -1.05326962, -0.05703246, -0.48190674]]])

        >>> b_cond_2 = paddle.linalg.cond(b, p=2)
        >>> print(b_cond_2)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [2.86566353, 6.85834455])

Nc           	     v  > [        5       (       a  [        R                  " U 5      n[        R                  " X2SS5      nUS:X  d  U[        R
                  :X  a  [        R                  " US/S5      $ US:X  d  U[        R
                  * :X  a  [        R                  " US/S5      $ g[        S0 [        5       D6nUR                  UR                  5       S9nUR                  UR                  5       S9nUR                  UR                  5       S9nUR                  SSU 0SU0S	9  [        UT5      u  prUR                  S
SU0SU0USUS.S9  US:X  d  U[        R
                  :X  a  UR                  SSU0SU0S/SUS.S9  US:X  d  U[        R
                  * :X  a  UR                  SSU0SU0S/SUS.S9  U$ )z
NOTE:
    Calculate the matrix norm of a square matrix or batches of square matrices,
    when porder is in (1, -1, inf, -inf)
NFr   r   ry   r   r>   r@   r   r   r   rC   r   r   r   )r   r   r   r   r   r   r   r   r   rP   rQ   r   rS   r"   )	r_   r   rB   r   r   r   rX   r   r)   s	           rZ   mat_normcond.<locals>.mat_norm  s    "##jj'Gjje<G{f.zz'B477|v"&&0zz'B477  1  3&(3E>>'') ? G >>'') ? G ::'') ; C OOC<%9I    0a8JOO!W~( %",	  	 {f.%>"CL "t$)&0	   	 |v"&&0%>"CL "t$)&0	   	 Jr[   r   r   c           
       > [        5       (       ai  [        R                  " X5      n[        R                  " X2SS5      n[        R                  " XBSS5      n[        R                  " U[	        SU-  5      5      $ [        S0 [        5       D6nUR                  UR                  5       S9nUR                  UR                  5       S9nUR                  UR                  5       S9nUR                  UR                  5       S9nUR                  SSU 0SU0SU0S	9  [        UT	5      u  pUR                  S
SU0SU0USUS.S	9  UR                  S
SU0SU0USUS.S	9  UR                  SSU0SU0S[	        SU-  5      0S	9  U$ )zZ
NOTE:
    Calculate the frobenius norm of a square matrix or batches of square matrices.
NFr   ry   r   r>   r@   r   rC   r   r   r   )r   r   r   r   r   r   rP   rQ   r   rS   r"   )
r_   r   rB   r   	sum_out_1	sum_out_2r   rX   r   r)   s
            rZ   fro_normcond.<locals>.fro_norm  s    "##jj/G

7$>I

9D%@I::isV|)<==3&(3E>>'') ? G @@'') A I @@'') A I ::'') ; C OOU|((	    0a8JOO!W~	* %",	  	 OO!Y'	* %",	  	 OOY'sV|!45	   Jr[   c           	     d  > [        U SS9u  p4n[        5       (       a  US:X  a  [        R                  " XBSS5      $ [        R                  " XBS5      n[        R
                  " XBS5      nUS:X  a  [        R                  " Xg5      $ US:X  a  [        R                  " Xv5      $ g[        UT5      u  p[        S0 [        5       D6n	U	R                  U	R                  5       S9n
US:X  a  U	R                  SS	U0S
U
0USUS.S9  U
$ U	R                  U	R                  5       S9nU	R                  U	R                  5       S9nU	R                  SS	U0S
U0USUS.S9  U	R                  SS	U0S
U0USUS.S9  US:X  a  U	R                  SXgS.S
U
0SS0S9  U
$ US:X  a  U	R                  SXvS.S
U
0SS0S9  U
$ g)z
NOTE:
    Calculate the matrix norm, which is related to singular values, of a matrix
    or batches of matrices, including nuclear norm, 2-norm and (-2)-norm.
Fr   r&   Nr   r   ry   r   r>   r@   r   rC   r   r   elementwise_divr  rB   r   r   )r   r   r   r   r   r   divider"   r   rP   rQ   r   rS   )r_   r   rB   r   r   r   max_outmin_outr   r   rX   r)   s              rZ   svd_normcond.<locals>.svd_norm;  s'    uE2b!##zz!477jj%0Gjj%0G{}}W66|}}W66   0a8J3&(3E::'') ; C %8"CL#$)&0	   	 
>>'') ? G >>'') ? G OO!Qx( %",	  	 OO!Qx( %",	  	 {*!(7"CL!2,	    
|*!(7"CL!2,	    
 r[   c                   [        5       (       a  [        5       (       a  [        S5      eU R                  5       n[	        U5      S:X  a&  US:X  a   U R                  S/5      R                  5       $ [        R                  " U5      nUS:  a[  US:X  aU  [        R                  " U R                  5       [        R                  " U/U R                  S9/5      nUR                  U5      $ U R                  U5      $ [        S5      e)Nz6only support x is nonempty tensor in static graph moder   ry   )r   r   rN   numelrL   reshaper   mathprodr   concatflattenzerosrR   )r_   rM   old_sizenew_sizetmps        rZ   empty_tensorcond.<locals>.empty_tensor  s    !##}} L 
 {{}H5zQ8q=}}aS)--//yy'H!|AmmhZu{{C {{5))==''D
 	
r[   z1input should be a matrix or batches of matrices, z'but the dimension of received input is r   r   r%   r&   r   r   r   )r   rB   zonly support p is z when input is a z+square matrix or batches of square matrices)r   r   )r   zunsupported z' for p, only supporting ('fro', 'nuc', z 1, -1, 2, -2, inf, -inf) or none)r   N)r_   r$   r   r   rB   r  r  r$   )r_   r$   r   r   rB   z	list[int]r  r$   )rI   rM   rL   rN   r   r   inverse)
r)   r~   rT   r  r  r!  r.  rY   x_sizex_invs
   `         rZ   condr4  G  s   j FJ@@$@2B@	@ @F ()RD<<$<09<	< <~ :<NN$N,5N	N N`
4 177mGw<1?7G~FG
 	
 	y<QaFUE1b"&&266'223w<!#$Gq0@(AA{#Aws|44IIKEEz{Xe_44Ez1~(:::G|!2$7(2$;   RVVbffW%%!2$7(2$;   &
 $QC'89?@  
gQ;73B<00!$$1#DE01
 	
r[   c                F    U R                  5       U-  R                  US9nU$ )ag  
Computes the dot product of two tensors along a specified axis.

This function multiplies two tensors element-wise and sums them along a specified axis to compute their dot product. It supports tensors of any dimensionality, including 0-D tensors, as long as the shapes of `x` and `y` are broadcastable along the specified axis.

Args:
    x (Tensor): The first input tensor. It should be a tensor with dtype of float32, float64, int32, int64, complex64, or complex128.
    y (Tensor): The second input tensor. Its shape must be broadcastable with `x` along the specified `axis`, and it must have the same dtype as `x`.
    axis (int, optional): The axis along which to compute the dot product. Default is -1, which indicates the last axis.
    name (str|None, optional): Name of the output. Default is None. It's used to print debug info for developers. Details: :ref:`api_guide_Name`

Returns:
    Tensor: A tensor containing the dot product of `x` and `y` along the specified axis.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> x = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype='float32')
        >>> y = paddle.to_tensor([[1, 2, 3], [4, 5, 6]], dtype='float32')
        >>> result = paddle.linalg.vecdot(x, y, axis=1)
        >>> print(result)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [14.0, 77.0])
rB   )conjr   )r)   ro   rB   rT   rX   s        rZ   vecdotr8    s'    @ 668a<

$

'CJr[   c                   Sn[        U R                  5      S:  d  [        U R                  5      S:  a"  [        S[        U R                  5       S35      e[        U SSS/S5        U n[        U R                  5      S:X  a  U R	                  S	5      nU(       d#  UR                  S
   S:w  a  UR                  5       nSnUR                  S   n	UGb  UR                  UR                  5      n[        UR                  5      S:  a"  [        S[        UR                  5       S35      eUR                  S
   U	:w  a  [        SU	 SUR                  S
    S35      eUR                  5       S
:  a  [        SUR                  5        S35      e[        R                  " U[        R                  " UR                  S5      5      R                  UR                  5      :H  5      (       d  [        S5      eUb  UR                  UR                  5      n
[        U
R                  5      S:  a"  [        S[        UR                  5       S35      e[        USSS/S5        UR                  S
   U	:w  a  [        SU	 SUR                  S
    S35      eUR                  5       S
:  a  [        SUR                  5        S35      eUb  X-  nOU
n[        R                  " XR                  S9nUc  Ub/  UR                  5       nUR                  5       S
:X  a  [        S5      eUb  Xx-  nUR                  SS9U-  nOUR                  SS9U-  nUnUb<  Ub9  U(       a2  XUR                  UR                  5      -  R                  5       U-  -
  nOX-
  n[        R                  " US
S9nX}R!                  S5      -
  n[        R"                  " X|R                  5       R%                  5       5      n[        R&                  " X5      R)                  5       nU$ )u  
Estimate the covariance matrix of the input variables, given data and weights.

A covariance matrix is a square matrix, indicate the covariance of each pair variables in the input matrix.
For example, for an N-dimensional samples X=[x1,x2,…xN]T, then the covariance matrix
element Cij is the covariance of xi and xj. The element Cii is the variance of xi itself.

Parameters:
    x (Tensor): A N-D(N<=2) Tensor containing multiple variables and observations. By default, each row of x represents a variable. Also see rowvar below.
    rowvar (bool, optional): If rowvar is True (default), then each row represents a variable, with observations in the columns. Default: True.
    ddof (bool, optional): If ddof=True will return the unbiased estimate, and ddof=False will return the simple average. Default: True.
    fweights (Tensor, optional): 1-D Tensor of integer frequency weights; The number of times each observation vector should be repeated. Default: None.
    aweights (Tensor, optional): 1-D Tensor of observation vector weights. How important of the observation vector, larger data means this element is more important. Default: None.
    name (str|None, optional): Name of the output. Default is None. It's used to print debug info for developers. Details: :ref:`api_guide_Name` .

Returns:
    Tensor: The covariance matrix Tensor of the variables.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)

        >>> xt = paddle.rand((3, 4))
        >>> paddle.linalg.cov(xt)
        >>> print(xt)
        Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[0.86583614, 0.52014720, 0.25960937, 0.90525323],
         [0.42400089, 0.40641287, 0.97020894, 0.74437362],
         [0.51785129, 0.73292869, 0.97786582, 0.04315904]])
covr   r   zZInput(x) only support N-D (1<=N<=2) tensor in cov, but received length of Input(input) is r<   rR   r.   r/   r0  r   Nz]Input(fweights) only support N-D (N<=1) tensor in cov, but received shape of Input(input) is z:The number of Input(fweights) should equal to x's dim[1]: z*, but received size of Input(fweights) is zXThe value of Input(fweights) cannot be negative, but received min of Input(fweights) is z Input(fweights) must be integer z^Input(aweights) only support N-D (N<=1) tensor in cov, but received length of Input(input) is z:The number of Input(aweights) should equal to x's dim[1]: z*, but received size of Input(aweights) is zXThe value of Input(aweights) cannot be negative, but received min of Input(aweights) is ry   z0The sum of weights is zero, can't be normalized.r6  r   )rL   rM   rN   r   r%  tr   rR   r   r   allround	to_tensorr   itemclipr   mmr7  r  squeeze)r)   rowvarddoffweightsaweightsrT   op_typenxwobservation_numaww_sumnx_wavgnorm_factorxxtr:  s                    rZ   r:  r:    s   R G
177|a3qww<!+)),QWWa9
 	
 Q)Y)?G	
B
177|qYYwbhhqkQ&TTVAhhqkOOOBHH%qww<!,,/,?+@C  >>!/L_L] ^..6nnQ.?-@C  <<>A--5\\^,<A?  zz||HOOI67>>x~~NO
 
 ?@@__RXX&rxx=1--0-@,AD  	!g	95u	
 >>!/L_L] ^..6nnQ.?-@C  <<>A--5\\^,<A?  =AA_HH=Ex3::<1OPP}vjjaj 5(ff!fnu$}-$8??177#;;@@BUJJl++kq1K	mmA	B
))B
(C
--
)
1
1
3CJr[   c                0   [        U R                  5      S:  a"  [        S[        U R                  5       S35      e[        5       (       a7  [        U R                  5      S::  a  U $ SS/n[        R
                  " X5      nU$ [        U S/ SQS5        [        S0 [        5       D6nUR                  U R                  5      nUR                  U R                  5      n[        U R                  5      S::  a  U nU$ UR                  S	S
U /0U/U/S.SSS/0S9  U$ )a  
Transpose <=2-D tensor.
0-D and 1-D tensors are returned as it is and 2-D tensor is equal to
the paddle.transpose function which perm dimensions set 0 and 1.

Args:
    input (Tensor): The input Tensor. It is a N-D (N<=2) Tensor of data types float32, float64, int32, int64.
    name (str|None, optional): The default value is None.  Normally there is no need for
        user to set this property.  For more information, please refer to :ref:`api_guide_Name` .

Returns:
    Tensor: A transposed n-D Tensor, with data type being float16, float32, float64, int32, int64.

Examples:

    .. code-block:: pycon
        :name: code-example

        >>> import paddle

        >>> # Example 1 (0-D tensor)
        >>> x = paddle.to_tensor([0.79])
        >>> out = paddle.t(x)
        >>> print(out)
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.79000002])

        >>> # Example 2 (1-D tensor)
        >>> x = paddle.to_tensor([0.79, 0.84, 0.32])
        >>> out2 = paddle.t(x)
        >>> print(out2)
        Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.79000002, 0.83999997, 0.31999999])
        >>> print(paddle.t(x).shape)
        paddle.Size([3])

        >>> # Example 3 (2-D tensor)
        >>> x = paddle.to_tensor([[0.79, 0.84, 0.32], [0.64, 0.14, 0.57]])
        >>> print(x.shape)
        paddle.Size([2, 3])
        >>> out3 = paddle.t(x)
        >>> print(out3)
        Tensor(shape=[3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[0.79000002, 0.63999999],
         [0.83999997, 0.14000000],
         [0.31999999, 0.56999999]])
        >>> print(paddle.t(x).shape)
        paddle.Size([3, 2])

r   TInput(input) only support N-D (N<=2) tensor, but received length of Input(input) is 8. Perhaps you can use paddle.tensor.transpose() instead.r   r   r_   )r,   r.   r/   r3   r4   r5   r:   r=   r>   r?   rB   rC   )r<  )rL   rM   rN   r   r   r:   r   r   rP   rQ   rR   rS   )r_   rT   r;   rX   rW   r   s         rZ   r<  r<  r  s*   f 5;;!)),U[[)9(: ;**
 	

 u{{q L1vu+
 I		
 -FH-77D??Lu{{q C 
 !eW~!$+?1v&	   
r[   c                   [        U R                  5      S:  a"  [        S[        U R                  5       S35      e[        5       (       a7  [        U R                  5      S::  a  U $ SS/n[        R
                  " X5      nU$ g)z}
Inplace version of ``t`` API, the output Tensor will be inplaced with input ``input``.
Please refer to :ref:`api_paddle_t`.
r   rS  rT  r   r   N)rL   rM   rN   r   r   r]   )r_   rT   r;   rX   s       rZ   t_rV    s     5;;!)),U[[)9(: ;**
 	

 u{{q L1v,
 r[   c                <   [        5       (       a"  Uc  [        OUn[        R                  " XU5      $ [	        U S/ SQS5        [	        US/ SQS5        [        S	0 [        5       D6nUR                  U R                  5      n0 nX&S'   UR                  SXS.SU0US9  U$ )
a  
Computes the cross product between two tensors along an axis.

Inputs must have the same shape, and the length of their axes should be equal to 3.
If `axis` is not given, it defaults to the first axis found with the length 3.

Args:
    x (Tensor): The first input tensor, the data type is float16, float32, float64, int32, int64, complex64, complex128.
    y (Tensor): The second input tensor, the data type is float16, float32, float64, int32, int64, complex64, complex128.
    axis (int, optional): The axis along which to compute the cross product. It defaults to be 9 which indicates using the first axis found with the length 3.
    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 Tensor with same data type as `x`.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1.0, 1.0, 1.0],
        ...                         [2.0, 2.0, 2.0],
        ...                         [3.0, 3.0, 3.0]])
        >>> y = paddle.to_tensor([[1.0, 1.0, 1.0],
        ...                         [1.0, 1.0, 1.0],
        ...                         [1.0, 1.0, 1.0]])
        ...
        >>> z1 = paddle.cross(x, y)
        >>> print(z1)
        Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-1., -1., -1.],
         [ 2.,  2.,  2.],
         [-1., -1., -1.]])

        >>> z2 = paddle.cross(x, y, axis=1)
        >>> print(z2)
        Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[0., 0., 0.],
         [0., 0., 0.],
         [0., 0., 0.]])
r)   )r,   r5   r.   r/   r3   r4   r6   r7   crossro   rV   r  r@   rC   )rX  )
r   K_DEFAULT_DIMr   rX  r   r   rP   rQ   rR   rS   )r)   ro   rB   rT   rW   rX   rG   s          rZ   rX  rX    s    `  $}$||A$'' 	 	
 	!	 	
 1177@e#CL	 	 	
 
r[   c                z   [        5       (       aD  U R                  n[        U5      S:  a  US   US   :X  d   S5       e[        R                  " X5      $ [        U SSS/S5        [        US	[        S5        [        S0 [        5       D6nUR                  U R                  S
9nUR                  SSU /0SU0S	U0S9  U$ )aS  
Computes the Cholesky decomposition of one symmetric positive-definite
matrix or batches of symmetric positive-definite matrices.

If `upper` is `True`, the decomposition has the form :math:`A = U^{T}U` ,
and the returned matrix :math:`U` is upper-triangular. Otherwise, the
decomposition has the form  :math:`A = LL^{T}` , and the returned matrix
:math:`L` is lower-triangular.

Args:
    x (Tensor): The input tensor. Its shape should be `[*, M, M]`,
        where * is zero or more batch dimensions, and matrices on the
        inner-most 2 dimensions all should be symmetric positive-definite.
        Its data type should be float32 or float64.
    upper (bool, optional): The flag indicating whether to return upper or lower
        triangular matrices. Default: 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, A Tensor with same shape and data type as `x`. It represents
    triangular matrices generated by Cholesky decomposition.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)

        >>> a = paddle.rand([3, 3], dtype="float32")
        >>> a_t = paddle.transpose(a, [1, 0])
        >>> x = paddle.matmul(a, a_t) + 1e-03

        >>> out = paddle.linalg.cholesky(x, upper=False)
        >>> print(out)
        Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[1.04337072, 0.        , 0.        ],
         [1.06467664, 0.17859250, 0.        ],
         [1.30602181, 0.08326444, 0.22790681]])
r   r   r   zLShape must have at least 2 dimensions and last two dimensions must be equal.rR   r.   r/   choleskyupperry   r>   r@   rC   )r[  )r   rM   rL   r   r[  r   r   r+   r   rP   rQ   rR   rS   )r)   r\  rT   rY   rW   rX   s         rZ   r[  r[  >  s    R ''7|q WR[GBK%? 	
Z	
? q(( Gi-CZP5'44468477agg7F!:CLE"	 	 	
 
r[   c                l   U R                   [        R                  :X  a  [        R                  O9U R                   [        R                  :X  a  [        R
                  OU R                   nSnUc  Ub  Ub  [        S5      eSnU(       GaD  Uc  [        / SU5      n[        U[        [        45      (       a  [        / X65      nUR                   U:w  a  [        X65      nUb[  [        U[        [        45      (       a  [        / XF5      nUR                   U:w  a  [        XF5      n[        R                  " X4/5      u  p4[        5       (       a  [        R                  " XXB5      $ 0 n0 n	[!        U S/ SQS5        XS'   X8S'   XHS	'   [#        US
[$        S5        X)S
'   ['        S0 [)        5       D6n
U
R+                  SS9nU
R-                  SUSU0U	S9  U$ [        5       (       a  [        U[.        [        R0                  R2                  45      (       a7  UR                   U:w  a  [        X5      nOUnSn[        R4                  " XX5      $ Uc  SnSnO[        U5      nSn[        R6                  " XX5      $ 0 n0 n	[!        U S/ SQS5        XS'   Uc  SU	S'   OY[        U[.        5      (       a)  SU	S'   UR                   U:w  a  [        X5      US'   O XS'   O[#        US[        S5        SU	S'   XS'   [#        US
[$        S5        X)S
'   ['        S0 [)        5       D6n
U
R+                  SS9nU
R-                  SUSU0U	S9  U$ )a  
Computes the rank of a matrix.

Notes:
    1. Support the use of attribute `tol` alone or the use of attributes `atol` and `rtol` together without `tol`.

    2. When `tol` is used alone, it will return the rank of a matrix is the number of singular values that are greater than the specified `tol`
    threshold when hermitian=False, or the number of eigenvalues in absolute value that are greater than the specified `tol` threshold
    when hermitian=True. It is compatible with numpy API.

    3. When `atol` and `rtol` are used, the tolerance value is computed as `max(atol, sigma_1 * rtol)`, where sigma_1 is largest
    singular value (or eigenvalues in absolute value).

    4. When `atol` and `rtol` are used: If `rtol` is not specified, then it is set to be `max(m,n) * eps`, where `x` has dimension(m, n) and
    `eps` is the epsilon value for the dtype of `x`; If `rtol` is not specified and `atol` is specified to be greater than 0, then it
    is set to be 0.

Args:
    x (Tensor): The input tensor. Its shape should be `[..., m, n]`, where `...` is zero or more batch dimensions. If `x` is a batch
        of matrices then the output has the same batch dimensions. The data type of `x` should be float32, float64, complex64 or complex128.
    tol (float|Tensor, optional): The tolerance value. If `tol` is not specified, and `sigma` is the largest singular value
        (or eigenvalues in absolute value), and `eps` is the epsilon value for the dtype of `x`, then `tol` is computed with formula
        `tol=sigma * max(m,n) * eps`. Note that if `x` is a batch of matrices, `tol` is computed this way for every batch. Default: None.
    hermitian (bool, optional): Indicates whether `x` is Hermitian. Default: False. When hermitian=True, `x` is assumed to be Hermitian,
        enabling a more efficient method for finding eigenvalues, but `x` is not checked inside the function. Instead, We just use
        the lower triangular of the matrix to compute. Default: False.
    atol (float|Tensor, optional): The absolute tolerance value. When None it is considered to be 0. Default: None.
    rtol (float|Tensor, optional): The relative tolerance value. See above Notes for the value it takes when None. Default: None.
    name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: Rank of tensor x.

Examples:
    .. code-block:: pycon

        >>> import paddle

        >>> a = paddle.eye(10)
        >>> b = paddle.linalg.matrix_rank(a)
        >>> print(b)
        Tensor(shape=[], dtype=int64, place=Place(cpu), stop_gradient=True,
               10)

        >>> c = paddle.ones(shape=[3, 4, 5, 5])
        >>> d = paddle.linalg.matrix_rank(c, tol=0.01, hermitian=True)
        >>> print(d)
        Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True,
               [[1, 1, 1, 1],
                [1, 1, 1, 1],
                [1, 1, 1, 1]])

Fz?Only support to use tol alone or use atol and rtol without tol.Tr   r)   r.   r/   r6   r7   matrix_rank_atol_rtolatolrtol	hermitianr3   ry   rX   rC   matrix_rankr>   use_default_tol	TolTensortolr@   )r_  )rc  )rR   r   r6   r.   r7   r/   rN   r    rK   r   r   r!   broadcast_tensorsr   r   r_  r   r   r+   r   rP   rQ   rS   r   pirValuematrix_rank_tolrc  )r)   rf  rb  r`  ra  rT   target_dtypeuse_atol_rtolrE   rG   rW   rX   
tol_tensorrd  tol_attrs                  rZ   rc  rc  {  s>   ~ 77f&&& 	 !6+<+< <fnn!''  Md.?Q  <C.DdUCL))D/D::%+D$--B3zz\)D/114,?JD!##//IIFE$A'	 3K!6N!6Ny+t5LM!*+ EFHEF;;';JC,	   J!###&***:*:;<<99,!%c!8J!$J"'--?  {"& :"'%%a?NNFE$A	 3K{+/'(C**+0'(99,*.s*AF;'*-;'3um<+0'("ey+t]C!*+ ;&(;F;;';JC"	   Jr[   c           
     8   [        U[        5      (       a  [        U5      n[        U[        5      (       a  [        U5      n[        5       (       a  [        R
                  " XXX55      $ [        S
0 [        5       D6n[        U S/ SQS5        U(       d  U(       a?  U(       a  [        US/ SQS5        UR                  [        R                  R                  S9nO'UR                  [        R                  R                  S9nUR                  SXS.SU0UUUUS.S	9  U$ )a  
Computes the histogram of a tensor. The elements are sorted into equal width bins between min and max.
If min and max are both zero, the minimum and maximum values of the data are used.

Args:
    input (Tensor): A Tensor with shape :math:`[N_1, N_2,..., N_k]` . The data type of the input Tensor
        should be float32, float64, int32, int64.
    bins (int, optional): number of histogram bins. Default: 100.
    min (float, optional): lower end of the range (inclusive). Default: 0.0.
    max (float, optional): upper end of the range (inclusive). Default: 0.0.
    weight (Tensor, optional): If provided, it must have the same shape as input. Each value in input contributes its associated
        weight towards the bin count (instead of 1). Default: None.
    density (bool, optional): If False, the result will contain the count (or total weight) in each bin. If True, the result is the
        value of the probability density function over the bins, normalized such that the integral over the range of the bins is 1.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    Tensor, shape is (nbins,), the counts or density of the histogram.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> inputs = paddle.to_tensor([1, 2, 1])
        >>> result = paddle.histogram(inputs, bins=4, min=0, max=3)
        >>> print(result)
        Tensor(shape=[4], dtype=int64, place=Place(cpu), stop_gradient=True,
        [0, 2, 1, 0])
	histogramr>   r3   r4   r.   r/   Weightry   )r>   rr  r@   )binsr   r   densityrC   )rp  )rK   r   r   r   r   rp  r   rP   r   rQ   r   VarTypeFP32INT64rS   )	r_   rs  r   r   weightrt  rT   rW   rX   s	            rZ   rp  rp  '	  s   N #sCj#sCjt#GG5FH5 3@+	
 W(<	 ;;oo** < C ;;oo++ < C 	1CL"		 	 
	
 
r[   c                   [        U[        5      (       a  [        U5      n[        U[        5      (       a  [        U5      n[        U S[        S5        [        U R                  S/ SQS5        [        US[        S5        US:X  a3  US:X  a-  [        R                  " U 5      n[        R                  " U 5      nOX2:  a  [        S5      eX#-
  S:X  a
  US-   nUS-
  n[        R                  " X#US-   US	9$ )
a  
Computes only the edges of the bins used by the histogram function.
If min and max are both zero, the minimum and maximum values of the data are used.

Args:
    input (Tensor): The data type of the input Tensor should be float32, float64, int32, int64.
    bins (int, optional): number of histogram bins.
    min (float, optional): lower end of the range (inclusive). Default: 0.0.
    max (float, optional): upper end of the range (inclusive). Default: 0.0.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    Tensor, the values of the bin edges. The output data type will be float32.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> inputs = paddle.to_tensor([1, 2, 1])
        >>> result = paddle.histogram_bin_edges(inputs, bins=4, min=0, max=3)
        >>> print(result)
        Tensor(shape=[5], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.        , 0.75000000, 1.50000000, 2.25000000, 3.        ])
r_   histogram_bin_edges)r.   r/   r3   r4   rs  r   z.max must be larger than min in range parameterg      ?r   )rT   )rK   r   r   r   r   r   rR   r   r   r   rN   linspace)r_   rs  r   r   rT   s        rZ   rz  rz  y	  s    @ #sCj#sCjug+@A0	 tVS"78
czcSjjjjj9MNN	cCiCi??3TAXD99r[   c                   U R                   [        R                  [        R                  [        R
                  [        R                  4;  a  [        S5      e[        5       (       a  [        R                  " XU5      $ [        S0 [        5       D6n[        U SSS/S5        Ub*  [        US/ SQS5        UR                  UR                   S9nOUR                  U R                   S9nUR                  SXS	.S
U0SU0S9  U$ )a  
Computes frequency of each value in the input tensor.

Args:
    x (Tensor): A Tensor with non-negative integer. Should be 1-D tensor.
    weights (Tensor, optional): Weight for each value in the input tensor. Should have the same shape as input. Default is None.
    minlength (int, optional): Minimum number of bins. Should be non-negative integer. Default is 0.
    name (str|None, optional): Normally there is no need for user to set this property.
        For more information, please refer to :ref:`api_guide_Name`. Default is None.

Returns:
    Tensor: The tensor of frequency.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([1, 2, 1, 4, 5])
        >>> result1 = paddle.bincount(x)
        >>> print(result1)
        Tensor(shape=[6], dtype=int64, place=Place(cpu), stop_gradient=True,
        [0, 2, 1, 0, 1, 1])

        >>> w = paddle.to_tensor([2.1, 0.4, 0.1, 0.5, 0.5])
        >>> result2 = paddle.bincount(x, weights=w)
        >>> print(result2)
        Tensor(shape=[6], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.        , 2.19999981, 0.40000001, 0.        , 0.50000000, 0.50000000])
z+Elements in Input(x) should all be integersbincountr>   r3   r4   Weightsrq  ry   )r>   r~  r@   	minlengthrC   )r}  )rR   r   r3   r4   r   INT32rw  	TypeErrorr   r   r}  r   rP   r   rQ   rS   )r)   weightsr  rT   rW   rX   s         rZ   r}  r}  	  s    H 	ww	  EFFq9554684 C'7);ZH$8	 ;;'--;PC;;!'';JC/CL	*	 	 	
 
r[   c                    [        5       (       a  [        R                  " X5      $ S nU" X5        [        S0 [	        5       D6nUR                  U R                  S9nUR                  SXS.SU0S9  U$ )a  
Performs a matrix-vector product of the matrix x and the vector vec.

Args:
    x (Tensor): A tensor with shape :math:`[M, N]` , The data type of the input Tensor x
        should be one of float32, float64.
    vec (Tensor): A tensor with shape :math:`[N]` , The data type of the input Tensor x
        should be one of float32, float64.
    name (str|None, optional): Normally there is no need for user to set this property.
        For more information, please refer to :ref:`api_guide_Name`. Default is None.

Returns:
    Tensor: The tensor which is produced by x and vec.

Examples:
    .. code-block:: python

        >>> # x: [M, N], vec: [N]
        >>> # paddle.mv(x, vec)  # out: [M]

        >>> import paddle

        >>> x = paddle.to_tensor([[2, 1, 3], [3, 0, 1]]).astype("float64")
        >>> vec = paddle.to_tensor([3, 5, 1]).astype("float64")
        >>> out = paddle.mv(x, vec)
        >>> print(out)
        Tensor(shape=[2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [14., 10.])
c                $   XS.nUR                  5        H  u  p4[        XCSS/S5        M     [        U R                  5      n[        UR                  5      n[	        U5      S:w  a  [        SU 35      e[	        U5      S:w  a  [        SU 35      eg )	N)r)   vecr.   r/   mvr   z7x should be 2-dimensional. But received x's dimension: r   z;vec should be 1-dimensional. But received vec's dimension: )rr   r   rI   rM   rL   rN   )r)   r  rt   rT   ru   rY   	vec_shapes          rZ   rv   mv.<locals>.__check_input
  s    ,I&__.	(	95t / 177mGSYYI7|q  MgYW  9~" QR[Q\]  #r[   r  ry   )r>   Vecr@   r   )r  )r   r   r  r   rP   rQ   rR   rS   )r)   r  rT   rv   rW   rX   s         rZ   r  r  	  sy    < yy  	" 	a.VX.77agg7FA2UCL 	 	
 
r[   c                   [        5       (       a  [        R                  " U 5      $ [        U R                  S/ SQS5        [        U R                  5      n[        U5      S:  d   S[        U5       S35       eUS   US   :X  d   S	US    S
US    S35       e[        S0 [        5       D6nUR                  U R                  S9nUR                  SSU /0SU/0S9  U$ )a+  

Calculates determinant value of a square matrix or batches of square matrices.

Args:
    x (Tensor): the input matrix of size `(n, n)` or the
        batch of matrices of size `(*, n, n)` where `*` is one or more
        batch dimensions.
    name (str|None, optional): Name of the output.It's used to print debug info for
        developers. Details: :ref:`api_guide_Name`. Default is None.

Returns:
    Tensor, the determinant value of a square matrix or batches of square matrices.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)
        >>> x =  paddle.randn([3,3,3])
        >>> A = paddle.linalg.det(x)
        >>> print(A)
        Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [-1.29280925,  0.77832544,  0.89754158])


Inputr,   r.   r/   r6   r7   detr   JThe x must be at least 2-dimensional, but received Input x's dimensional: .
r   r   "Expect squared input,but received  by 	 matrix.
determinantry   r@   r   )r  )r   r   r  r   rR   rI   rM   rL   r   rP   rQ   rS   r)   rT   r   rW   rX   s        rZ   r  r  5
  s
   8 zz!}GGH		
 177m;1$ 	
336{3C2DCI	
$
 2+b/1 	
'O,DR0AM	
1 7fh777agg7F!~u~ 	 	
 
r[   c                   [        5       (       a  [        R                  " U 5      $ [        U R                  S/ SQS5        [        U R                  5      n[        U5      S:  d   S[        U5       S35       eUS   US   :X  d   S	US    S
US    S35       e[        S0 [        5       D6nUR                  U R                  S9nUR                  SSU /0SU/0S9  U$ )az  

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)`.

Args:
    x (Tensor): the batch of matrices of size :math:`(*, n, n)`
        where math:`*` is one or more batch dimensions.
    name (str|None, optional): Name of the output.It's used to print debug info for
        developers. Details: :ref:`api_guide_Name`. Default is None.

Returns:
    y (Tensor), A tensor containing the sign of the determinant and the natural logarithm
    of the absolute value of determinant, respectively. The output shape is :math:`(2, *)`,
    where math:`*` is one or more batch dimensions of the input `x`.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)
        >>> x = paddle.randn([3, 3, 3])
        >>> A = paddle.linalg.slogdet(x)
        >>> print(A)
        Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-1.        ,  1.        ,  1.        ],
         [ 0.25681755, -0.25061053, -0.10809582]])

r  r^  slogdetr   r  r  r   r   r  r  r  slogdeterminantry   r@   r   )r  )r   r   r  r   rR   rI   rM   rL   r   rP   rQ   rS   r  s        rZ   r  r  n
  s   L ~~a  GG=		
 177m;1$ 	
336{3C2DCI	
$
 2+b/1 	
'O,DR0AM	
1 ;&(;77agg7F"aS>SEN 	 	

 
r[   rX   c                  [        5       (       a  [        R                  " XUS9$ [        U S/ SQS5        [	        US[
        S5        [        S
0 [        5       D6nUR                  U R                  S9nUR                  U R                  S9nUR                  U R                  S9n0 nXS'   UR                  SSU /0XVUS.US	9  XWU4$ )a	  
Computes the singular value decomposition of one matrix or a batch of regular matrices.

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

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

Args:
    x (Tensor): The input tensor. Its shape should be `[..., N, M]`,
        where `...` is zero or more batch dimensions. N and M can be arbitrary
        positive number. Note that if x is singular matrices, the grad is numerical
        instable. The data type of x should be float32, float64, complex64 or complex128.
    full_matrices (bool, optional): A flag to control the behavior of svd.
        If full_matrices = True, svd op will compute full U and V matrices,
        which means shape of U is `[..., N, N]`, shape of V is `[..., M, M]`. K = min(M, N).
        If full_matrices = False, svd op will use a economic method to store U and V.
        which means shape of U is `[..., N, K]`, shape of V is `[..., M, K]`. K = min(M, N).
        Default value is False.
    name (str|None, optional): Name for the operation. For more information,
        please refer to :ref:`api_guide_Name`. Default value is None.

Returns:
    - U (Tensor), is the singular value decomposition result U.
    - S (Tensor), is the singular value decomposition result S.
    - VH (Tensor), VH is the conjugate transpose of V, which is the singular value decomposition result V.

    Tuple of 3 tensors(U, S, VH): VH is the conjugate transpose of V. S is the singular value vectors of matrices with shape `[..., K]`

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1.0, 2.0], [1.0, 3.0], [4.0, 6.0]]).astype('float64')
        >>> x = x.reshape([3, 2])
        >>> u, s, vh = paddle.linalg.svd(x)
        >>> print (u)
        Tensor(shape=[3, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[-0.27364809, -0.21695147],
         [-0.37892198, -0.87112408],
         [-0.88404460,  0.44053933]])

        >>> print (s)
        Tensor(shape=[2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [8.14753743, 0.78589688])

        >>> print (vh)
        Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[-0.51411221, -0.85772294],
         [ 0.85772294, -0.51411221]])

        >>> # one can verify : U * S * VT == X
        >>> #                  U * UH == I
        >>> #                  V * VH == I
r  rR   r^  r   r   ry   r>   r   rC   )r   )r   r   r   r   r   r+   r   rP   rQ   rR   rS   )	r)   r   rT   rX   rW   r   r   r   rG   s	            rZ   r   r   
  s    @ zz!44 wI5	
 	=/4?/fh/55AGG5D66QWW6E55AGG5D!.o!:A.	 	 	
 Rxr[   c                .    [         R                  " U 5      $ )a  
Computes the singular values of one matrix or a batch of matrices.

Let :math:`X` be the input matrix or a batch of input matrices,
the output singular values :math:`S` are the diagonal elements of the matrix
produced by singular value decomposition:

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

Args:
    x (Tensor): The input tensor. Its shape should be `[..., M, N]`, where
        `...` is zero or more batch dimensions. The data type of x should
        be float32 or float64.
    name (str|None, optional): Name for the operation. For more
        information, please refer to :ref:`api_guide_Name`.
        Default: None.

Returns:
    Tensor: Singular values of x. The shape is `[..., K]`, where `K = min(M, N)`.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1.0, 2.0], [1.0, 3.0], [4.0, 6.0]])
        >>> s = paddle.linalg.svdvals(x)
        >>> print(s)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [8.14753819, 0.78589684])
)r   svdvalsrd   s     rZ   r  r  	  s    B >>!r[   c                P    U R                  5       (       a  U R                  5       $ U $ r   )r   r7  r)   s    rZ   
_conjugater  -  s    ||~~vvxHr[   c                    U R                   n[        [        S[        U5      5      5      n/ US S QUS   PUS   Pn[        R
                  " X5      $ )Nr   r   r   )rM   rI   r   rL   r   r:   )r)   rM   r;   s      rZ   
_transposer  3  sS    GGEaU$%D+T#2Y+R+$r(+DA$$r[   c                *    [        [        U 5      5      $ r   )r  r  r  s    rZ   _transjugater  :  s    jm$$r[   c                <   Uc  SOUnU R                   SS  u  pE[        R                  R                  n[        R                  " XQ4U R
                  S9n[        U 5      n[        U5      n	Ucq  U" [        R                  " X5      5      S   n
[        U5       HA  nU" [        R                  " X5      5      S   n
U" [        R                  " X
5      5      S   n
MC     U
$ [        U5      nU" [        R                  " X5      [        R                  " X75      -
  5      S   n
[        U5       Ho  nU" [        R                  " X5      [        R                  " X5      -
  5      S   n
U" [        R                  " X
5      [        R                  " X:5      -
  5      S   n
Mq     U
$ )Nr   r   ry   r   )rM   r   linalgqrrandnrR   r  r  r   r   r  )r)   qniterMmnr  RA_tA_HQr   M_Hs                rZ   _get_approximate_basisr  >  sI   AEE7723<DA			BaV177+A
Q-C
S/Cyv}}Q"#A&uA6==()!,A6==&'*A  H 1ov}}Q"V]]1%889!<uA6==(6==+@@A!DA6==&q)<<=a@A  Hr[   c           	        [         R                  " U 5      (       d  [        S[        U 5       35      eU R                  SS u  pVUc  [        SXV5      nO>[        XV5      S:w  a/  US:  a  U[        XV5      ::  d  [        SU S[        XV5       35      eUS:  d  [        SU S	35      eUc  SnO&UR                  U R                  5      n[        U5      n[        U 5      nXV:  d  Xa:  Ga+  [        XX'S
9n	[        U	5      n
Uc  [         R                  " X
5      nO-[         R                  " X
5      [         R                  " X:5      -
  nUR                  S   U:X  d   UR                  U45       eUR                  S   S:w  a&  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[        U5      nU	R                  U5      nGO4[        XX#S
9n	[        U	5      n
Uc  [         R                  " X5      nO-[         R                  " X5      [         R                  " Xz5      -
  n[        U5      nUR                  S   S:w  a&  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[        U5      nU	R                  U5      nXU4$ )aS
  
Return the singular value decomposition (SVD) on a low-rank matrix or batches of such matrices.

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

.. math::
    X \approx U * diag(S) * V^{H}

When :math:`M` is given, the output should satisfies:

.. math::
    X - M \approx U * diag(S) * V^{H}

Args:
    x (Tensor): The input tensor. Its shape should be `[..., N, M]`, where `...` is
        zero or more batch dimensions. N and M can be arbitrary positive number.
        The data type of ``x`` should be float32 or float64.
    q (int, optional): A slightly overestimated rank of :math:`X`.
        Default value is None, which means the overestimated rank is 6.
    niter (int, optional): The number of iterations to perform. Default: 2.
    M (Tensor, optional): The input tensor's mean. Its shape should be `[..., 1, M]`.
        Default value is None.
    name (str|None, optional): Name for the operation. For more information, please
        refer to :ref:`api_guide_Name`. Default: None.

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 the matrix :math:`X` or :math:`X - M`.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2024)

        >>> x = paddle.randn((5, 5), dtype='float64')
        >>> U, S, V = paddle.linalg.svd_lowrank(x)
        >>> print(U)
        Tensor(shape=[5, 5], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[-0.03586982, -0.17211503,  0.31536566, -0.38225676, -0.85059629],
         [-0.38386839,  0.67754925,  0.23222694,  0.51777188, -0.26749766],
         [-0.85977150, -0.28442378, -0.41412094, -0.08955629, -0.01948348],
         [ 0.18611503,  0.56047358, -0.67717019, -0.39286761, -0.19577062],
         [ 0.27841082, -0.34099254, -0.46535957,  0.65071250, -0.40770727]])

        >>> print(S)
        Tensor(shape=[5], dtype=float64, place=Place(cpu), stop_gradient=True,
        [4.11253399, 3.03227120, 2.45499752, 1.25602436, 0.45825337])

        >>> print(V)
        Tensor(shape=[5, 5], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[ 0.46401347,  0.50977695, -0.08742316, -0.11140428, -0.71046833],
         [-0.48927226, -0.35047624,  0.07918771,  0.45431083, -0.65200463],
         [-0.20494730,  0.67097011, -0.05427719,  0.66510472,  0.24997083],
         [-0.69645001,  0.40237917,  0.09360970, -0.58032322, -0.08666357],
         [ 0.13512270,  0.07199989,  0.98710572,  0.04529277,  0.01134594]])
Input must be tensor, but got r   N   r   q(=>) must be non-negative integer and not greater than min(m, n)=niter(=) must be non-negative integerr  r  r   Fr  )r   	is_tensorrN   rD   rM   r   broadcast_tor  r  r  r   r  r   r  )r)   r  r  r  rT   r  r  M_tr  r  Q_cB_tr   r   VhVBs                    rZ   svd_lowrankr  V  s   F A9$q'CDD7723<DAy1L	QaaAQN! //21yk;
 	

 QJ75')GHIIyNN177#m
Q-Cu"3>m9--'C--'&--*??Cyy}!1CIIq>1!99R=A99R=A%5		1~5%yy}		"-8syy8-==$$S$>bHHQK"1u:m9c'Ac'&--*AAAm99R=A99R=A%5		1~5%yy}!1CIIq>1!yy}		"-8syy8-==$$S$>bHHQK7Nr[   c           	        [         R                  " U 5      (       d  [        S[        U 5       35      eU R                  SS u  pVUc  [        SXV5      nO/US:  a  U[        XV5      ::  d  [        SU S[        XV5       35      eUS:  d  [        SU S	35      eU(       d  [        XUSS
9$ U R                  SSS9n[        X-
  XSS
9$ )a	  
Performs linear Principal Component Analysis (PCA) on a low-rank matrix or batches of such matrices.

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]`,
        where `...` is zero or more batch dimensions. N and M can be arbitrary
        positive number. The data type of x should be float32 or float64.
    q (int, 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.
    niter (int, optional): number of iterations to perform. Default: 2.
    name (str|None, optional): Name for the operation. For more information,
        please refer to :ref:`api_guide_Name`. Default: None.

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

        >>> import paddle
        >>> paddle.seed(2023)

        >>> x = paddle.randn((5, 5), dtype='float64')
        >>> U, S, V = paddle.linalg.pca_lowrank(x)
        >>> print(U)
       Tensor(shape=[5, 5], dtype=float64, place=Place(cpu), stop_gradient=True,
       [[ 0.80131563,  0.11962647,  0.27667179, -0.25891214,  0.44721360],
        [-0.12642301,  0.69917551, -0.17899393,  0.51296394,  0.44721360],
        [ 0.08997135, -0.69821706, -0.20059228,  0.51396579,  0.44721360],
        [-0.23871837, -0.02815453, -0.59888153, -0.61932365,  0.44721360],
        [-0.52614559, -0.09243040,  0.70179595, -0.14869394,  0.44721360]])

        >>> print(S)
        Tensor(shape=[5], dtype=float64, place=Place(cpu), stop_gradient=True,
        [2.60101614, 2.40554940, 1.49768346, 0.19064830, 0.00000000])

        >>> print(V)
        Tensor(shape=[5, 5], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[ 0.58339481, -0.17143771,  0.00522143,  0.57976310,  0.54231640],
         [ 0.22334335,  0.72963474, -0.30148399, -0.39388750,  0.41438019],
         [ 0.05416913,  0.34666487,  0.93549758,  0.00063507,  0.04162998],
         [-0.39519094,  0.53074980, -0.16687419,  0.71175586, -0.16638919],
         [-0.67131070, -0.19071018,  0.07795789, -0.04615811,  0.71046714]])
r  r   Nr  r   r  r  r  r  r  Tr   )r   r  rN   rD   rM   r   r  mean)r)   r  centerr  rT   r  r  Cs           rZ   pca_lowrankr    s    ~ A9$q'CDDWWRS\FQy1L1fc!i! //21yk;
 	
 QJ75')GHII1u55	B%Aqua55r[   c                   [        5       (       a  [        R                  " X5      $ [        U SSS/S5        [	        US[
        S5        [        S
0 [        5       D6nUR                  U R                  S9nUR                  SSU 0SU0SU0S	9  U$ )a  

Computes the n-th power of a square matrix or a batch of square matrices.

Let :math:`X` be a square matrix or a batch of square matrices, :math:`n` be
an exponent, the equation should be:

.. math::
    Out = X ^ {n}

Specifically,

- If `n > 0`, it returns the matrix or a batch of matrices raised to the power of `n`.

- If `n = 0`, it returns the identity matrix or a batch of identity matrices.

- If `n < 0`, it returns the inverse of each matrix (if invertible) raised to the power of `abs(n)`.

Args:
    x (Tensor): A square matrix or a batch of square matrices to be raised
        to power `n`. Its shape should be `[*, M, M]`, where `*` is zero or
        more batch dimensions. Its data type should be float32 or float64.
    n (int): The exponent. It can be any positive, negative integer or zero.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    - Tensor, The n-th power of the matrix (or the batch of matrices) `x`. Its
      data type should be the same as that of `x`.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1, 2, 3],
        ...                       [1, 4, 9],
        ...                       [1, 8, 27]], dtype='float64')
        >>> print(paddle.linalg.matrix_power(x, 2))
        Tensor(shape=[3, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[6.  , 34. , 102.],
         [14. , 90. , 282.],
         [36. , 250., 804.]])

        >>> print(paddle.linalg.matrix_power(x, 0))
        Tensor(shape=[3, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[1., 0., 0.],
         [0., 1., 0.],
         [0., 0., 1.]])

        >>> print(paddle.linalg.matrix_power(x, -2))
        Tensor(shape=[3, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[ 12.91666667, -12.75000000,  2.83333333 ],
         [-7.66666667 ,  8.         , -1.83333333 ],
         [ 1.80555556 , -1.91666667 ,  0.44444444 ]])
rR   r.   r/   matrix_powerr  ry   r>   r@   rC   )r  )r   r   r  r   r   r   r   rP   rQ   rR   rS   )r)   r  rT   rW   rX   s        rZ   r  r  %  s    v ""1(( wI.	
 	1c3/8vx877agg7F8CL(	 	 	
 
r[   c                    g r   r   r)   moderT   s      rZ   r  r  r  s    
  r[   c                    g r   r   r  s      rZ   r  r  z  s    
 r[   c                   [        5       (       a#  [        R                  " X5      u  p4US:X  a  U$ X44$ [        U S/ SQS5        [	        US[
        S5        [        S
0 [        5       D6nUR                  U R                  S9nUR                  U R                  S9n0 nXS'   UR                  SSU /0X4S.US	9  US:X  a  U$ X44$ )aY  
Computes the QR decomposition of one matrix or batches of matrices (backward is unsupported now).

Args:
    x (Tensor): The input tensor. Its shape should be `[..., M, N]`,
        where ... is zero or more batch dimensions. M and N can be arbitrary
        positive number. The data type of x supports float, double, complex64, complex128.
    mode (str, optional): A flag to control the behavior of qr.
        Suppose x's shape is `[..., M, N]` and denoting `K = min(M, N)`:
        If mode = "reduced", qr op will return reduced Q and R matrices,
        which means Q's shape is `[..., M, K]` and R's shape is `[..., K, N]`.
        If mode = "complete", qr op will return complete Q and R matrices,
        which means Q's shape is `[..., M, M]` and R's shape is `[..., M, N]`.
        If mode = "r", qr op will only return reduced R matrix, which means
        R's shape is `[..., K, N]`. Default: "reduced".
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    If mode = "reduced" or mode = "complete", qr will return a two tensor-tuple, which represents Q and R.
    If mode = "r", qr will return a tensor which represents R.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]).astype('float64')
        >>> q, r = paddle.linalg.qr(x)
        >>> print(q)
        Tensor(shape=[3, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[-0.16903085,  0.89708523],
         [-0.50709255,  0.27602622],
         [-0.84515425, -0.34503278]])
        >>> print(r)
        Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[-5.91607978, -7.43735744],
         [ 0.        ,  0.82807867]])

        >>> # one can verify : X = Q * R ;
rrR   r^  r  r  ry   r>   )r  r  rC   )r  )r   r   r  r   r   r  r   rP   rQ   rR   rS   )r)   r  rT   r  r  rW   rG   s          rZ   r  r    s    \ yy!3;H4K wI4	
 	4d+.VX.55AGG5D55AGG5DfsQCj2B% 	 	
 3;H4Kr[   c                    g r   r   r)   pivot	get_infosrT   s       rZ   lur    s      r[   c                    g r   r   r  s       rZ   r  r    s     %(r[   c                    g r   r   r  s       rZ   r  r    s     =@r[   c                ^   [        5       (       a  [        R                  " X5      u  pEnOw[        U S/ SQS5        [	        S
0 [        5       D6nUR                  U R                  S9nUR                  SS9nUR                  SS9n0 nXS'   UR                  SSU 0XEUS.US	9  U(       a  XEU4$ XE4$ )a
  
Computes the LU factorization of an N-D(N>=2) matrix x.

Returns the LU factorization(inplace x) and Pivots. low triangular matrix L and
upper triangular matrix U are combined to a single LU matrix.

Pivoting is done if pivot is set to True.
P mat can be get by pivots:

.. code-block:: text

    ones = eye(rows) #eye matrix of rank rows
    for i in range(cols):
        swap(ones[i], ones[pivots[i]])
    return ones

Args:

    X (Tensor): the tensor to factor of N-dimensions(N>=2). Its data type should be float32, float64, complex64, or complex128.

    pivot (bool, optional): controls whether pivoting is done. Default: True.

    get_infos (bool, optional): if set to True, returns an info IntTensor. Default: False.

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

Returns:
    factorization (Tensor), LU matrix, the factorization of input X.

    pivots (IntTensor), the pivots of size(\*(N-2), min(m,n)). `pivots` stores all the
    intermediate transpositions of rows. The final permutation `perm` could be
    reconstructed by this, details refer to upper example.

    infos (IntTensor, optional), if `get_infos` is `True`, this is a tensor of size (\*(N-2))
    where non-zero values indicate whether factorization for the matrix or each minibatch
    has succeeded or failed.


Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]).astype('float64')
        >>> lu,p,info = paddle.linalg.lu(x, get_infos=True)

        >>> print(lu)
        Tensor(shape=[3, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[5.        , 6.        ],
         [0.20000000, 0.80000000],
         [0.60000000, 0.50000000]])
        >>> print(p)
        Tensor(shape=[2], dtype=int32, place=Place(cpu), stop_gradient=True,
        [3, 3])
        >>> print(info)
        Tensor(shape=[], dtype=int32, place=Place(cpu), stop_gradient=True,
        0)

        >>> P,L,U = paddle.linalg.lu_unpack(lu,p)

        >>> print(P)
        Tensor(shape=[3, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[0., 1., 0.],
         [0., 0., 1.],
         [1., 0., 0.]])
        >>> print(L)
        Tensor(shape=[3, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[1.        , 0.        ],
         [0.20000000, 1.        ],
         [0.60000000, 0.50000000]])
        >>> print(U)
        Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[5.        , 6.        ],
         [0.        , 0.80000000]])

        >>> # one can verify : X = P @ L @ U ;
rR   r^  r  ry   r   r  r>   )r@   PivotsInfosrC   )r  )	r   r   r  r   r   rP   rQ   rR   rS   )	r)   r  r  rT   r  r~   inforW   rG   s	            rZ   r  r    s    d ii)t wI4	
 .VX.66QWW6E55E5B88u8Eg8d;	 	 	
 d{ur[   c           	     R   U R                   S:  a!  [        S[        U R                  5       35      eUR                   S:  a!  [        S[        UR                  5       35      eUR                   S:  a!  [        S[        UR                  5       35      eU R                  S   UR                  S   :w  a+  [        SU R                  S    SUR                  S    35      eUR                  S	   UR                  S   :w  a+  [        S
UR                  S	    SUR                  S    35      eUR                  S	   UR                  S	   :w  a+  [        SUR                  S	    SUR                  S	    35      e[	        U R                  SS UR                  SS 5      n[	        XRR                  SS	 5      nU R                  SS U:X  a  U O.[
        R                  " X[        U R                  SS 5      -   5      n US:X  a  UOSnUR                  SS	 U:X  a  UO.[
        R                  " X&[        UR                  S	S 5      -   5      nUR                  SS U:X  a  UO.[
        R                  " X[        UR                  SS 5      -   5      nSUl        [        R                  " XX#5      nU$ )a  
Computes the solution x to the system of linear equations :math:`Ax = b` ,
given LU decomposition :math:`A` and column vector :math:`b`.

Args:
    b (Tensor): Column vector `b` in the above equation. It has shape :math:`(*, m, k)`, where :math:`*` is batch dimensions,
        with data type float32, float64, complex64, or complex128.

    lu (Tensor): LU decomposition. It has shape :math:`(*, m, m)`, where :math:`*` is batch dimensions, that can be decomposed into an upper triangular matrix U and a lower triangular matrix L,
        with data type float32, float64, complex64, or complex128.

    pivots (Tensor): Permutation matrix P of LU decomposition. It has shape :math:`(*, m)`, where :math:`*` is batch dimensions, that can be converted to a permutation matrix P, with data type int32.

    trans (str, optional): The transpose of the matrix A. It can be "N" , "T" or "C", "N" means :math:`Ax=b`, "T" means :math:`A^Tx=b`, "C" means :math:`A^Hx=b`, default is "N".

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

Returns:
    Tensor, the same data type as the `b` and `lu`.

Examples:
    .. code-block:: python

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

        >>> A = paddle.to_tensor([[3, 1], [1, 2]], dtype="float64")
        >>> b = paddle.to_tensor([[9, 8], [9, 8]], dtype="float64")
        >>> lu, p = paddle.linalg.lu(A)
        >>> x = paddle.linalg.lu_solve(b, lu, p)
        >>> paddle.allclose(A @ x, b)

        >>> print(x)
        Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[1.80000000, 1.60000000],
        [3.60000000, 3.20000000]])
r   z-`b` dimension must be gather than 2, but got z.`lu` dimension must be gather than 2, but got r   z2`pivots` dimension must be gather than 1, but got r   z;the rows of `b` must be equal to the rows of `lu`, but got z and r   z8`lu` shape[-1] must be equal to `lu` shape[-2], but got z<`pivots` shape[-1] must be equal to `lu` shape[-1], but got NNTT)r  rN   rL   rM   r   r   r  rI   stop_gradientr   lu_solve)br  pivotstransrT   
temp_shapebatch_shaperX   s           rZ   r  r  K  s   Z 	vvz;CL>J
 	
 
ww{<S]OL
 	
 {{Q@V\\AR@ST
 	
 	wwr{bhhrl"I!''RT+V[\^\d\deg\h[ij
 	
 
xx|rxx|#FrxxPR|nTYZ\ZbZbceZfYgh
 	
 ||B288B<'J6<<XZK[J\\abdbjbjkmbnaop
 	
 !"rxx}=J!*ll3B.?@K 773B<;& 	
  $qwwrs|2D$DE 
 c\EsE <<+ 	  tFLL<M7N)NO  88CR=K' 	  43F%FG 
  F
//!
/CJr[   c                &   U R                   S:  a  [        SU R                    S35      eUR                   S:  a  [        SUR                    S35      e[        5       (       a  [        R                  " XX#5      u  pVnXVU4$ [        U S/ SQS	5        [        S0 [        5       D6nUR                  U R                  S
9n	UR                  U R                  S
9n
UR                  U R                  S
9n0 nX,S'   X<S'   UR                  S	XS.XUS.US9  XU4$ )a^	  
Unpack L U and P to single matrix tensor .
unpack L and U matrix from LU, unpack permutation matrix P from Pivots .

P mat can be get by pivots:

.. code-block:: text

    ones = eye(rows) #eye matrix of rank rows
    for i in range(cols):
        swap(ones[i], ones[pivots[i]])


Args:
    x (Tensor): The LU tensor get from paddle.linalg.lu, which is combined by L and U.
        Its data type should be float32, float64, complex64, or complex128.

    y (Tensor): Pivots get from paddle.linalg.lu. Its data type should be int32.

    unpack_ludata (bool, optional): whether to unpack L and U from x. Default: True.

    unpack_pivots (bool, optional): whether to unpack permutation matrix P from Pivots. Default: True.

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

Returns:
    P (Tensor), Permutation matrix P of lu factorization.

    L (Tensor), The lower triangular matrix tensor of lu factorization.

    U (Tensor), The upper triangular matrix tensor of lu factorization.


Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]).astype('float64')
        >>> lu,p,info = paddle.linalg.lu(x, get_infos=True)

        >>> print(lu)
        Tensor(shape=[3, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[5.        , 6.        ],
         [0.20000000, 0.80000000],
         [0.60000000, 0.50000000]])
        >>> print(p)
        Tensor(shape=[2], dtype=int32, place=Place(cpu), stop_gradient=True,
        [3, 3])
        >>> print(info)
        Tensor(shape=[], dtype=int32, place=Place(cpu), stop_gradient=True,
        0)

        >>> P,L,U = paddle.linalg.lu_unpack(lu,p)

        >>> print(P)
        Tensor(shape=[3, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[0., 1., 0.],
         [0., 0., 1.],
         [1., 0., 0.]])
        >>> print(L)
        Tensor(shape=[3, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[1.        , 0.        ],
         [0.20000000, 1.        ],
         [0.60000000, 0.50000000]])
        >>> print(U)
        Tensor(shape=[2, 2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[5.        , 6.        ],
         [0.        , 0.80000000]])

        >>> # one can verify : X = P @ L @ U ;
r   :The shape of x should be (*, M, N), but received ndim is [ < 2]r   z<The shape of Pivots should be (*, K), but received ndim is [z < 1]rR   r^  	lu_unpackry   unpack_ludataunpack_pivots)r>   r  )PmatLr   rC   )r  )r  rN   r   r   r  r   r   rP   rQ   rR   rS   )r)   ro   r  r  rT   Pr  r   rW   r~   lr   rG   s                rZ   r  r    s4   ` 	vvzHPUV
 	
 	vvzJ166(RWX
 	
 ""1FaQw =		
 5FH555AGG5D55AGG5D55AGG5D!.o!.o(Q/	 	 	
 Qwr[   c                4   [        5       (       a  [        R                  " U 5      $ [        U S/ SQS5        [	        S0 [        5       D6nUR                  U R                  5      nUR                  U R                  5      nSU 0nX4S.nUR                  SXVS9  X44$ )a  
Performs the eigenvalue decomposition of a square matrix or a batch of square matrices.

Note:
    - If the matrix is a Hermitian or a real symmetric matrix, please use :ref:`api_paddle_linalg_eigh` instead, which is much faster.
    - If only eigenvalues is needed, please use :ref:`api_paddle_linalg_eigvals` instead.
    - If the matrix is of any shape, please use :ref:`api_paddle_linalg_svd`.
    - This API is only supported on CPU device.
    - The output datatype is always complex for both real and complex input.

Args:
    x (Tensor): A tensor with shape math:`[*, N, N]`, The data type of the x should be one of ``float32``,
        ``float64``, ``complex64`` or ``complex128``.
    name (str|None, optional): The default value is `None`. Normally there is no need for user to set
        this property. For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Eigenvalues(Tensor): A tensor with shape math:`[*, N]` refers to the eigen values.
    Eigenvectors(Tensor): A tensor with shape math:`[*, N, N]` refers to the eigen vectors.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1.6707249, 7.2249975, 6.5045543],
        ...                       [9.956216,  8.749598,  6.066444 ],
        ...                       [4.4251957, 1.7983172, 0.370647 ]])
        >>> w, v = paddle.linalg.eig(x)
        >>> print(v)
        Tensor(shape=[3, 3], dtype=complex64, place=Place(cpu), stop_gradient=True,
        [[ (0.5061365365982056+0j) ,  (0.7971761226654053+0j) ,
           (0.1851806491613388+0j) ],
         [ (0.8308236598968506+0j) , (-0.3463813066482544+0j) ,
           (-0.6837005615234375+0j) ],
         [ (0.23142573237419128+0j), (-0.49449989199638367+0j),
           (0.7058765292167664+0j) ]])

        >>> print(w)
        Tensor(shape=[3], dtype=complex64, place=Place(cpu), stop_gradient=True,
        [ (16.50470733642578+0j)  , (-5.503481388092041+0j)  ,
          (-0.21026138961315155+0j)])
r>   r^  eigEigenvaluesEigenvectorsr   )r  )	r   r   r  r   r   rP   rQ   rR   rS   )r)   rT   rW   rJ  vrE   rF   s          rZ   r  r    s    Z zz!} sEu	
 /fh/55agg>55agg>q"#7eFDtr[   c                   [        U R                  5      n[        U5      S:  a  [        S[        U5       SU 35      eUS   US   :w  a  [        SU 35      e[	        5       (       a  [
        R                  " U 5      $ [        U S/ SQS	5        [        S0 [        5       D6nUR                  U R                  S
9nUR                  S	SU 0SU0S9  U$ )a  
Compute the eigenvalues of one or more general matrices.

Warning:
    The gradient kernel of this operator does not yet developed.
    If you need back propagation through this operator, please replace it with paddle.linalg.eig.

Args:
    x (Tensor): A square matrix or a batch of square matrices whose eigenvalues will be computed.
        Its shape should be `[*, M, M]`, where `*` is zero or more batch dimensions.
        Its data type should be float32, float64, complex64, or complex128.
    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 tensor containing the unsorted eigenvalues which has the same batch
    dimensions with `x`. The eigenvalues are complex-valued even when `x` is real.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)

        >>> x = paddle.rand(shape=[3, 3], dtype='float64')
        >>> print(x)
        Tensor(shape=[3, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[0.86583615, 0.52014721, 0.25960938],
         [0.90525323, 0.42400090, 0.40641288],
         [0.97020893, 0.74437359, 0.51785128]])

        >>> print(paddle.linalg.eigvals(x))
        Tensor(shape=[3], dtype=complex128, place=Place(cpu), stop_gradient=True,
        [ (1.788956694280852+0j)  ,  (0.16364484879581526+0j),
          (-0.14491322408727625+0j)])
r   zMThe dimension of Input(x) should be at least 2, but received x's dimension = z, x's shape = r   r   zNThe last two dimensions of Input(x) should be equal, but received x's shape = rR   r^  eigvalsry   r>   r@   r   )r  )rI   rM   rL   rN   r   r   r  r   r   rP   rQ   rR   rS   )r)   rT   rY   rW   rX   s        rZ   r  r  Y  s    L 177mG
7|a[\_`g\h[iiwx  xA  B
 	
 r{gbk!\]d\ef
 	
 ~~a   =		
 3&(377agg7Fia5#,O
r[   c                   [        5       (       a  [        R                  " U 5      $ [        U S[        [
        4S5        [        U 5       HL  u  p#[        US[        U5      -   S-   / SQS5        UR                  U S   R                  :w  d  MC  [        S5      e   [        S0 [        5       D6nUR                  SS9nUR                  U5      nUR                  SS	U 0S
U0S9  U$ )aY  
Multi_dot is an operator that calculates multiple matrix multiplications.

Supports inputs of float16(only GPU support), float32 and float64 dtypes. This function does not
support batched inputs.

The input tensor in [x] must be 2-D except for the first and last can be 1-D.
If the first tensor is a 1-D vector of shape(n, ) it is treated as row vector
of shape(1, n), similarly if the last tensor is a 1D vector of shape(n, ), it
is treated as a column vector of shape(n, 1).

If the first and last tensor are 2-D matrix, then the output is also 2-D matrix,
otherwise the output is a 1-D vector.

Multi_dot will select the lowest cost multiplication order for calculation. The
cost of multiplying two matrices with shapes (a, b) and (b, c) is a * b * c.
Given matrices A, B, C with shapes (20, 5), (5, 100), (100, 10) respectively,
we can calculate the cost of different multiplication orders as follows:
- Cost((AB)C) = 20x5x100 + 20x100x10 = 30000
- Cost(A(BC)) = 5x100x10 + 20x5x10 = 6000

In this case, multiplying B and C first, then multiply A, which is 5 times faster
than sequential calculation.

Args:
    x (list[Tensor]): The input tensors which is a list Tensor.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: The output Tensor.

Examples:

    .. code-block:: pycon

        >>> import paddle

        >>> # A * B
        >>> A = paddle.rand([3, 4])
        >>> B = paddle.rand([4, 5])
        >>> out = paddle.linalg.multi_dot([A, B])
        >>> print(out.shape)
        paddle.Size([3, 5])

        >>> # A * B * C
        >>> A = paddle.rand([10, 5])
        >>> B = paddle.rand([5, 8])
        >>> C = paddle.rand([8, 7])
        >>> out = paddle.linalg.multi_dot([A, B, C])
        >>> print(out.shape)
        paddle.Size([10, 7])

r)   	multi_dotzx[])r,   r.   r/   r5   r   z:All the Tensors in the input must have the same data type.)input_param_namer>   r@   r   )r  )r   r   r  r   rI   rJ   rO   r   r  rR   r  r   rP   r   rQ   rS   )r)   rT   idr@  rW   rR   rX   s          rZ   r  r    s    n ""1cD%=+6!!HB$s2w$;	 zzQqTZZ'P  % 5FH5""C"877>c1Xs| 	 	
 
r[   c                p   S n[        5       (       d  [        5       (       a  U" X5        [        R                  " X5      $ U" X5        [	        S
0 [        5       D6n[        U S/ SQS5        UR                  U R                  S9nUR                  U R                  S9nUR                  SSU 0XVS.SU0S	9  XV4$ )a  
Compute the eigenvalues and eigenvectors of a
complex Hermitian (conjugate symmetric) or a real symmetric matrix.

Args:
    x (Tensor): A tensor with shape :math:`[*, N, N]` , The data type of the input Tensor x
        should be one of float32, float64, complex64, complex128.
    UPLO (str, optional): (string, default 'L'), 'L' represents the lower triangular matrix,
        "'U' represents the upper triangular matrix.". Default: 'L'.
    name (str|None, optional): The default value is None. Normally there is no need for user to set this
        property.  For more information, please refer to :ref:`api_guide_Name`.

Returns:
    2-element tuple containing

    - out_value(Tensor): A Tensor with shape :math:`[*, N]` and data type of float32 and float64.
      The eigenvalues of eigh op.
    - out_vector(Tensor): A Tensor with shape :math:`[*, N, N]` and data type of float32, float64,
      complex64 and complex128. The eigenvectors of eigh op.

Examples:
    .. code-block:: pycon

        >>> import paddle

        >>> x = paddle.to_tensor([[1, -2j], [2j, 5]])
        >>> out_value, out_vector = paddle.linalg.eigh(x, UPLO='L')
        >>> print(out_value)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.17157286, 5.82842731])
        >>> print(out_vector)
        Tensor(shape=[2, 2], dtype=complex64, place=Place(cpu), stop_gradient=True,
               [[(-0.92387950+0.00000000j), (-0.38268340+0.00000000j)],
                [ (0.00000000+0.38268340j), (0.00000000-0.92387950j) ]])

c                   [        U R                  5      n[        U R                  5      S:  a"  [        S[        U R                  5       S35      eUS   US   :w  a  [        SU 35      eUS:w  a  US:w  a  [        S	U 35      eg g 
Nr   zMInput(input) only support >=2 tensor, but received length of Input(input) is r<   r   r   zQThe input matrix must be batches of square matrices. But received x's dimension: r  r   z+UPLO must be L or U. But received UPLO is: rI   rM   rL   rN   r)   UPLOrY   s      rZ   rv   eigh.<locals>.__check_input      qww-qww<!--0\N!=  2;'"+%cdkclm  3;43;=dVD  ';r[   eighrR   r^  ry   r>   r  r  rC   )r  )
r   r   r   r  r   rP   r   rQ   rR   rS   )r)   r  rT   rv   rW   	out_value
out_vectors          rZ   r  r    s    P  KMMa{{1## 	a0vx0 =		
 ==AGG=L	>>QWW>M
8$-J4.	 	 	
 $$r[   c           	        [        5       (       Ga  U(       Gd8  [        R                  " U S5      u  pEnUR                  S   S:X  a  UnO[        R                  " US/S5      n[
        R                  " XR                  S9nX-  n[        S5      n	[
        R                  " XR                  S9n	[
        R                  " XX:  SU-  SU	-  5      n
[        R                  " U
S/5      n[        [        [        UR                  5      5      5      n/ US	S QUS   PUS   Pn[        R                  " Xm5      nX-  n[        R                  " XSS5      nU$ [!        5       (       a^  U R"                  S:X  aN  [        [        [        U R                  5      5      5      n/ US	S QUS   PUS   Pn[        R                  " X5      $ [        R$                  " U S
5      u  pT[
        R&                  " U5      n[        R                  " US/S5      n[
        R                  " XR                  S9nX-  n[        S5      n	[
        R                  " XR                  S9n	[
        R                  " UU:  SU-  SU	-  5      n
[        R                  " U
S/5      nXK-  n[        R(                  " U5      n[        R                  " UUSS5      nU$ U(       Gd  [+        S*0 [-        5       D6nU R                  n[/        U SSS/S5        UR1                  U5      nUR1                  U5      nUR1                  U5      nUR3                  SSU /0XFUS.SS0S9  UR1                  U5      nUR3                  SSU0SU0S/SSS.S9  [5        S/UUS9nX-  n[        S5      n	[5        S/U	US9n	[
        R                  " XX:  SU-  SU	-  5      n
UR1                  US9nUR1                  US9nUR3                  SSU
0SS/0UUS.S9  [        [        [        UR                  5      5      5      n/ US	S QUS   PUS   PnUR1                  U5      nUR1                  U5      nUR3                  SSU/0U/U/S.SU0S9  UR1                  U5      nUR3                  SXS.SU0SS0S9  UR7                  U5      nUR1                  U5      nUR3                  S XS.SU0SSS!.S9  U$ [+        S*0 [-        5       D6nU R                  n[/        U S"/ S#QS5        U[
        R8                  :X  a  SnOU[
        R:                  :X  a  SnOUnUR1                  U5      nUR1                  U5      nUR3                  S$SU 0XTS%.S&S
0S9  UR1                  U5      nUR3                  S'SU0SU0S(9  UR1                  U5      nUR3                  SSU0SU0S/SSS.S9  [5        S/UUS9nX-  n[        S5      n	[5        S/U	US9n	[
        R                  " UU:  SU-  SU	-  5      n
UR1                  US9nUR1                  US9nUR3                  SSU
0SS/0UUS.S9  UR1                  U5      nUR3                  SXKS.SU0SS0S9  UR7                  U5      nUR1                  U5      nUR3                  S)SU0SU/0S(9  UR1                  U5      nUR3                  S UUS.SU0SSS!.S9  U$ )+aj  
Calculate pseudo inverse via SVD(singular value decomposition)
of one matrix or batches of regular matrix.

.. math::

    if hermitian == False:
        x = u * s * vt  (SVD)
        out = v * 1/s * ut
    else:
        x = u * s * ut  (eigh)
        out = u * 1/s * u.conj().transpose(-2,-1)

If x is hermitian or symmetric matrix, svd will be replaced with eigh.

Args:
    x (Tensor): The input tensor. Its shape should be (*, m, n)
        where * is zero or more batch dimensions. m and n can be
        arbitrary positive number. The data type of x should be
        float32 or float64 or complex64 or complex128. When data
        type is complex64 or complex128, hermitian should be set
        True.
    rcond (Tensor|float, optional): the tolerance value to determine
        when is a singular value zero. Default:1e-15.
    hermitian (bool, optional): indicates whether x is Hermitian
        if complex or symmetric if real. Default: False.
    name (str|None, optional): The default value is None. Normally there is no need for user to set this
        property. For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: The tensor with same data type with x. it represents
    pseudo inverse of x. Its shape should be (*, n, m).

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.arange(15).reshape((3, 5)).astype('float64')
        >>> input = paddle.to_tensor(x)
        >>> out = paddle.linalg.pinv(input)
        >>> print(input)
        Tensor(shape=[3, 5], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[0. , 1. , 2. , 3. , 4. ],
         [5. , 6. , 7. , 8. , 9. ],
         [10., 11., 12., 13., 14.]])

        >>> print(out)
        Tensor(shape=[5, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[-0.22666667, -0.06666667,  0.09333333],
         [-0.12333333, -0.03333333,  0.05666667],
         [-0.02000000, -0.00000000,  0.02000000],
         [ 0.08333333,  0.03333333, -0.01666667],
         [ 0.18666667,  0.06666667, -0.05333333]])

        # one can verify : x * out * x = x ;
        # or              out * x * out = x ;
Fr   r   Try   r   r   r   Nr  pinvr)   r.   r/   r   r>   r   r   rC   r   r@   r   )rM   
fill_valuerR   r   r   r?   )rD   rE   rG   rF   r=   rB   elementwise_mulr  	matmul_v2)trans_xtrans_yrR   r^  r  r  r  r   r   r7  )r  )r   r   r   rM   r   r   r?  rR   r   wherer   rI   r   rL   r:   r   r   sizer  r   r7  r   rP   r   rQ   rS   r    append_activationr7   r6   )r)   rcondrb  rT   r   r   r   max_singular_valcutoffro   singularstr^   r;   r  out_1out_2s_absu_conjrW   rR   st_shapev_shapes_types                           rZ   r  r  <  sg   @ zz!U+HA"wwr{a#$ #)::a"t#< $$U'':E-FeA  ''2A||AJAq1u=H!!(RD1Bc"((m,-D3T#2Y3R3$r(3D  *AFEMM%E48EL  QVVq[E#agg,/07cr7DH7d2h7''00 ;;q#&DAJJqME%zz%"t<$$U'':E-FeA  ''2A||EFNAE1q5AH!!(RD1BFE[[^FMM%=EL 4684FGGE$Qi-CVL99%@A99%@A::5ABaSz2&.	    &HHO!Qx 01!dEJ	   suEBE-FeAA31E:A||AJAq1u=H:::GB@@u@MH!Xtn "h7	   c"((m,-D3T#2Y3R3$r(3D99%@A??FG!bT{!"y9tn	   ==eDE&(rl	   ,,U3E==eDE "+"'D9	   L 4684FGGE$A	 )))"&***"99%@A99&AAQx()=sm	   ==fEEC8eU^    &HHP!U| 01!dEJ	   suFCE-FeAA31F;A||EFNAE1q5AH:::HB@@v@NH!Xtn "h7	   ==eDE&(rl	   ,,U3E>>uEFS!Huvh6G   ==eDE "0"'D9	   Lr[   c                   U R                   SS n[        UR                   5      S:X  a3  [        SU S[        UR                   5      R	                  S5       35      eUR                   SS nUS   US   :w  a  [        SU SU 35      eg)z=check the input shape of x and y for solve when left is Falser   Nr   z]Incompatible shapes of X and Y for the equation Out * X = Y, where input X's matrix shape is z andinput Y's matrix shape is r   )rM   rL   rN   rI   append)r)   ro   rY   y_shapes       rZ   _check_right_solve_shaper   :  s    ggbclG
177|q//6i 8))-agg)=)=a)@(AC
 	
 ''"#,1:#33:) <--4I7  $r[   c                    [        [        [        U R                  5      5      5      nUS   US   sUS'   US'   [	        X5      n U $ )z*transpose the last 2 dimension of a tensorr   r   )rI   r   rL   rM   r:   )r)   
x_new_dimss     rZ   _transpose_last_2dimr#  M  sD    eCL)*J%/^Z^"JrNJrN! AHr[   r  c                  U(       d!  [        X5        [        U 5      n [        U5      n[        5       (       a  [        R                  " X5      nOhU /U/S.n[        S
0 [        5       D6n[        U SSS/S5        [        USSS/S5        UR                  U R                  S9nUR                  SXS.SU0S	9  U(       d  [        W5      nUb  [        R                  " WU5        W$ )aa  

Computes the solution of a square system of linear equations with a unique solution for input 'X' and 'Y'.
Let :math:`X` be a square matrix or a batch of square matrices, :math:`Y` be
a vector/matrix or a batch of vectors/matrices. When `left` is True, the equation should be:

.. math::
    Out = X^-1 * Y

When `left` is False, the equation should be:

.. math::
    Out = Y * X^-1

Specifically, this system of linear equations has one solution if and only if input 'X' is invertible.

Args:
    x (Tensor): A square matrix or a batch of square matrices. Its shape should be ``[*, M, M]``, where ``*`` is zero or
        more batch dimensions. Its data type should be float32 or float64. Alias: ``A``.
    y (Tensor): A vector/matrix or a batch of vectors/matrices. Its shape should be ``[*, M, K]``, where ``*`` is zero or
        more batch dimensions. Its data type should be float32 or float64. Alias: ``B``.
    left (bool, optional): Whether to solve the system :math:`X * Out = Y` or :math:`Out * X = Y`. Default: True.
    name (str|None, optional): Name for the operation (optional, default is None).
        For more information, please refer to :ref:`api_guide_Name`.
    out (Tensor|None, optional): The output tensor. Default: None.

Returns:
    Tensor: The solution of a square system of linear equations with a unique solution for input 'x' and 'y'.
    Its data type should be the same as that of `x`.

Examples:

    .. code-block:: python

        >>> # a square system of linear equations:
        >>> # 3*X0 + X1 = 9
        >>> # X0 + 2*X1 = 8

        >>> import paddle

        >>> x = paddle.to_tensor([[3, 1],[1, 2]], dtype="float64")
        >>> y = paddle.to_tensor([9, 8], dtype="float64")
        >>> out = paddle.linalg.solve(x, y)

        >>> print(out)
        Tensor(shape=[2], dtype=float64, place=Place(cpu), stop_gradient=True,
        [2., 3.])
r  solver)   r.   r/   ro   ry   r@   r   )r%  )r   r#  r   r   r%  r   rP   r   rQ   rR   rS   r   r   )r)   ro   leftrT   rX   r   rE   rW   s           rZ   r%  r%  U  s    r  & # #ll1 s!%11 C)Y)?I C)Y)?I77agg7Fq!1E3< 	 	
 "3'
c3Jr[   c           	     .   [        5       (       a  [        R                  " XX#U5      $ U /U/S.n[        S
0 [	        5       D6n[        U S/ SQS5        [        US/ SQS5        UR                  U R                  S9nUR                  SXS.SU0UUUS.S	9  U$ )a  
Computes the solution of a system of equations with a triangular coefficient. `x` is coefficient matrix
`y` is multiple right-hand sides of equations.

Input `x` and `y` is 2D matrices or batches of 2D matrices. If the inputs are batches, the outputs is also
batches.

Equations can be described as:

.. math::
    x * Out = y

Solution of Equations is:

.. math::
    Out = x ^ {-1} * y

Args:
    x (Tensor): The input triangular coefficient matrix. Its shape should be `[*, M, M]`, where `*` is zero or
        more batch dimensions. Its data type should be float32, float64, complex64, complex128.
    y (Tensor): Multiple right-hand sides of system of equations. Its shape should be `[*, M, K]`, where `*` is
        zero or more batch dimensions. Its data type should be float32, float64, complex64, complex128.
    upper (bool, optional): Whether to solve the upper-triangular system of equations (default) or the lower-triangular
        system of equations. Default: True.
    transpose (bool, optional): whether `x` should be transposed before calculation. Default: False.
    unitriangular (bool, optional): whether `x` is unit triangular. If True, the diagonal elements of `x` are assumed
        to be 1 and not referenced from `x` . Default: 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: The solution of the system of equations. Its data type should be the same as that of `x`.

Examples:
    .. code-block:: python

        >>> # a square system of linear equations:
        >>> # x1 +   x2  +   x3 = 0
        >>> #      2*x2  +   x3 = -9
        >>> #               -x3 = 5

        >>> import paddle
        >>> x = paddle.to_tensor([[1, 1, 1],
        ...                       [0, 2, 1],
        ...                       [0, 0,-1]], dtype="float64")
        >>> y = paddle.to_tensor([[0], [-9], [5]], dtype="float64")
        >>> out = paddle.linalg.triangular_solve(x, y, upper=True)

        >>> print(out)
        Tensor(shape=[3, 1], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[ 7.],
         [-2.],
         [-5.]])
r  triangular_solver)   r^  ro   ry   r@   )r\  r:   unitriangularrC   )r(  )	r   r   r(  r   rP   r   rQ   rR   rS   )	r)   ro   r\  r:   r)  rT   rE   rW   rX   s	            rZ   r(  r(    s    | &&qU}MMs!%<68< =		
 	!=		
 77agg7F##CL&!.	 	 		
 
r[   c                   [        5       (       a  [        R                  " XU5      $ [        S0 [	        5       D6n[        U SSS/S5        [        USSS/S5        UR                  U R                  S9nUR                  SXS.SU0S	U0S
9  U$ )a  
Solves a linear system of equations A @ X = B, given A's Cholesky factor matrix u and  matrix B.

Input `x` and `y` is 2D matrices or batches of 2D matrices. If the inputs are batches, the outputs
is also batches.

Args:
    x (Tensor): Multiple right-hand sides of system of equations. Its shape should be `[*, M, K]`, where `*` is
        zero or more batch dimensions. Its data type should be float32 or float64.
    y (Tensor): The input matrix which is upper or lower triangular Cholesky factor of square matrix A. Its shape should be `[*, M, M]`, where `*` is zero or
        more batch dimensions. Its data type should be float32 or float64.
    upper (bool, optional): whether to consider the Cholesky factor as a lower or upper triangular matrix. Default: 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: The solution of the system of equations. Its data type is the same as that of `x`.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> u = paddle.to_tensor([[1, 1, 1],
        ...                       [0, 2, 1],
        ...                       [0, 0,-1]], dtype="float64")
        >>> b = paddle.to_tensor([[0], [-9], [5]], dtype="float64")
        >>> out = paddle.linalg.cholesky_solve(b, u, upper=True)

        >>> print(out)
        Tensor(shape=[3, 1], dtype=float64, place=Place(cpu), stop_gradient=True,
        [[-2.50000000],
         [-7.        ],
         [ 9.50000000]])
cholesky_solver)   r.   r/   ro   ry   r  r@   r\  rC   )r+  )	r   r   r+  r   rP   r   rQ   rR   rS   )r)   ro   r\  rT   rW   rX   s         rZ   r+  r+    s    L $$Q511:: sY	*,<	
 	!sY	*,<	
 77agg7F!#CLE"	 	 	
 
r[   c                   [        5       (       a%  [        R                  " XU R                  5      u  p4U$ S n[	        5       (       a-  U" X5        [        R                  " XU R                  5      u  p4U$ U" X5        [        S
0 [        5       D6n[        U S/ SQS5        UR                  U R                  S9nUR                  U R                  S9nU R                  n	UR                  SSU 0XxS.XS.S	9  U$ )a  
Computes the eigenvalues of a
complex Hermitian (conjugate symmetric) or a real symmetric matrix.

Args:
    x (Tensor): A tensor with shape :math:`[*, M, M]` , where * is zero or greater batch dimension. The data type of the input Tensor x
        should be one of float32, float64, complex64, complex128.
    UPLO(str, optional): Lower triangular part of a ('L', default) or the upper triangular part ('U').
    name(str|None, optional): The default value is None.  Normally there is no need for user to set this
        property.  For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tensor: The tensor eigenvalues in ascending order.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1, -2j], [2j, 5]])
        >>> out_value = paddle.eigvalsh(x, UPLO='L')
        >>> print(out_value)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.17157286, 5.82842731])
c                   [        U R                  5      n[        U R                  5      S:  a"  [        S[        U R                  5       S35      eUS   US   :w  a  [        SU 35      eUS:w  a  US:w  a  [        S	U 35      eg g r  r  r   s      rZ   rv   eigvalsh.<locals>.__check_input`  r  r[   eigvalshrR   r^  ry   r>   r  )r  is_testrC   )r/  )r   r   r/  r  r   r   rP   r   rQ   rR   rS   )
r)   r  rT   values_rv   rW   r  r  r0  s
             rZ   r/  r/  @  s    8 OOAQ__=	  }}aOOAQ__=	 	a4684 =		
 ==AGG=L	>>QWW>M
//8$-J4	 	 	
 r[   c           	        [         R                  " 5       nUS:X  a  US;  a  [        SU 35      eUc  SOUnO=UR                  S5      (       a  US;  a  [        SU 35      eUc  SOUnO[	        S	5      eU R
                  UR
                  :X  a  U R
                  [         R                  [         R                  [         R                  R                  R                  R                  [         R                  R                  R                  R                  4;   d  [        S
5      eU R                  S:  a  [        SU R                   S35      eUR                  S:  a  [        SUR                   S35      eU R                  S   UR                  S   :w  a,  [        SU R                  S    SUR                  S    S35      eUGc  U R
                  [         R                  :X  d<  U R
                  [         R                  R                  R                  R                  :X  a*  S[        U R                  S   U R                  S   5      -  nOU R
                  [         R                  :X  d<  U R
                  [         R                  R                  R                  R                  :X  a)  S[        U R                  S   U R                  S   5      -  n[!        5       (       a  ["        R$                  " XX#5      u  pgpUS:X  a7  [         R&                  " S/SS9n[         R&                  " S/U R
                  S9n	O&US:X  a   [         R&                  " S/U R
                  S9n	XgX4$ [)        S$0 [+        5       D6n
[-        U S/ SQS5        [-        US/ SQS5        U
R/                  U R
                  S9nU
R/                  U R
                  S9nU
R/                  [         R0                  S9nU
R/                  U R
                  S9n	U
R3                  SXS.UUUU	S.X#S.S 9  US:X  a?  [         R4                  R7                  S!S/S"9n[         R4                  R7                  S#S/S"9n	O%US:X  a  [         R4                  R7                  S#S/S"9n	XgX4$ )%a7  
Computes a solution to
the least squares problem of a system of linear equations.

Args:
    x (Tensor): A tensor with shape ``(*, M, N)`` , the data type of the input Tensor ``x``
        should be one of float32, float64.
    y (Tensor): A tensor with shape ``(*, M, K)`` , the data type of the input Tensor ``y``
        should be one of float32, float64.
    rcond(float, optional): The default value is None. A float pointing number used to determine
        the effective rank of ``x``. If ``rcond`` is None, it will be set to max(M, N) times the
        machine precision of x_dtype.
    driver(str, optional): The default value is None. The name of LAPACK method to be used. For
        CPU inputs the valid values are 'gels', 'gelsy', 'gelsd, 'gelss'. For CUDA input, the only
        valid driver is 'gels'. If ``driver`` is None, 'gelsy' is used for CPU inputs and 'gels'
        for CUDA inputs.
    name(str, optional): The default value is None. Normally there is no need for user to set
        this property. For more information, please refer to :ref:`api_guide_Name`.

Returns:
    Tuple: A tuple of 4 Tensors which is (``solution``, ``residuals``, ``rank``, ``singular_values``).
    ``solution`` is a tensor with shape ``(*, N, K)``, meaning the least squares solution. ``residuals``
    is a tensor with shape ``(*, K)``, meaning the squared residuals of the solutions, which is computed
    when M > N and every matrix in ``x`` is full-rank, otherwise return an empty tensor. ``rank`` is a tensor
    with shape ``(*)``, meaning the ranks of the matrices in ``x``, which is computed when ``driver`` in
    ('gelsy', 'gelsd', 'gelss'), otherwise return an empty tensor. ``singular_values`` is a tensor with
    shape ``(*, min(M, N))``, meaning singular values of the matrices in ``x``, which is computed when
    ``driver`` in ('gelsd', 'gelss'), otherwise return an empty tensor.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> x = paddle.to_tensor([[1, 3], [3, 2], [5, 6.]])
        >>> y = paddle.to_tensor([[3, 4, 6], [5, 3, 4], [1, 2, 1.]])
        >>> results = paddle.linalg.lstsq(x, y, driver="gelsd")
        >>> print(results[0])
        Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[ 0.78350395, -0.22165027, -0.62371236],
         [-0.11340097,  0.78866047,  1.14948535]])
        >>> print(results[1])
        Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [19.81443405, 10.43814468, 30.56185532])
        >>> print(results[2])
        Tensor(shape=[], dtype=int32, place=Place(cpu), stop_gradient=True,
        2)
        >>> print(results[3])
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [9.03455734, 1.54167950])

        >>> x = paddle.to_tensor([[10, 2, 3], [3, 10, 5], [5, 6, 12.]])
        >>> y = paddle.to_tensor([[4, 2, 9], [2, 0, 3], [2, 5, 3.]])
        >>> results = paddle.linalg.lstsq(x, y, driver="gels")
        >>> print(results[0])
        Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[ 0.39386186,  0.10230169,  0.93606132],
         [ 0.10741688, -0.29028130,  0.11892584],
         [-0.05115093,  0.51918161, -0.19948851]])
        >>> print(results[1])
        Tensor(shape=[0], dtype=float32, place=Place(cpu), stop_gradient=True,
        [])
cpu)Ngelsgelssgelsdgelsyz_Only support valid driver is 'gels', 'gelss', 'gelsd', 'gelsy' or None for CPU inputs. But got r8  gpu)Nr5  zEOnly support valid driver is 'gels' or None for CUDA inputs. But got r5  z.Only support lstsq api for CPU or CUDA device.zIOnly support x and y have the same dtype such as 'float32' and 'float64'.r   r  r  z:The shape of y should be (*, M, K), but received ndim is [r   zx with shape (*, M = z, N) and y with shape (*, M = z, K) should have same M.gHz>r   V瞯<r   r4   )rM   rR   lstsqrR   r^  ry   r  )Solution	ResidualsRankSingularValues)r  driverrC   r   )rT   rM   singular_values)r;  )r   
get_devicerN   
startswithRuntimeErrorrR   r.   r/   basecorer   FLOAT32FLOAT64r  rM   r   r   r   r;  emptyr   rP   r   rQ   r3   rS   staticdata)r)   ro   r  r@  rT   devicesolution	residualsr   rA  rW   s              rZ   r;  r;    s$   L  FBBqrxqyz  #N			5	!	!'WX^W_`  ">vKLL 	
177GGNNNNKK%%--KK%%--	

 W
 	
 	vvzHPUV
 	
 	vvzHPUV
 	
 	wwr{aggbk!#AGGBK=0NqwwWY{m[st
 	
 }GGv~~%ww&++**33;;;3qwwr{AGGBK88EGGv~~%ww&++**33;;;CQWWR[99E5;\\%6
2T V<<qc9D$ll!AGGDOw$ll!AGGDOD9911 =		
 	!=		
 <<177<K==AGG=L	88v||8L CC'' D 
 	#$&"1	 "4 	 
	
 V==%%6!%=D$mm00&qc 1 O w$mm00&qc 1 O D99r[   c                
   [        U R                  5      S:  d  [        U R                  5      S:  a"  [        S[        U R                  5       S35      e[        U SSS/S5        [	        X5      nUR
                  S	:X  a  X3-  $ [        R                  " U5      n[        R                  " U5      (       a  UR                  5       n[        R                  " U5      nX5S
S
2S
4   -  nX5S
S
S
24   -  n[        R                  " U5      (       a_  [        R                  " [        R                  " UR                  5       SS5      [        R                  " UR                  5       SS5      5      $ [        R                  " USS5      nU$ )u  

A correlation coefficient matrix indicate the correlation of each pair variables in the input matrix.
For example, for an N-dimensional samples X=[x1,x2,…xN]T, then the correlation coefficient matrix
element Rij is the correlation of xi and xj. The element Rii is the covariance of xi itself.

The relationship between the correlation coefficient matrix `R` and the
covariance matrix `C`, is

.. math:: R_{ij} = \frac{ C_{ij} } { \sqrt{ C_{ii} * C_{jj} } }

The values of `R` are between -1 and 1.

Args:

    x (Tensor): A N-D(N<=2) Tensor containing multiple variables and observations. By default, each row of x represents a variable. Also see rowvar below.
    rowvar (bool, optional): If rowvar is True (default), then each row represents a variable, with observations in the columns. Default: True.
    name (str|None, optional): Name of the output. It's used to print debug info for developers. Details: :ref:`api_guide_Name`. Default: None.

Returns:

    The correlation coefficient matrix of the variables.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> paddle.seed(2023)

        >>> xt = paddle.rand((3,4))
        >>> print(paddle.linalg.corrcoef(xt))
        Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[ 0.99999988, -0.47689581, -0.89559376],
         [-0.47689593,  1.        ,  0.16345492],
         [-0.89559382,  0.16345496,  1.        ]])

r   r   z_Input(x) only support N-D (1<=N<=2) tensor in corrcoef, but received length of Input(input) is r<   rR   r.   r/   corrcoefr   Nr   )rL   rM   rN   r   r:  r  r   diagr   realsqrtcomplexrA  imag)r)   rD  rT   cr   stddevs         rZ   rP  rP  F  s:   L 177|a3qww<!+)),QWWa9
 	
 Q)Y)?LAAvv{ uAAFFH[[^F4AaA ~~KK"a(&++affhA*F
 	
 KK2q!Hr[   c           	        [        U SSS5        [        USSS5        [        US[        [        4S5        US;  a  [	        SU S35      eS	nUS
:X  a  S	nOUS:X  a  SnOUS:X  a  Sn[        U R                  5      n[        U5      S:  d   S[        U5       S35       e[        UR                  5      n[        U5      S:  d   S[        U5       S35       eUS   US   :X  d   SUS    SUS    S35       eUS	:  d   SU S35       eU R                  S   nUR                  S   n	U R                  S   n
[        U5      nUS	:X  d  U	S	:X  a   [        R                  " X4U R                  S9$ U
S	:X  a   [        R                  " X4U R                  S9$ US:X  Ga>  US:X  d  US	:X  Ga1  US:  d  U	S:  Ga$  [        R                  " U R                  S5      SSS9n[        R                  " UR                  S5      SSS9n[        R                  " U/ [        UR                   S-
  5      QUR                   S-
  PUR                   S-
  PS9n[        R                  " U/ [        UR                   S-
  5      QUR                   S-
  PUR                   S-
  PS9n[        R"                  " X5      S-  U-   U-   n[        R$                  " USS9R'                  5       nU$ [        R(                  R+                  U SS S S 24   USS S S 2S S 24   -
  USS!9$ )"a  

Compute the p-norm distance between each pair of the two collections of inputs.

This function is equivalent to `scipy.spatial.distance.cdist(input,'minkowski', p=p)`
if :math:`p \in (0, \infty)`. When :math:`p = 0` it is equivalent to `scipy.spatial.distance.cdist(input, 'hamming') * M`.
When :math:`p = \infty`, the closest scipy function is `scipy.spatial.distance.cdist(xn, lambda x, y: np.abs(x - y).max())`.

Args:
    x (Tensor): A tensor with shape :math:`B \times P \times M`.
    y (Tensor): A tensor with shape :math:`B \times R \times M`.
    p (float, optional): The value for the p-norm distance to calculate between each vector pair. Default: :math:`2.0`.
    compute_mode (str, optional): The mode for compute distance.

        - ``use_mm_for_euclid_dist_if_necessary`` , for p = 2.0 and (P > 25 or R > 25), it will use matrix multiplication to calculate euclid distance if possible.
        - ``use_mm_for_euclid_dist`` , for p = 2.0, it will use matrix multiplication to calculate euclid distance.
        - ``donot_use_mm_for_euclid_dist`` , it will not use matrix multiplication to calculate euclid distance.

        Default: ``use_mm_for_euclid_dist_if_necessary``.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    Tensor, the dtype is same as input tensor.

    If x has shape :math:`B \times P \times M` and y has shape :math:`B \times R \times M` then
    the output will have shape :math:`B \times P \times R`.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> x = paddle.to_tensor([[0.9041,  0.0196], [-0.3108, -2.4423], [-0.4821,  1.059]], dtype=paddle.float32)
        >>> y = paddle.to_tensor([[-2.1763, -0.4713], [-0.6986,  1.3702]], dtype=paddle.float32)
        >>> distance = paddle.cdist(x, y)
        >>> print(distance)
        Tensor(shape=[3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[3.11927032, 2.09589314],
         [2.71384072, 3.83217239],
         [2.28300953, 0.37910119]])
r)   r.   r/   cdistro   r~   )#use_mm_for_euclid_dist_if_necessaryuse_mm_for_euclid_distdonot_use_mm_for_euclid_distzThe compute_mode should be 'use_mm_for_euclid_dist_if_necessary', 'use_mm_for_euclid_dist' or 'donot_use_mm_for_euclid_dist', but received compute_mode is r<   r   r[  r\  r   r]  r   zLThe x must be at least 2-dimensional, But received Input x's dimensional is r  zLThe y must be at least 2-dimensional, But received Input y's dimensional is r   zTThe x and y must have same last dimension, But received Input x's last dimension is z, Input y's last dimension is z<The p must be greater than or equal to 0, But received p is r   ry   r      Tr   )r;   r   r;  .Nr}   )r   r   r   r   rN   rI   rM   rL   r   rI  rR   r*  r   r   r:   r   r  r   rA  rS  r  r   )r)   ro   r~   compute_moderT   r  rY   r  r1r2c1x_normy_normy_transposedy_norm_transposedress                   rZ   rZ  rZ    s<   h Q%;WEQ%;WEq#s|W-  
 ,,8><
 	
 D<<	1	1	7	7177mGw<1 	114Wc	C 177mGw<1 	114Wc	C 2;'"+% 	44;BK= A''.r{m3	8%
 6 
FqcM6 
B	
B	
BaA	Qw"'||RHAGG44	Qw||RHAGG44CxTQY419"r'R"WAEE!H2t<AEE!H2t<''@eAFFQJ'@!@QVVaZ@
 #,,L5q)L6;;?LFKK!OL
 mmA,r14EENkk#3',,.
==	#tQ,!Cq!O,,   r[   c           
        [        U R                  S/ SQS5        [        UR                  S/ SQS5        U R                  UR                  :X  d   S5       e[        U R                  5      S:  aH  [        UR                  5      S:  a/  [        U R                  5      [        UR                  5      S-   :X  d   S5       eU R                  S	   U R                  S
   :  d   S5       eU R                  S
   UR                  S
   :  d   S5       e[	        U R                  SS	 5       H,  u  p4U R                  U   UR                  U   :X  a  M'   S5       e   S n[        U R                  5      S:X  a  U" X5      $ U R                  S	S u  pgU R                  nUR                  n	U R                  S
US	   US
   45      n UR                  S
U	S
   45      nU R                  S   n
[        R                  " XU/U R                  S9n[        U
5       HN  n[        5       (       a  U" X   X   5      X'   M#  [        R                  R                  XU" X   X   5      5      nMP     UR                  U5      nU$ )a#  

Computes the first n columns of a product of Householder matrices.

This function can get the vector :math:`\omega_{i}` from matrix `x` (m x n), the :math:`i-1` elements are zeros, and the i-th is `1`, the rest of the elements are from i-th column of `x`.
And with the vector `tau` can calculate the first n columns of a product of Householder matrices.

:math:`H_i = I_m - \tau_i \omega_i \omega_i^H`

Args:
    x (Tensor): A tensor with shape (*, m, n) where * is zero or more batch dimensions.
    tau (Tensor): A tensor with shape (*, k) where * is zero or more batch dimensions.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    Tensor, the dtype is same as input tensor, the Q in QR decomposition.

    :math:`out = Q = H_1H_2H_3...H_k`

Examples:
    .. code-block:: python

        >>> import paddle
        >>> x = paddle.to_tensor([[-1.1280,  0.9012, -0.0190],
        ...         [ 0.3699,  2.2133, -1.4792],
        ...         [ 0.0308,  0.3361, -3.1761],
        ...         [-0.0726,  0.8245, -0.3812]])
        >>> tau = paddle.to_tensor([1.7497, 1.1156, 1.7462])
        >>> Q = paddle.linalg.householder_product(x, tau)
        >>> print(Q)
        Tensor(shape=[4, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               [[-0.74969995, -0.02181768,  0.31115776],
                [-0.64721400, -0.12367040, -0.21738708],
                [-0.05389076, -0.37562513, -0.84836429],
                [ 0.12702821, -0.91822827,  0.36892807]])
r)   r  householder_producttauz5The input x must have the same dtype with input tau.
r   r   zThe input x must have more than 2 dimensions, and input tau must have more than 1 dimension,and the dimension of x is 1 larger than the dimension of tau
r   r   zMThe rows of input x must be greater than or equal to the columns of input x.
z,The last dim of x must be greater than tau.
Nz@The input x must have the same batch dimensions with input tau.
c           
        U R                   SS  u  p#UR                   S   n[        R                  " U5      R                  U R                  5      n[        [        XC5      5       GH  nXS 2U4   n[        5       (       a  SUS'   O![        R                  R                  USS5      nUR                  SS/5      n[        5       (       a  U R                  [        R                  [        R                  4;   aK  US S 2US 24   US S 2US 24   U-  [        R                  " U5      R                  -  X   -  -
  US S 2US 24'   M  US S 2US 24   US S 2US 24   U-  UR                  -  X   -  -
  US S 2US 24'   GM  [        R                  R                  U[        S 5      [        US 5      4U R                  [        R                  [        R                  4;   a,  US S 2US 24   US S 2US 24   U-  UR                  -  X   -  -
  O+US S 2US 24   US S 2US 24   U-  UR                  -  X   -  -
  5      nGM     US S 2S U24   $ )Nr   r   r   r   )rM   r   eyer   rR   r   r   r   rJ  setitemr%  r7   r6   r7  r  slice)r)   rj  r  r  kr  r   rJ  s           rZ   _householder_product1householder_product.<locals>._householder_product_  s   wwrs|IIbMJJqM  )s1y!A"a%A  !MM))!Q2		2q'"A  77v00&2B2BCC ABx!QR%1v{{1~'7'77#&@ AaeH  !ABx1QU8a<!##+=+FGAaeHMM))4[%4.1 77v'8'8&:J:J&KK !QR%AaeHqL133$6$?@q!"uX1ab5A);cf)DE "0 BQBxr[   r   ry   )r   rR   rL   rM   rO   r%  r   r*  r   r   rJ  rm  )r)   rj  rT   rU   r2  rp  r  r  org_x_shapeorg_tau_shapen_batchrX   r   s                rZ   ri  ri  	  sP   P 		
 	 			
 	 77cii @ 	AGG		NaLC		NQ..
	I	/ 772;!''"+% X% 772;#))B-' 7' AGGCRL)wws|syy~- 	
O	
- *
< 177|q#A++7723<DA''KIIM			2{2B89A
++r=,-
.CggajG
,,Aagg
6C7^)!$7CF--'',QT36:C	  ++k
"CJr[   ry   c               2   / SQn[         R                  R                  5       (       d'  U Vs/ s H  n[         R                  " SXS5      PM     nnUc  [	        U SU5      tp&X$S   U-  -   n[         R
                  " X5      nUS   U-  US   U-  -   n	X4$ s  snf )z3rd-order Pade approximant.)g      ^@g      N@g      (@r   r   r   r   r   	frameworkr   r    _matrix_matsr   )
mat_amat_imat_a2rR   r  r)   r2  r-  mat_umat_vs
             rZ   _matrix_exp_pade3r~    s    A++--0121V[[Q&2~!%E2

Q4%<
CMM%%EaD6MAaD5L(E< 3s   !Bc               X   / SQn[         R                  R                  5       (       d'  U Vs/ s H  n[         R                  " SXd5      PM     nnUc  [	        U SU5      tp#nX5S   U-  -   US   U-  -   n[         R
                  " X5      n	US   U-  US   U-  -   US   U-  -   n
X4$ s  snf )z5th-order Pade approximant.)g     @g     @g     @@g     @z@g      >@r         r   r   r   rv  )ry  rz  r{  mat_a4rR   r  r)   r2  r-  r|  r}  s              rZ   _matrix_exp_pade5r    s     	0A++--0121V[[Q&2~)%E:
Q4&=
 1Q4%<
/CMM%%EaD6MAaD6M)AaD5L8E< 3s   !B'c               |   / SQn[         R                  R                  5       (       d'  U Vs/ s H  n[         R                  " SXu5      PM     nnUc  [	        U SU5      tp#pHXFS   U-  -   US   U-  -   US   U-  -   n	[         R
                  " X	5      n
US   U-  US   U-  -   US   U-  -   US	   U-  -   nX4$ s  snf )
z7th-order Pade approximant.)g    ~pAg    ~`Ag    @t>Ag    @Ag     @g     @g      L@r   r     r  r   r  r   r   rv  )ry  rz  r{  r  mat_a6rR   r  r)   r2  r-  r|  r}  s               rZ   _matrix_exp_pade7r    s     	LA++--0121V[[Q&2~%1%E%B"
Q4&=
 1Q4&=
01Q4%<
?CMM%%EaD6MAaD6M)AaD6M9AaD5LHE< 3s   !B9c                  / SQn[         R                  R                  5       (       d'  U Vs/ s H  n[         R                  " SX5      PM     nnUc  [	        U SU5      tp#pEn	XWS   U-  -   US   U-  -   US   U-  -   US   U-  -   n
[         R
                  " X
5      nUS   U-  US   U-  -   US	   U-  -   US
   U-  -   US   U-  -   nX4$ s  snf )z9th-order Pade approximant.)	g   ynBg   yn Bg    Ag   @
Ag    2|Ag    ~@Ag     @g     @g     V@r         r  r  r   r  r  r   r   rv  )ry  rz  r{  r  r  mat_a8rR   r  r)   r2  r-  r|  r}  s                rZ   _matrix_exp_pade9r    s   
	A ++--0121V[[Q&2~-9%E-J*
Q4&=
 1Q4&=
01Q4&=
@1Q4%<
OCMM%%E	!v
A$-	
A$-	 A$-	 A$,		 
 < 3s   !Cc               >   / SQn[         R                  R                  5       (       d'  U Vs/ s H  n[         R                  " SXu5      PM     nnUc  [	        U SU5      tp#pH[         R
                  " XDUS   U-  -   US   U-  -   5      US   U-  -   US   U-  -   US   U-  -   US	   U-  -   n	[         R
                  " X	5      n
US
   U-  US   U-  -   US   U-  -   n[         R
                  " XK5      US   U-  -   US   U-  -   US   U-  -   US   U-  -   nX4$ s  snf )z13th-order Pade approximant.)g D`lCg D`\Cg `=Hb;Cg 	eCg JXBg  "5Bg  /cBg   \L8Bg   pķAg    syAg    S-Ag     @g     f@r   r     r(   r  r  r  r      
   r  r  r   r   rv  )ry  rz  r{  r  r  rR   r  r)   r2  tmp_ur|  tmp_vr}  s                rZ   _matrix_exp_pade13r    sc   	A ++--0121V[[Q&2~%1%E%B" 	fquv~5!vEF
A$-	
A$-	 A$-	 A$,		 
 MM%'EbEFNQrUV^+adVm;Ef$
A$-	
A$-	 A$-	 A$,		 
 <+ 3s   !Dc           
        [        U 5      S:X  a5  [        R                  " [        R                  " X S   5      US   US   5      $ [        R                  " [        R                  " X S   5      US   [	        U SS  USS  U5      5      $ )Nr   r   )rL   r   r  	less_than_matrix_uv_where)valscasesl1_norms      rZ   r  r    s    
4yA~||W1g.a%(
 	
 ||W1g.!HT!"XuQRy':
 	
r[   c                    [         R                  " X 5      nS nS nS nUS:  a  [         R                  " X35      nUS:  a  [         R                  " XC5      nUS:  a  [         R                  " XS5      nX4XV4$ )Nr   r  r  )r   r   )ry  totalrR   r{  r  r  r  s          rZ   rx  rx  $  si    ]]5(FFFFqyv.qyv.qyv.6))r[   c                   [         R                  " U R                  S   US9n[        U SU5      tpVn[	        XXSS9u  p[        XXVUS9u  p[        U [         R                  " [         R                  " [         R                  " SSU5      U5      U5      -  UUS9u  p[         R                  " SSU5      [         R                  " SSU5      4n[        XX4U5      n[        XX4U5      nUU4$ )Nr   ry   r  r   r   g#"ՀA?gNj?)r   rl  rM   rx  r~  r  r  r!   r   r    r  )ry  r  	squaringsrR   rz  r{  r  r2  u3v3u5v5u7v7condsr   r  s                    rZ   _matrix_uv_float32r  6  s    JJu{{2e4E%eQ6FQuVAFBuV5IFB
++JJv{{2sE2I>
	

 	FB 	B.6B-u5E
 	Rg6ARg6Aa4Kr[   c                z   [         R                  " U R                  S   US9n[        U SU5      tpVpxn	[	        XXSS9u  p[        XXVUS9u  p[        XXVXsS9u  p[        XXVXxUS9u  nn[        U [         R                  " [         R                  " [         R                  " SSU5      U5      U5      -  UUS9u  nn[         R                  " SSU5      [         R                  " SSU5      [         R                  " SSU5      [         R                  " SS	U5      4n[        UXUUU4U5      n[        UXUUU4U5      nUU4$ )
Nr   ry   r  r   r   g ,?g|zی@?gQi?gd @)r   rl  rM   rx  r~  r  r  r  r  r!   r   r    r  )ry  r  r  rR   rz  r{  r  r  r  r2  r  r  r  r  r  r  u9v9u13v13r  r   r  s                          rZ   _matrix_uv_float64r  P  sI   JJu{{2e4E)5eQ)F&FFQuVAFBuV5IFBffFB ffEFB "
++JJv{{2sE2I>
	

 	HC 	B.6B.6B.6B-u5	E 	R 5w?AR 5w?Aa4Kr[   c           
       ^
^^^^^^ [        U [        R                  [        R                  R                  R
                  [        R                  R                  R                  R                  45      (       d  [        R                  " U 5      mOU m[        TR                  5      m
T
S;  a  [        ST
 35      eTR                  S:X  a  [        R                  " T5      $ TR                  S:  a  [        S5      eTR                  S   TR                  S   :w  a  [        S5      e[!        TR                  SS	 5      S
S
/:X  a  [        R                  " T5      $ [        R"                  " [        R$                  " [        R&                  " [        R(                  " T5      TR                  S-
  S9SS9SS/S9n[        R*                  " TR                  ST
5      mS	nT
S:X  a  [        R*                  " SST
5      n[        R,                  " [        R.                  " X$-  5      [        R.                  " [        R*                  " SST
5      5      -  5      m[        R0                  " T[        R2                  " T5      5      m[4        nOT
S:X  a  [        R*                  " SST
5      n[        R,                  " [        R.                  " X$-  5      [        R.                  " [        R*                  " SST
5      5      -  5      m[        R0                  " T[        R2                  " T5      5      m[6        nU" TUTT
5      u  mm[        R8                  " [        R$                  " U5      5      m[        R:                  R<                  R?                  TUU4S jU
U4S j5      n[        R$                  " T5      m[        R*                  " SST
5      nUU4S jnU4S jn[        R:                  R<                  RA                  XxXe/5      u  pU$ )a  
Computes the matrix exponential of square matrices.

.. math::

    exp(A) = \sum_{n=0}^\infty A^n/n!

The input tensor x should be of square matrices with shape like :math:`(*, M, M)`, and the
exponential output is computed by Pade approximation of the scaling and squaring method.

[1] Nicholas J. Higham, The scaling and squaring method for the matrix exponential revisited.

Args:
    x (Tensor): A tensor with shape :math:`(*, M, M)` where :math:`*` is zero or more batch dimensions. The data type should be one of float32, float64.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    Tensor, the shape and dtype are same as input tensor.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> mat_a = paddle.empty((2, 2, 2))
        >>> mat_a[0, :, :] = paddle.eye(2, 2)
        >>> mat_a[1, :, :] = 2 * paddle.eye(2, 2)
        >>> print(mat_a)
        Tensor(shape=[2, 2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[1., 0.],
          [0., 1.]],
         [[2., 0.],
          [0., 2.]]])

        >>> out = paddle.linalg.matrix_exp(mat_a)
        >>> print(out)
        Tensor(shape=[2, 2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[2.71828198, 0.        ],
          [0.        , 2.71828198]],
         [[7.38905621, 0.        ],
          [0.        , 7.38905621]]])

        >>> import math
        >>> mat_a = paddle.to_tensor([[0, math.pi/3], [-math.pi/3, 0]])
        >>> out = paddle.linalg.matrix_exp(mat_a)
        >>> print(out)
        Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[ 0.49999994,  0.86602545],
         [-0.86602551,  0.50000000]])

rY  z=The input tensor's dtype must be float32 or float64, but got r   r   z1The input tensor must be at least two-dimensionalr   r   z.Last 2 dimensions of the tensor must be squareNr   r6  r.   r   gj%eg@r   r/   gC|@c                 R   > [         R                  R                  T * T-   T T-   5      $ r   )r   r  r%  )r   r  s   rZ   r   matrix_exp.<locals>.<lambda>  s     ##QBFAE2r[   c                 d   > [         R                  " TR                  [        R                  T 5      $ r   )r   r    rM   r   nan)rR   ry  s   rZ   r   r    s    EKK7r[   c                h   >^  [         R                  R                  R                  TU U4S jS 5      $ )Nc                 2   > [         R                  " T T5      $ r   )r   r  )r   max_squarings   rZ   r   *matrix_exp.<locals>.cond.<locals>.<lambda>  s    F$$Q5r[   c                 J    [         R                  " SS[         R                  S9$ )Nr   Fry   )r   r    r+   r   r[   rZ   r   r    s    FKKE=r[   )r   rJ  nnr4  )r   r2  	is_finiter  s   ` rZ   r4  matrix_exp.<locals>.cond  s)    }}$$5=
 	
r[   c                   > U S-   [         R                  " [         R                  " U T5      [         R                  " X5      U5      4$ r   )r   r  r  r   )r   r   r  s     rZ   bodymatrix_exp.<locals>.body  s>    1ufllQ	*MM&)
 
 	
r[   )!rK   r   r$   rE  rw  r   	libpaddlerh  ri  r?  r   rR   rN   r  exprM   rI   r   r   r   r   r    floorlogmaximum
zeros_liker  r  isfiniterJ  r  r4  
while_loop)r)   rT   r  _matrix_uv_funcmaxnormr   r   r4  r  r2  rR   r  ry  r  r  r   r  s             @@@@@@@rZ   
matrix_expr  s  s   l 	MMKK!!**KK!!%%++	
    #%++&E **KE7S
 	

 zzQzz%   zzA~LMM{{2%++b/)IJJ EKK!Q'zz%   

6::fjj/ejj1nEBO"XG
 EKKE2IO 	++b"3U;LLJJw()jjRe456
	 NN9f.?.?	.JK	,	)	++b"3U;LLJJw()jjRe456
	 NN9f.?.?	.JK	,5'9e<DAq 

7 34I]]""27F ::i(LB5!A

   ++DDIAMr[   c           	     
   S nS nS nS n	S n
[        US[        S5        U" U 5        U" X5        U R                  S   nU R                  SU/5      nUR                  S	   nS
nUbJ  UR	                  U R
                  5      nUR                  U/5      nUR                  S	   U:X  d
   SU 35       eU	" X5        Uc  [        R                  " US/U R
                  S9n[        R                  " US	S9R                  S/5      n[        R                  " US	S9R                  S/5      n[        R                  " 5       (       a  UUS
S
2S	4'   XS
S
2S4'   O[        R                  R                  U[        S
5      S	4U5      n[        R                  R                  U[        S
5      S4U5      nO/[        R                  " X R
                  S9R                  US/5      n/ n/ n/ n[        U[         ["        45      (       a  [        U[         5      (       a  U/U-  n[%        U5      U:X  d   SU S35       e['        U5       H  u  nn[        UU   [         5      (       d  [)        SU S35      e[        R*                  " US	   US   UU   S-   U R
                  5      nUR-                  U5        UR-                  UR/                  5       5        UR-                  UU   S-   5        M     O[        U[0        5      (       ay  U" X5        U Hj  n[        R                  " U5      nUR-                  U5        UR-                  UR/                  5       5        UR-                  UR                  S	   S-   5        Ml     O[)        S5      e/ n['        U5       HH  u  nn[        R                  " U5      nUR-                  [        R2                  " UUS
S
2U4   SS95        MJ     [        R                  " U5      n[5        U5       H  nUS
S
2U4   UU   S   :H  n[        R                  " 5       (       a&  [        R6                  " UUU   S-
  UU   5      UU'   MU  [        R6                  " UUU   S-
  UU   5      n[        R                  R                  UUU5      nM     [1        U5      nU
" UU5      n[        R8                  " UU[        R                  " U5      R;                  5       S9nUR                  U5      nUR	                  U R
                  5      nU[        SS5      4-  nUU   nU(       aO  UR=                  5       n [5        U5       H+  nUS/-  n!UU   S-
  U!U'   UUU   R                  U!5      -  nM-     UU -  nUU4$ )aD  
Computes a multi-dimensional histogram of the values in a tensor.

Interprets the elements of an input tensor whose innermost dimension has size `N` as a collection of N-dimensional points. Maps each of the points into a set of N-dimensional bins and returns the number of points (or total weight) in each bin.

input `x` must be a tensor with at least 2 dimensions. If input has shape `(M, N)`, each of its `M` rows defines a point in N-dimensional space. If input has three or more dimensions, all but the last dimension are flattened.

Each dimension is independently associated with its own strictly increasing sequence of bin edges. Bin edges may be specified explicitly by passing a sequence of 1D tensors. Alternatively, bin edges may be constructed automatically by passing a sequence of integers specifying the number of equal-width bins in each dimension.

Args:
    x (Tensor): The input tensor.
    bins (list[Tensor], list[int], or int): If list[Tensor], defines the sequences of bin edges. If list[int], defines the number of equal-width bins in each dimension. If int, defines the number of equal-width bins for all dimensions.
    ranges (sequence[float]|None, optional): Defines the leftmost and rightmost bin edges in each dimension. If is None, set the minimum and maximum as leftmost and rightmost edges for each dimension.
    density (bool, optional): If False (default), the result will contain the count (or total weight) in each bin. If True, each count (weight) is divided by the total count (total weight), then divided by the volume of its associated bin.
    weights (Tensor, optional): By default, each value in the input has weight 1. If a weight tensor is passed, each N-dimensional coordinate in input contributes its associated weight towards its bin's result. The weight tensor should have the same shape as the input tensor excluding its innermost dimension N.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    N-dimensional Tensor containing the values of the histogram. ``bin_edges(Tensor[])``,  sequence of N 1D Tensors containing the bin edges.

Examples:
    .. code-block:: python
        :name: example

        >>> import paddle
        >>> x = paddle.to_tensor([[0., 1.], [1., 0.], [2.,0.], [2., 2.]])
        >>> bins = [3,3]
        >>> weights = paddle.to_tensor([1., 2., 4., 8.])
        >>> paddle.histogramdd(x, bins=bins, weights=weights)
        (Tensor(shape=[3, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               [[0., 1., 0.],
                [2., 0., 0.],
                [4., 0., 8.]]), [Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               [0.        , 0.66666669, 1.33333337, 2.        ]), Tensor(shape=[4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               [0.        , 0.66666669, 1.33333337, 2.        ])])

    .. code-block:: python
        :name: examp2

        >>> import paddle
        >>> y = paddle.to_tensor([[0., 0.], [1., 1.], [2., 2.]])
        >>> bins = [2,2]
        >>> ranges = [0., 1., 0., 1.]
        >>> density = True
        >>> paddle.histogramdd(y, bins=bins, ranges=ranges, density=density)
        (Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               [[2., 0.],
                [0., 2.]]), [Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               [0.        , 0.50000000, 1.        ]), Tensor(shape=[3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               [0.        , 0.50000000, 1.        ])])


c                d    [        U R                  5      S:  d   S5       e[        U SSS/S5        g )Nr   z4input x must be a tensor with at least 2 dimensions.r)   r.   r/   histogramdd)rL   rM   r   r  s    rZ   	__check_xhistogramdd.<locals>.__check_xH  sB    177|q  	
B	
  	! 	
r[   c                    U  HJ  n[         R                  " U5      n[        USSS/S5        UR                  UR                  :X  a  ME   S5       e   g )Nrs  r.   r/   r  z@When bins is Tensor[], the dtype of bins must be the same as x.
)r   r?  r   rR   )rs  r)   bins_tensors      rZ   __check_bins!histogramdd.<locals>.__check_binsV  s^    K **;7K$  $$/ S/  r[   c                *   Uc  g U R                   UR                   p2[        U5      [        U5      S-   :X  d   S5       e[        U5       H  u  pEX4   X$   :X  a  M   S5       e   [        USSS/S5        UR                  U R                  :X  d   S5       eg )Nr   zrif weight tensor is provided,it should have the same shape as the input tensor excluding its innermost dimension.
r  r.   r/   r  z,The dtype of weights must be the same as x.
)rM   rL   rO   r   rR   )r)   r  rY   weights_shaper   r2  s         rZ   __check_weights$histogramdd.<locals>.__check_weightsf  s    ?!"'--7|s=1A55 	
e	
5 m,DA #wz1 i1 -
 	! 	
 }}' 	
;	
'r[   c                |    Uc  g [        US[        [        4S5        U S-  [        U5      :X  d   SU S-   S35       eg )Nrangesr  r   z"The length of ranges list must be 
)r   rI   rJ   rL   )Dr  s     rZ   __check_ranges#histogramdd.<locals>.__check_ranges  sI    >68dE]MB1uF# 	
0Qr:	
#r[   c                4   [         R                  " US S S2   5      R                  SS9R                  S5      SS  n[         R                  " U[         R                  " S/UR
                  S9/5      n[         R                  " U SS9nX2-  R                  SS9nU$ )Nr   r   )rV   r   ry   r6  )r   r?  cumprodflipr(  rR   stackr   )
index_list
hist_shapestridesstacked_indicesflattened_indexs        rZ   __compute_flattened_index.histogramdd.<locals>.__compute_flattened_index  s    "":dd#34<<<CHHKABO--f&&s'--@A
 !,,z;*499r9Br[   rt  r  r   r   NzThe size of weight must be r   ry   r6  r   zThe length of bins must be z when bins is a list.
zThe type of z%-th element in bins list must be int.z+Input bins must be Tensor[], int[], or int.T)right)r  )r   r+   rM   r%  r   rR   r   r*  r   r   r   rJ  rm  rn  r?  rK   r   rI   rL   rO   rN   r{  r  diffrJ   searchsortedr   r  r}  r'  r   )"r)   rs  r  rt  r  rT   r  r  r  r  r  r  reshaped_inputr  reshaped_weightsmaxvminvedgesr  dedgesrU   r  ebinr  edger   on_edgeindex_list_ir  histrF  r   rM   s"                                     rZ   r  r  
  s
   |
 
4
	 w	47aLA	AYYAw'NQA..)"??A3/%%a(A-P1LQC/PP-1~q!fAGG4zz.q1992$?zz.q1992$?!!##F1a4L1a4L]]**6E$K3CTJF]]**6E$K3CTJF!!&8@@!QHEJF$d$$dC  6A:D4yA~ 	
)!,CD	
~  'FCd3i-- "3%'LM  !adDIM177CALLOMM!&&(#d3i!m, ( 
e
 
 	TC""3'CLLMM#((*%ciilQ./	  FGGJ u%	T%nQV&<DI	
 &
 !!*-J1X A&%(2,6!!##"LLA*JqMJqM "<<A*JqML  ..z1lKJ  z"J/
JGO??"":.335D
 <<
#D;;qwwDaD:DHHJqAGE!!}q(E!H&)++E22D  		%=r[   c                   [        UR                  S/ SQS5        [        US[        S5        [        US[        S5        U R                  UR                  :X  a  U R                  UR                  :X  d   S5       e[	        U R
                  5      S:  a2  [	        UR
                  5      S:  a  [	        UR
                  5      S:  d   S	5       e[	        U R
                  5      [	        UR
                  5      S-   :X  a,  [	        U R
                  5      [	        UR
                  5      :X  d   S
5       eU R
                  S   UR
                  S   :X  d   S5       eU(       a/  U(       a(  U R
                  S   UR
                  S   :X  d   S5       eOU(       d/  U(       a(  U R
                  S   UR
                  S   :X  d   S5       eO]U(       a/  U(       d(  U R
                  S   UR
                  S   :X  d   S5       eO'U R
                  S   UR
                  S   :X  d   S5       e[	        U R
                  5      S:X  aG  U R
                  S   UR
                  S   :X  a   U R
                  S   UR
                  S   :X  d   S5       e[        X5      n[	        U R
                  5      S:X  a  U(       a  UR                  OUnO"U(       a  [        R                  " U/ SQ5      OUnU(       a  [        Xb5      nU$ [        X&5      nU$ )a!  
Calculate the product of a normal matrix and a householder matrix.
Compute the product of the matrix C (given by y) with dimensions (m, n) and a matrix Q,
where Q is generated by the Householder reflection coefficient (x, tau). Returns a Tensor.

Args:
    x (Tensor): Shape(\*,mn, k), when left is True, the value of mn is equal to m, otherwise the value of mn is equal to n. \* indicates that the length of the tensor on axis 0 is 0 or greater.
    tau (Tensor): Shape (\*, min(mn, k)), where \* indicates that the length of the Tensor on axis 0 is 0 or greater, and its type is the same as input.
    y (Tensor): Shape (\*m,n), where \* indicates that the length of the Tensor on axis 0 is 0 or greater, and its type is the same as input.
    left (bool, optional): Determines the order in which the matrix product operations are operated. If left is true, the order of evaluation is op(Q) \* y, otherwise, the order of evaluation is y \* op(Q). Default value: True.
    transpose (bool, optional): If true, the matrix Q is conjugated and transposed, otherwise, the conjugate transpose transformation is not performed. Default value: False.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    Tensor. Data type and dimension are equals with :attr:`y`.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> import numpy as np
        >>> from paddle import  linalg

        >>> input = paddle.to_tensor([[-114.6, 10.9, 1.1], [-0.304, 38.07, 69.38], [-0.45, -0.17, 62]])
        >>> tau = paddle.to_tensor([1.55, 1.94, 3.0])
        >>> y = paddle.to_tensor([[-114.6, 10.9, 1.1], [-0.304, 38.07, 69.38], [-0.45, -0.17, 62]])
        >>> output = linalg.ormqr(input, tau, y)
        >>> print(output)
        Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[ 63.82712936 , -13.82312393 , -116.28614044],
            [-53.65926361 , -28.15783691 , -70.42700958 ],
            [-79.54292297 ,  24.00182915 , -41.34253311 ]])
ro   r  ormqrr&  r:   z9The input tau and y must have the same dtype with the x.
r   r   zaThe input x and y must have more than 2 dimensions, and input tau must have more than 1 dimensionzsthe dimension of x is 1 larger than the dimension of tau
 and the dimension of x is equal to the dimension of inputr   z7The innermost dimension of x and tau should be the samer   z0The row dimensions of x and y should be the samezGThe column dimension of x and the row dimension of y should be the samezGThe row dimension of x and the column dimension of y should be the samez<The column dimensions of Impt and Osser's should be the samer  r   z=The input and tau and y parameters should have the same batch)r   r   r   )r   rR   r   r+   rL   rM   ri  r  r   r:   r   )r)   rj  ro   r&  r:   rT   r  r   s           rZ   r  r    s   T 		
 	 tVT7+y+tW577ciiAGGqww$6 D6 qww<1QWW!2s399~7J kJ qww<3syy>A--#agg,#	C 3  	 
 772;#))B-' A' Twwr{aggbk) 	
>	
) 4wwr{aggbk) 	
U	
) 
4wwr{aggbk) 	
U	
) wwr{aggbk) 	
J	
) 177|qwwqzQWWQZ'AGGAJ#))A,,F 	
K	
F 	A#A
177|qACC!.7FQ	*Q!VA\FM (.a|FMr[   c                   U R                   S:w  a  [        S5      eU R                  S   U R                  S   :w  a  [        S5      eU(       a  U R                  U -  nOX R                  -  n[        R
                  R                  U5      $ )a  
Using the Cholesky factor `U` to calculate the inverse matrix of a symmetric positive definite matrix, returns the matrix `inv`.

If `upper` is `False`, `U` is lower triangular matrix:

.. math::

    inv = (UU^{T})^{-1}

If `upper` is `True`, `U` is upper triangular matrix:

.. math::

    inv = (U^{T}U)^{-1}

Args:
    x (Tensor): A tensor of lower or upper triangular Cholesky decompositions of symmetric matrix with shape `[N, N]`.
        The data type of the `x` should be one of ``float32``, ``float64``.
    upper (bool, optional): If `upper` is `False`, `x` is lower triangular matrix, or is upper triangular matrix. Default: `False`.
    name (str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

Returns:
    Tensor. Computes the inverse matrix.

Examples:
    .. code-block:: python

        >>> import paddle

        >>> # lower triangular matrix
        >>> x = paddle.to_tensor([[3.,.0,.0], [5.,3.,.0], [-1.,1.,2.]])
        >>> out = paddle.linalg.cholesky_inverse(x)
        >>> print(out)
        Tensor(shape=[3, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        [[ 0.61728382, -0.25925916,  0.22222219],
         [-0.25925916,  0.13888884, -0.08333331],
         [ 0.22222218, -0.08333331,  0.25000000]])

        >>> # upper triangular matrix
        >>> out = paddle.linalg.cholesky_inverse(x.T, upper=True)
        >>> print(out)
        Tensor(shape=[3, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
        [[ 0.61728382, -0.25925916,  0.22222219],
         [-0.25925916,  0.13888884, -0.08333331],
         [ 0.22222218, -0.08333331,  0.25000000]])

r   z&The input tensor must be 2-dimensionalr   r   z&The input tensor must be square matrix)r  rN   rM   r  r   r  inv)r)   r\  rT   r
  s       rZ   cholesky_inverser  ]  sp    d 	vv{ABBwwqzQWWQZABBCC!GG==Qr[   r   )r)   r$   r;   Sequence[int]rT   r  r  r$   )r_   r$   r^   r  r  r$   )r)   paddle.TensorrT   r  r  r  )FFNr   r,   identityN)r   NFN)r)   r$   r~   r   rB   zint | Sequence[int] | Noner   r+   rT   r  rR   paddle._typing.DTypeLike | NonerX   Tensor | Noner  r$   )r)   r$   r~   r  rB   r  r   r+   rT   r  r  r$   )NNFNNN)r)   r$   r~   float | _POrder | NonerB   z(int | list[int] | tuple[int, int] | Noner   r+   rX   zpaddle.Tensor | NonerR   r  rT   r  r  r$   )r   N)
r)   r$   ro   r$   r~   r   rT   r  r  r$   )NN)r)   r$   r~   r  rT   r  r  r$   )r   N)
r)   r$   ro   r$   rB   r   rT   r  r  r$   )TTNNN)r)   r$   rD  r+   rE  r+   rF  r  rG  r  rT   r  r  r$   )r_   r$   rT   r  r  r$   )r(   N)FN)r)   r$   r\  r+   rT   r  r  r$   )NFNNN)r)   r$   rf  float | Tensor | Nonerb  r+   r`  r  ra  r  rT   r  r  r$   )d   r   r   NFN)r_   r$   rs  r   r   r   r   r   rx  r  rt  r+   rT   r  r  r$   )r   r   r   N)r_   r$   rs  r   r   r   r   r   rT   r  r  r$   )Nr   N)
r)   r$   r  r  r  r   rT   r  r  r$   )r)   r$   r  r$   rT   r  r  r$   )r)   r$   rT   r  r  r$   )
r)   r$   r   r+   rT   r  rX   z$tuple[Tensor, Tensor, Tensor] | Noner  tuple[Tensor, Tensor, Tensor])Nr   NN)r)   r$   r  
int | Noner  r   r  r  rT   r  r  r  )NTr   N)r)   r$   r  r  r  r+   r  r   rT   r  r  r  )r)   r$   r  r   rT   r  r  ztuple[Tensor, int])..)r)   r$   r  zLiteral['reduced', 'complete']rT   r  r  tuple[Tensor, Tensor])r)   r$   r  zLiteral['r']rT   r  r  r$   )reducedN)r  zTensor | tuple[Tensor, Tensor])...)
r)   r$   r  r+   r  zLiteral[False]rT   r  r  r  )
r)   r$   r  r+   r  zLiteral[True]rT   r  r  r  )
r)   r$   r  r+   r  r+   rT   r  r  5tuple[Tensor, Tensor] | tuple[Tensor, Tensor, Tensor])TFN)r  r  )r  N)
r  r$   r  r$   r  r$   r  zLiteral['N', 'T', 'C']rT   r  )TTN)r)   r$   ro   r$   r  r+   r  r+   rT   r  r  r  )r)   r$   rT   r  r  r  )r)   zlist[Tensor]rT   r  r  r$   )r  N)r)   r$   r  Literal['L', 'U']rT   r  r  r  )r:  FN)
r)   r$   r  zfloat | Tensorrb  r+   rT   r  r  r$   )TN)r)   r$   ro   r$   r&  r+   rT   r  rX   r  r  r$   )TFFN)r)   r$   ro   r$   r\  r+   r:   r+   r)  r+   rT   r  r  r$   )
r)   r$   ro   r$   r\  r+   rT   r  r  r$   )r)   r$   r  r  rT   r  r  r$   )NNN)r)   r$   ro   r$   r  zfloat | Noner@  z1Literal['gels', 'gelsy', 'gelsd', 'gelss'] | NonerT   r  r  z%tuple[Tensor, Tensor, Tensor, Tensor])r)   r$   rD  r+   rT   r  r  r$   )r   r[  N)r)   r$   ro   r$   r~   r   r_  zhLiteral['use_mm_for_euclid_dist_if_necessary', 'use_mm_for_euclid_dist', 'donot_use_mm_for_euclid_dist']rT   r  r  r$   )r)   r$   rj  r$   rT   r  r  r$   )NNNN)NNNNN)r  NFNN)r)   r$   rs  zTensor | list[int] | intr  zSequence[float] | Nonert  r+   r  r  rT   r  r  ztuple[Tensor, list[Tensor]])r)   r$   rj  r$   ro   r$   r&  r+   r:   r+   rT   r  r  r$   )w
__future__r   r&  typingr   r   numpyr   typing_extensionsr   r   r   r   paddle._C_opsr	   r
   r   r   paddle.base.libpaddler   paddle.common_ops_importr   paddle.tensor.mathr   paddle.utils.decorator_utilsr   r   r   r   paddle.utils.inplace_utilsr   base.data_feederr   r   r   r   common_ops_importr   rw  r   r   r   r   creationr    manipulationr!   r"   collections.abcr#   r$   r'   __annotations____all__rY  r:   r]   ra   re   rp   r   r	  r   r  r4  r8  r:  r<  rV  rX  r[  rc  rp  rz  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;  rP  rZ  ri  r~  r  r  r  r  r  rx  r  r  r  r  r  r  r   r[   rZ   <module>r     s   #  )  1   4 4 * , .  D  )    "( .GY.
  7;}}"}*4}} }@ * * v) )> 
 @ 	
	eP E7UG45 '+} .2}}} %} 	}
 } +} 
} } 6}D /12hh
h
h
 ,h
 	h

 h
 h
V GS>%IJ !%59 $-1ttt 3t 	t
 
t +t t t Ktnoh !%E
E
E
 E
 	E
V 	!!! ! 	!
 !L ""||| | 	|
 | | |~Tn  ( fug&' 	\\\ \ 	\
 \ (\~:~ "&"&"&ii	i i  	i
  i i i\  OO
O 
O 
	O
 O O O Oh 6:6:
6: 
6: 
	6:
 6: 6:v "	CCC C 	C
 CL:z6rBN  S
 15SSS S
 
.S #Sl!H%%4 www w 	w
 w #wx R6R6R6 R6 	R6
 R6 #R6l +/JJJ'JJZ 
 ,/  
(    	  
  
 
  	 
 
	D $	DN 
  #	      	 
   
  
 "	((( ( 	(
 #( 
( 
LO@@@-1@?I@:@ 
@ *.g:g\ %(YYY Y "	Y
 Y~ ppp p 	p
 p #pf<~=@Mb BFP%P%&P%4>P%P%j "	{{{ { 	{
 {|& #sc3Z( 	N NNN N 	N 
N N )Nh [[[ [ 	[
 [ [ [~ CG888!%85?88x BFJJ&J4>JJ` @Dv:v:v: v: >	v:
 v: +v:rCR 
 	.zzz z	z z z| 04EEE",EERt   ,0:>$ 9=GK& % %R 9=)GK)X

*$4 FTr &(%)!ll
"l #l 	l
 l l !lf aa	a a 	a
 a a aJ 8<< < < *4< < r[   