Ë
    –\;jûQ ã                   óì  — d dl Zd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 ddl
mZmZmZ ddlmZ dd	lmZmZmZ d
dlmZ d
dlmZ d
dlmZ g ZdZd5d„Ze	d5d„«       Zd6d„Zd7d„Zd8d„Z d9d„Z!d5d„Z"d:d„Z#d5d„Z$e	d5d„«       Z%d;d„Z&d<d„Z'd=d„Z(d5d„Z)d>d„Z*d?d„Z+d5d„Z,d5d „Z-d5d!„Z.d<d"„Z/d@d#„Z0d5d$„Z1dAd%„Z2dBd&„Z3dCd'„Z4d5d(„Z5d5d)„Z6d5d*„Z7dDd+„Z8dEd,„Z9d5d-„Z:	 dFd.„Z;d<d/„Z<dDd0„Z=dGd1„Z>dHd2„Z?	 dId3„Z@d5d4„ZAy)Jé    N)Ú_C_ops)ÚDataType)ÚVarDesc)Úinplace_apis_in_dygraph_onlyé   )Úcheck_dtypeÚ
check_typeÚcheck_variable_and_dtype)ÚVariable)ÚLayerHelperÚin_dynamic_modeÚin_dynamic_or_pir_modeé   )Úfull)Úcast)Ú_get_reduce_axisé	   c           	      óÞ  — t        «       rt        j                  | |«      S t        | dg d¢d«       t	        |dt
        t        fd«       t        |t        «      rt        |«      }t        |«      t        | j                  «      k7  r.t        dt        | j                  «      › dt        |«      › d�«      ‚t        |«      D ]D  \  }}|t        | j                  «      k\  sŒt        d|||   t        | j                  «      fz  «      ‚ t        di t        «       ¤Ž}|j                  | j                  «      }|j                  | j                  «      }|j!                  d	d
| gi|g|gdœd|i¬«       |S )aM  
    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`.

    Args:
        x (Tensor): The input Tensor. It is a N-D Tensor of data types bool, float32, float64, int32.
        perm (list|tuple): Permute the input according to the data of perm.
        name (str, 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

            x = [[[ 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) =  [2,3,4]

            # Example 1
            perm0 = [1,0,2]
            y_perm0 = [[[ 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) = [3,2,4]

            # Example 2
            perm1 = [2,1,0]
            y_perm1 = [[[ 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) = [4,3,2]

    Examples:

        .. code-block:: python

            >>> import paddle

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

    Úx)	ÚboolÚfloat16Úfloat32Úfloat64Úint32Úint64Úuint16Ú	complex64Ú
complex128Ú	transposeÚpermz–Input(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 Ú.z“Each element in Input(perm) should be less than Input(x)'s dimension, but %d-th element in Input(perm) is %d which exceeds Input(x)'s dimension %d.Ú
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           ú]G:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/tensor/linalg.pyr   r   $   sj  € ôd ÔÜ×Ñ  4Ó(Ð(ä ØØò
ð ô	
ô  	�4˜¤$¬ °Ô<Ü�dœEÔ"Ü˜“:ˆDÜˆt‹9œ˜AŸG™G›Ò$Üð9ä9<¸Q¿W¹W»¸ð G0Ü03°D³	¨{¸!ð=óð ô " $ž‰HˆC�Ø”c˜!Ÿ'™'“lÓ"Ü ð$à'*¨D°©I´s¸1¿7¹7³|Ð&DñEóð ð (ô Ñ5¬F«HÑ5ˆØ×7Ñ7¸¿¹Ó@ˆØ×;Ñ;¸A¿G¹GÓDˆØ×ÑØØ˜!˜�:Ø ˜E¨g¨YÑ7Ø˜4�.ð	 	ô 	
ð ˆ
ó    c                 óD   — t        «       rt        j                  | |«      S y)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    r8   s      r>   rA   rA   ‡   s"   € ô ÔÜ× Ñ   DÓ)Ð)ð r?   c                 óþ   — t        «       rt        j                  | |||«      S ||dœ}d„ } || |«       t        di t	        «       ¤Ž}|j                  | j                  ¬«      }|j                  d| |dœd|i|¬«       |S )	aí  
    Applies matrix multiplication to two tensors. `matmul` follows
    the complete broadcast rules,
    and its behavior is consistent with `np.matmul`.

    Currently, the input tensors' number of dimensions can be any, `matmul` can be used to
    achieve the `dot`, `matmul` and `batchmatmul`.

    The actual behavior depends on the shapes of :math:`x`, :math:`y` and the
    flag values of :attr:`transpose_x`, :attr:`transpose_y`. Specifically:

    - If a transpose flag is specified, the last two dimensions of the tensor
      are transposed. If the tensor is ndim-1 of shape, the transpose is invalid. If the tensor
      is ndim-1 of shape :math:`[D]`, then for :math:`x` it is treated as :math:`[1, D]`, whereas
      for :math:`y` it is the opposite: It is treated as :math:`[D, 1]`.

    The multiplication behavior depends on the dimensions of `x` and `y`. Specifically:

    - If both tensors are 1-dimensional, the dot product result is obtained.

    - If both tensors are 2-dimensional, the matrix-matrix product is obtained.

    - If the `x` is 1-dimensional and the `y` is 2-dimensional,
      a `1` is prepended to its dimension in order to conduct the matrix multiply.
      After the matrix multiply, the prepended dimension is removed.

    - If the `x` is 2-dimensional and `y` is 1-dimensional,
      the matrix-vector product is obtained.

    - If both arguments are at least 1-dimensional and at least one argument
      is N-dimensional (where N > 2), then a batched matrix multiply is obtained.
      If the first argument is 1-dimensional, a 1 is prepended to its dimension
      in order to conduct the batched matrix multiply and removed after.
      If the second argument is 1-dimensional, a 1 is appended to its
      dimension for the purpose of the batched matrix multiple and removed after.
      The non-matrix (exclude the last two dimensions) dimensions are
      broadcasted according the broadcast rule.
      For example, if input is a (j, 1, n, m) tensor and the other is a (k, m, p) tensor,
      out will be a (j, k, n, p) tensor.

    Args:
        x (Tensor): The input tensor which is a Tensor.
        y (Tensor): The input tensor which is a Tensor.
        transpose_x (bool, optional): Whether to transpose :math:`x` before multiplication. Default is False.
        transpose_y (bool, optional): Whether to transpose :math:`y` before multiplication. Default is False.
        name (str, optional): If set None, the layer will be named automatically. For more information, please refer to :ref:`api_guide_Name`. Default is None.

    Returns:
        Tensor: The output Tensor.

    Examples:

        .. code-block:: python

            >>> import paddle

            >>> # vector * vector
            >>> x = paddle.rand([10])
            >>> y = paddle.rand([10])
            >>> z = paddle.matmul(x, y)
            >>> print(z.shape)
            []

            >>> # matrix * vector
            >>> x = paddle.rand([10, 5])
            >>> y = paddle.rand([5])
            >>> z = paddle.matmul(x, y)
            >>> print(z.shape)
            [10]

            >>> # batched matrix * broadcasted vector
            >>> x = paddle.rand([10, 5, 2])
            >>> y = paddle.rand([2])
            >>> z = paddle.matmul(x, y)
            >>> print(z.shape)
            [10, 5]

            >>> # batched matrix * batched matrix
            >>> x = paddle.rand([10, 5, 2])
            >>> y = paddle.rand([10, 2, 5])
            >>> z = paddle.matmul(x, y)
            >>> print(z.shape)
            [10, 5, 5]

            >>> # batched matrix * broadcasted matrix
            >>> x = paddle.rand([10, 1, 5, 2])
            >>> y = paddle.rand([1, 3, 2, 5])
            >>> z = paddle.matmul(x, y)
            >>> print(z.shape)
            [10, 3, 5, 5]

    ©Útrans_xÚtrans_yc                 ó^   — | |dœ}|j                  «       D ]  \  }}t        ||g d¢d«       Œ y )N)r   Úy)Úint8r   r   r   r   r   r   Úmatmul)Úitemsr
   )r   rG   Ú	var_namesr8   Úvals        r>   Ú__check_inputzmatmul.<locals>.__check_inputö   s9   € Ø aÑ(ˆIØ&Ÿ_™_Ö.‘	��cÜ(ØØòð õñ /r?   Ú	matmul_v2©r6   ©r#   ÚYr%   r(   )rN   )r   r   rI   r   r4   r5   r6   r7   )	r   rG   Útranspose_xÚtranspose_yr8   r,   rM   r;   r<   s	            r>   rI   rI   ‘   s•   € ôz ÔÜ�}‰}˜Q  ;°Ó<Ð<ð #Ø"ñ
ˆò
	ñ$ 	�a˜ÔäÑ5¬F«HÑ5ˆØ×7Ñ7¸a¿g¹gÐ7ÓFˆØ×ÑØØ Ñ#Ø˜C�LØð	 	ô 	
ð ˆ
r?   c                 ó   ‡ — dd„}	 dd„}d|dddfˆ fd„	}d|ddfˆ fd„	}|€l|�jt        |t        «      r|dk(  r |‰ |||¬	«      S t        d
|› �«      ‚t        |t        t        f«      r |‰ |||d|¬«      S t        dt        |«      › �«      ‚t        |t        «      rt        |«      }t        |t        «      rt        |«      dk(  r|d   }t        |t        «      rct        |t        «      r!|dk(  r |‰ d||d|¬«      S t        d
|› �«      ‚t        |t        t        f«      r |‰ |||d|¬«      S t        d|› �«      ‚t        |t        «      rst        |«      dk(  re|dk(  r |‰ |||¬	«      S |t        j                  k(  s|t        j                   k(  r |‰ ||||¬«      S |dk(  rt        d|› �«      ‚ |‰ ||||¬«      S t        d|› �«      ‚)aæ  

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

    Note:
        This norm API is different from `numpy.linalg.norm`.
        This api supports high-order input tensors (rank >= 3), and certain axis need to be pointed out to calculate the norm.
        But `numpy.linalg.norm` only supports 1-D vector or 2-D matrix as input tensor.
        For p-order matrix norm, this api actually treats matrix as a flattened vector to calculate the vector norm, NOT REAL MATRIX NORM.

    Args:
        x (Tensor): The input tensor could be N-D tensor, and the input data
            type could be float32 or float64.
        p (float|string, optional): Order of the norm. Supported values are `fro`, `0`, `1`, `2`,
            `inf`, `-inf` and any positive real number yielding the corresponding p-norm. Not supported: ord < 0 and nuclear norm.
            Default value is `fro`.
        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`.
        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.
        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: 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,
            [17.43559647, 16.91153526, 16.73320007, 16.91153526])

            >>> # 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.]])
    NFc                 ó¦  — |�)t        |t        «      rt        |«      dk(  st        d«      ‚t	        «       r2|€t        j                  | g |d«      S t        j                  | ||d«      S ||ddœ}|€d|d<   t        | ddd	gd
«       t        di t        «       ¤Ž}|j                  |j                  «       ¬«      }|j                  d
d| id|i|¬«       |S )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.
          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!TF©r:   Úkeep_dimÚ
reduce_allrX   Úinputr   r   Úfrobenius_normrO   r#   r%   r(   )rZ   )r/   r-   r0   r2   r   r   rZ   r
   r   r4   r5   Úinput_dtyper7   )rY   r:   Úkeepdimr8   r,   r;   r<   s          r>   rZ   znorm.<locals>.frobenius_norms  sû   € ð ˆ?¤J¨s´DÔ$9¼cÀ#»hÈ!ºmÜØSóð ô "Ô#Øˆ{Ü×,Ñ,¨U°B¸ÀÓFÐFÜ×(Ñ(¨°°W¸eÓDÐDà¨WÀEÑJˆEØˆ{Ø&*��lÑ#Ü$Ø�w ¨IÐ 6Ð8Hôô !Ñ>´V³XÑ>ˆFØ×;Ñ;Ø×(Ñ(Ó*ð <ó ˆCð ×ÑØ%Ø˜U�|Ø ˜Øð	 ô ð ˆJr?   c                 óœ  — t        «       r|€d}t        j                  | ||d||«      S |�t        |dt        t
        fd«       |�t        |dt
        d«       t        | dg d¢d«       |�|nd|�t	        |«      nd||dd	œ}t        di t        «       ¤Ž}|j                  |j                  «       ¬
«      }|j                  dd| id|i|¬«       |S )a°  
        Calculate the p-order vector norm for certain  dimension of Tensor `input`.
        Args:
          input (Variable): Tensor, data type float32, float64.
          porder (float, optional): None for porder=2.0. Default None.
          axis (int, optional): None for last dimension. Default None.
          keepdim (bool, optional): Whether keep the dimensions as the `input`, Default False.
          asvector (bool, optional): Whether keep the result as a vector, 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`.
        éÿÿÿÿgê-�™—q=ÚporderÚp_normr'   rY   )r   r   r   r   ç       @)r'   r_   r\   ÚasvectorÚepsilonrO   r#   r%   r(   )r`   )r   r   r`   r	   ÚfloatÚintr
   r   r4   r5   r[   r7   )	rY   r_   r'   r\   rb   r8   r,   r;   r<   s	            r>   Úvector_normznorm.<locals>.vector_norm›  sù   € ô ÔØˆ|Ø�Ü—=‘= ¨°°e¸WÀhÓOÐOàÐ!Ü˜6 8¬e´S¨\¸8ÔDØÐÜ˜4 ¬#°Ô9Ü$ØØÚ;Øô	ð !%Ð 0™°bØ+1Ð+=œ% œ-À3Ø"Ø$Ø ñˆEô !Ñ6¬V«XÑ6ˆFØ×;Ñ;Ø×(Ñ(Ó*ð <ó ˆCð ×ÑØØ˜U�|Ø ˜Øð	 ô ð ˆJr?   c           	      ó8  •— t        «       r[t        j                  | «      }|t        j                  d«      k(  rt        j
                  |||«      S t        j                  |||«      S t        di t        «       ¤Ž}|j                  |j                  «       ¬«      }|j                  dd| id|i¬«       |j                  |j                  «       ¬«      }t        |‰«      \  }	}|t        j                  d«      k(  rdnd}
|j                  |
d|id|i|||	d	œ¬
«       |S )NÚinfrO   Úabsr#   r%   ©r)   r*   r+   Ú
reduce_maxÚ
reduce_minrV   r(   )Úinf_norm)r   r   ri   Únpr   ÚmaxÚminr   r4   r5   r[   r7   r   )rY   r_   r'   r\   rb   r8   r<   r;   Ú
reduce_outrX   Úreduce_typer   s              €r>   rm   znorm.<locals>.inf_normÍ  s2  ø€ ô ÔÜ—*‘*˜UÓ#ˆCØœŸ™ EÓ*Ò*Ü—z‘z # t¨WÓ5Ð5ä—z‘z # t¨WÓ5Ð5ä Ñ8¬v«xÑ8ˆFØ×;Ñ;Ø×(Ñ(Ó*ð <ó ˆCð ×ÑØ C¨ <¸%À¸ð ô ð  ×BÑBØ×(Ñ(Ó*ð Có ˆJô  0°°aÓ8ÑˆJ˜à &¬"¯*©*°UÓ*;Ò ;‘Àð ð ×ÑØ Ø˜S�zØ 
Ð+àØ 'Ø",ñð	 ô 	ð Ðr?   ç      ð?c           
      ó  •— t        «       rgt        j                  | «      }t        j                  ||«      }t        j                  ||d|«      }t        j                  |t        d|z  «      «      }|S t        di t        «       ¤Ž}	|	j                  |	j                  «       ¬«      }|	j                  |	j                  «       ¬«      }|	j                  dd| id|i¬«       |	j                  |	j                  «       ¬«      }|	j                  dd|id|id	|i¬
«       |	j                  |	j                  «       ¬«      }t        |‰«      \  }
}|	j                  dd|id|i|||
dœ¬
«       |	j                  dd|id|id	t        d|z  «      i¬
«       |S )z‘
        NOTE:
            This function actually treats the matrix as flattened vector to calculate vector norm instead of matrix norm.
        Nrs   rO   ri   r#   r%   rj   ÚpowÚfactorr(   Ú
reduce_sumrV   ©Únorm)r   r   ri   ru   Úsumrd   r   r4   r5   r[   r7   r   )rY   r_   r'   r\   r8   Úabs_outÚpow_outÚsum_outr<   ÚblockrX   r   s              €r>   Úp_matrix_normznorm.<locals>.p_matrix_normò  sÄ  ø€ ô
 ÔÜ—j‘j Ó'ˆGÜ—j‘j ¨&Ó1ˆGÜ—j‘j ¨$°°gÓ>ˆGÜ—*‘*˜W¤e¨C°&©LÓ&9Ó:ˆCØˆJäÑ/¤f£hÑ/ˆØ×6Ñ6Ø×#Ñ#Ó%ð 7ó 
ˆð ×:Ñ:Ø×#Ñ#Ó%ð ;ó 
ˆð 	�‰Ø  U˜|°e¸WÐ5Eð 	ô 	
ð ×:Ñ:Ø×#Ñ#Ó%ð ;ó 
ˆð 	�‰ØØ˜�>Ø˜GÐ$Ø˜VÐ$ð	 	ô 	
ð ×:Ñ:Ø×#Ñ#Ó%ð ;ó 
ˆô ,¨D°!Ó4Ñˆ
�DØ�‰ØØ˜�>Ø˜GÐ$àØ#Ø(ñð	 	ô 		
ð 	�‰ØØ˜�>Ø˜C�LØœU 3¨¡<Ó0Ð1ð	 	ô 	
ð ˆ
r?   Úfro)r:   r\   r8   z*only valid string values are 'fro', found T)r_   r'   r\   rb   r8   z,only valid p type is string or float, found r   r   r   )r'   r_   r\   rb   r8   z8unspport p for p-order vector norm. except float, found )r_   r'   r\   r8   zHjust support axis type int or list (length of list <=1) if p = 0, found z9except axis type int or list (length of list <=2), found ©NFN)NNFFN)r/   Ústrr2   re   rd   r)   r.   r-   r0   rn   rh   )	r   Úpr'   r\   r8   rZ   rf   rm   r   s	   `        r>   ry   ry     sE  ø€ ó|&ðR LPó0ðf  ¨u¸uÈ4õ#ðJ %(¨d¸EÈõ 4ðl €|˜˜Ü�aœÔØ�EŠzÙ% a¨T¸7ÈÔNÐNä Ø@ÀÀÐDóð ô ˜œC¤˜<Ô(ÙØØØØØØôð ô Ø>¼tÀA»w¸iÐHóð ô �$œÔÜ�D‹zˆÜ�$œÔ¤# d£)¨q¢.Ø�A‰wˆô �$œÔÜ�aœÔØ�EŠzÙ"ØØØØ#Ø"Øôð ô !Ø@ÀÀÐDóð ô ˜œC¤˜<Ô(ÙØØØØØØôð ô ØJÈ1È#ÐNóð ô 
�Dœ$Ô	¤C¨£I°¢NØ�Š:Ù! !¨°wÀTÔJÐJØ”"—&‘&Š[˜A¤"§&¡& šLÙ˜A a¨d¸GÈ$ÔOÐOØ�!ŠVÜØZÐ[_ÐZ`Ðaóð ñ !Ø˜! $°¸dôð ô ØGÈÀvÐNó
ð 	
r?   c                 ót  — t        «       rt        j                  | ||«      S t        | dg d¢d«       t        |dg d¢d«       t	        |dt
        t        fd«       t        di t        «       ¤Ž}|j                  | j                  «      }| g|gdœ}d|gi}dt        |«      i}|j                  d|d|i|¬«       |S )	a3  

    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, 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.)
    r6   )Úbfloat16r   r   r   Údistrƒ   rP   r%   r(   )r†   )r   r   r†   r
   r	   rd   re   r   r4   r5   r6   r7   )	r   rG   rƒ   r8   r;   r<   r*   r+   r,   s	            r>   r†   r†   u  sÈ   € ôx ÔÜ�{‰{˜1˜a Ó#Ð#äØ	ˆ7ÒAÀ6ôô Ø	ˆ7ÒAÀ6ôô ˆq�#œœs�| VÔ,ÜÑ,¤6£8Ñ,€FØ
×
3Ñ
3°A·G±GÓ
<€Cà�3˜a˜SÑ!€FØ�s�eˆn€GØ”%˜“(ˆO€EØ
×ÑØ˜F¨U°C¨LÀð ô ð €Jr?   c                 ó6  ‡ — dˆ fd„	}ddgfˆ fd„	}dgfˆ fd„	}d„ }t        ‰ j                  «      }t        |«      dk\  st        dd	t        |«      › �z   «      ‚|€d}d
|v rd
nd}|ddddt        j
                  t        j
                   fv rÞ|t        |«      dz
     |t        |«      dz
     k(  r¨|d
k(  r |‰ |dd «      S ‰ j                  «       }	|dk(  r |‰ «       ||	«      z  S |dk(  r |‰ |«       ||	|«      z  S |dv r |‰ |dg¬«       ||	|dg¬«      z  S |t        j
                  t        j
                   fv r+ |‰ |dg¬«       ||	|dg¬«      z  S t        d|› d�dz   «      ‚y|dv r|d
k(  r |‰ |dd «      S  |‰ |¬«      S t        d|› d�dz   «      ‚)ak  

    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           	      ó‚  •— t        «       r�t        j                  | «      }t        j                  ||dd«      }|dk(  s|t        j
                  k(  rt        j                  |dgd«      S |dk(  s|t        j
                   k(  rt        j                  |dgd«      S yt        di t        «       ¤Ž}|j                  |j                  «       ¬«      }|j                  |j                  «       ¬«      }|j                  |j                  «       ¬«      }|j                  dd| id|i¬	«       t        |‰«      \  }}|j                  d
d|id|i|d|dœ¬«       |dk(  s|t        j
                  k(  r|j                  dd|id|idgd|dœ¬«       |dk(  s|t        j
                   k(  r|j                  dd|id|idgd|dœ¬«       |S )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^   rO   ri   r#   r%   rj   rw   rV   r(   rk   rl   rx   )r   r   ri   rz   rn   rh   ro   rp   r   r4   r5   r[   r7   r   )	rY   r_   r'   r{   r}   r~   r<   rX   r   s	           €r>   Úmat_normzcond.<locals>.mat_normW  sö  ø€ ô "Ô#Ü—j‘j Ó'ˆGÜ—j‘j ¨$°°eÓ<ˆGà˜Š{˜f¬¯©Ò.Ü—z‘z '¨B¨4°Ó7Ð7Ø˜Š|˜v¬"¯&©&¨Ò0Ü—z‘z '¨B¨4°Ó7Ð7ð  1ô  Ñ3¬&«(Ñ3ˆEØ×>Ñ>Ø×'Ñ'Ó)ð ?ó ˆGð ×>Ñ>Ø×'Ñ'Ó)ð ?ó ˆGð ×:Ñ:Ø×'Ñ'Ó)ð ;ó ˆCð �O‰OØ C¨ <¸%ÀÐ9Ið ô ô  0°°aÓ8ÑˆJ˜Ø�O‰OØ!Ø˜W�~Ø Ð(àØ %Ø",ñð	 ô 	ð ˜Š{˜f¬¯©Ò.Ø—‘Ø%Ø ˜>Ø" C˜Là "˜tØ$)Ø&0ñð	  ô 	ð ˜Š|˜v¬"¯&©&¨Ò0Ø—‘Ø%Ø ˜>Ø" C˜Là "˜tØ$)Ø&0ñð	  ô 	ð ˆJr?   r   r^   c           
      ó(  •— t        «       rht        j                  | |«      }t        j                  ||dd«      }t        j                  ||dd«      }t        j                  |t	        d|z  «      «      S t        di t        «       ¤Ž}|j                  |j                  «       ¬«      }|j                  |j                  «       ¬«      }|j                  |j                  «       ¬«      }|j                  |j                  «       ¬«      }|j                  dd| id|id|i¬	«       t        |‰	«      \  }}|j                  d
d|id|i|d|dœ¬	«       |j                  d
d|id|i|d|dœ¬	«       |j                  dd|id|idt	        d|z  «      i¬	«       |S )zr
        NOTE:
            Calculate the frobenius norm of a square matrix or batches of square matrices.
        NFrs   rO   ru   r#   r%   rv   r(   rw   rV   rx   )r   r   ru   rz   rd   r   r4   r5   r[   r7   r   )
rY   r_   r'   r|   Ú	sum_out_1Ú	sum_out_2r~   r<   rX   r   s
            €r>   Úfro_normzcond.<locals>.fro_norm—  sÚ  ø€ ô
 "Ô#Ü—j‘j ¨Ó/ˆGÜŸ
™
 7¨D°$¸Ó>ˆIÜŸ
™
 9¨d°D¸%Ó@ˆIÜ—:‘:˜i¬¨s°V©|Ó)<Ó=Ð=äÑ3¬&«(Ñ3ˆEØ×>Ñ>Ø×'Ñ'Ó)ð ?ó ˆGð ×@Ñ@Ø×'Ñ'Ó)ð Aó ˆIð ×@Ñ@Ø×'Ñ'Ó)ð Aó ˆIð ×:Ñ:Ø×'Ñ'Ó)ð ;ó ˆCð �O‰OØØ˜U�|Ø Ð(Ø Ð(ð	 ô ô  0°°aÓ8ÑˆJ˜Ø�O‰OØ!Ø˜W�~Ø 	Ð*àØ %Ø",ñð	 ô 	ð �O‰OØ!Ø˜YÐ'Ø 	Ð*àØ %Ø",ñð	 ô 	ð �O‰OØØ˜YÐ'Ø ˜Ø¤ s¨V¡|Ó!4Ð5ð	 ô ð ˆJr?   c           	      ó�  •— t        | d¬«      \  }}}t        «       r‚|dk(  rt        j                  ||dd«      S t        j                  ||d«      }t        j
                  ||d«      }|dk(  rt        j                  ||«      S |dk(  rt        j                  ||«      S yt        |‰«      \  }}t        di t        «       ¤Ž}	|	j                  |	j                  «       ¬«      }
|dk(  r|	j                  dd	|id
|
i|d|dœ¬«       |
S |	j                  |	j                  «       ¬«      }|	j                  |	j                  «       ¬«      }|	j                  dd	|id
|i|d|dœ¬«       |	j                  dd	|id
|i|d|dœ¬«       |dk(  r|	j                  d||dœd
|
i|ddœ¬«       |
S |dk(  r|	j                  d||dœd
|
i|ddœ¬«       |
S y)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©Úfull_matricesÚnucNr   éþÿÿÿrO   rw   r#   r%   rV   r(   rk   rl   Úelementwise_divrP   )ÚaixsÚ
use_mkldnnrx   )Úsvdr   r   rz   ro   rp   Údivider   r   r4   r5   r[   r7   )rY   r_   r'   ÚuÚsÚvhÚmax_outÚmin_outrX   r~   r<   r   s              €r>   Úsvd_normzcond.<locals>.svd_normÓ  s8  ø€ ô �u¨EÔ2‰ˆˆ1ˆbä!Ô#Ø˜ŠÜ—z‘z ! T¨4°Ó7Ð7Ü—j‘j  D¨%Ó0ˆGÜ—j‘j  D¨%Ó0ˆGØ˜Š{Ü—}‘} W¨gÓ6Ð6Ø˜Š|Ü—}‘} W¨gÓ6Ð6ð ô  0°°aÓ8ÑˆJ˜ÜÑ3¬&«(Ñ3ˆEØ×:Ñ:Ø×'Ñ'Ó)ð ;ó ˆCð ˜ŠØ—‘Ø%Ø ˜8Ø" C˜Là#Ø$)Ø&0ñð	  ô 	ð �
Ø×>Ñ>Ø×'Ñ'Ó)ð ?ó ˆGð ×>Ñ>Ø×'Ñ'Ó)ð ?ó ˆGð �O‰OØ!Ø˜Q�xØ Ð(àØ %Ø",ñð	 ô 	ð �O‰OØ!Ø˜Q�xØ Ð(àØ %Ø",ñð	 ô 	ð ˜Š{Ø—‘Ø*Ø!(¨wÑ7Ø" C˜LØ#'°uÑ=ð	  ô ð �
Ø˜Š|Ø—‘Ø*Ø!(¨wÑ7Ø" C˜LØ#'°uÑ=ð	  ô ð �
ð r?   c                 óN   — t        «       r| j                  |«      S t        d«      ‚)Nz6only support x is nonempty tensor in static graph mode)r   Úreshaper2   )rY   r1   s     r>   Úempty_tensorzcond.<locals>.empty_tensor!  s'   € Ü!Ô#Ø—=‘= Ó'Ð'ÜØDó
ð 	
r?   z1input should be a matrix or batches of matrices, z'but the dimention of received input is r   r   r€   r‘   r’   ©r   r^   )r_   r'   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)rs   N)r-   r1   r0   r2   rn   rh   Úinverse)
r   rƒ   r8   r‰   r�   r�   r    r=   Úx_sizeÚx_invs
   `         r>   Úcondr¥   ç  s  ø€ õ`>ð@  !¨ tõ :ðx ') Tõ Lò\
ô �1—7‘7‹m€GÜˆw‹<˜1ÒÜØ?Ø7¼¸G»°~ÐFñGó
ð 	
ð 	€yØˆØ˜‘<‰Q a€FØˆU�E˜1˜b¤"§&¡&¬2¯6©6¨'Ð2Ñ2Ø”3�w“< !Ñ#Ñ$¨´°G³¸qÑ0@Ñ(AÒAØ˜Š{Ù# A w¨s° |Ó4Ð4Ø—I‘I“KˆEØ�EŠzÙ “{¡X¨e£_Ñ4Ð4Ø�EŠzÙ  1“~©°¸Ó(:Ñ:Ð:Ø�G‰|Ù ¨!°2°$Ô7¹(Ø !¨2¨$ô;ñ ð ð ”R—V‘VœbŸf™f˜WÐ%Ñ%Ù ¨!°2°$Ô7¹(Ø !¨2¨$ô;ñ ð ô Ø$ Q CÐ'8Ð9Ø?ñ@óð ð &ð 
ˆg‰Ø�QŠ;Ù  7¨3¨B <Ó0Ð0Ù˜ !Ô$Ð$äØ˜1˜#ÐDÐEØ0ñ1ó
ð 	
r?   c                 ó�  — t        «       rt        j                  | |«      S d}| €
J d|› �«       ‚|€
J d|› �«       ‚t        | dg d¢|«       t        |dg d¢|«       t	        |fi t        «       ¤Ž}|€|j                  | j                  ¬«      }n|j                  || j                  d¬	«      }|j                  d| |d
œi d|i¬«       |S )a¯  
    This operator calculates inner product for vectors.

    Note:
       Support 1-d and 2-d Tensor. When it is 2d, the first dimension of this matrix
       is the batch dimension, which means that the vectors of multiple batches are dotted.

    Parameters:
        x(Tensor): 1-D or 2-D ``Tensor``. Its dtype should be ``float32``, ``float64``, ``int32``, ``int64``, ``complex64``, ``complex128``
        y(Tensor): 1-D or 2-D ``Tensor``. Its dtype should be ``float32``, ``float64``, ``int32``, ``int64``, ``complex64``, ``complex128``
        name(str, 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 calculated result Tensor.

    Examples:

        .. code-block:: python

            >>> import paddle

            >>> # 1-D Tensor * 1-D Tensor
            >>> x = paddle.to_tensor([1, 2, 3])
            >>> y = paddle.to_tensor([4, 5, 6])
            >>> z = paddle.dot(x, y)
            >>> print(z)
            Tensor(shape=[], dtype=int64, place=Place(cpu), stop_gradient=True,
            32)

            >>> # 2-D Tensor * 2-D Tensor
            >>> x = paddle.to_tensor([[1, 2, 3], [2, 4, 6]])
            >>> y = paddle.to_tensor([[4, 5, 6], [4, 5, 6]])
            >>> z = paddle.dot(x, y)
            >>> print(z)
            Tensor(shape=[2], dtype=int64, place=Place(cpu), stop_gradient=True,
            [32, 64])

    Údotzx cannot be None in zy cannot be None in r   )r   r   r   r   r   r   r   r   rG   rO   F)r8   r6   ÚpersistablerP   r%   ©r)   r*   r,   r+   )
r   r   r§   r
   r   r4   r5   r6   Úcreate_variabler7   )r   rG   r8   Úop_typer;   r<   s         r>   r§   r§   R  sþ   € ôN ÔÜ�z‰z˜!˜QÓÐàˆàˆ}Ð>Ð 4°W°IÐ>Ó>ˆ}Øˆ}Ð>Ð 4°W°IÐ>Ó>ˆ}ä ØØò	ð ô	
ô 	!ØØò	ð ô	
ô  ˜WÑ1¬«Ñ1ˆØˆ<Ø×;Ñ;À!Ç'Á'Ð;ÓJ‰Cà×(Ñ(Ø §¡°eð )ó ˆCð 	×ÑØ Q¨QÑ/°rÀEÈ3À<ð 	ô 	
ð ˆ
r?   c                 óÄ  — d}t        | j                  «      dkD  st        | j                  «      dk  r!t        dt        | j                  «      z  «      ‚t        | dddgd«       | }t        | j                  «      dk(  r| j	                  d«      }|s"|j                  d	   dk7  r|j                  «       }d
}|j                  d   }	|��|j                  |j                  «      }t        |j                  «      dkD  r!t        dt        |j                  «      z  «      ‚|j                  d	   |	k7  r(t        dj                  |	|j                  d	   «      «      ‚|j                  «       d	k  rt        d|j                  «       › d�«      ‚t        j                  |t        j                  |j                  d«      «      k(  «      st        d«      ‚|�Ø|j                  |j                  «      }
t        |
j                  «      dkD  r!t        dt        |j                  «      z  «      ‚t        |dddgd«       |j                  d	   |	k7  r(t        dj                  |	|j                  d	   «      «      ‚|j                  «       d	k  rt        d|j                  «       › d�«      ‚|�||
z  }n|
}t        j                  |	|j                  ¬«      }|€|�.|j                  «       }|j                  «       d	k(  rt        d«      ‚|�||z  }|j                  d¬«      |z  }n|j                  d¬«      |z  }|}|�|�|r|||z  j                  «       |z  z
  }n||z
  }|d	k  r!t        j                  d	|j                  ¬«      }||j!                  d«      z
  }t        j"                  ||j                  «       j%                  «       «      }t        j&                  ||«      j)                  «       }|S )uv  
    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, 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   z]Input(x) only support N-D (1<=N<=2) tensor in cov, but received length of Input(input) is %s.r6   r   r   r¡   r   Nz`Input(fweights) only support N-D (N<=1) tensor in cov, but received shape of Input(input) is %s.ziThe number of Input(fweights) should equal to x's dim[1]: {}, but received size of Input(fweights) is {}.zWThe value of Input(fweights) cannot be negtive, but received min of Input(fweights) is r!   z Input(fweights) must be integer zaInput(aweights) only support N-D (N<=1) tensor in cov, but received length of Input(input) is %s.ziThe number of Input(aweights) should equal to x's dim[1]: {}, but received size of Input(aweights) is {}.zWThe value of Input(aweights) cannot be negtive, but received min of Input(aweights) is rO   z0The sum of weights is zero, can't be normalized.)r'   )r0   r1   r2   r
   rŸ   ÚtÚastyper6   Úformatrp   ÚpaddleÚallÚroundÚ	to_tensorrz   ÚitemÚ	unsqueezeÚmmÚconjr—   Úsqueeze)r   ÚrowvarÚddofÚfweightsÚaweightsr8   r«   ÚnxÚwÚobservation_numÚawÚw_sumÚnx_wÚavgÚnorm_factorÚxxtr­   s                    r>   r­   r­   ­  sª  € ðD €GÜ
ˆ1�7‰7ƒ|�aÒœ3˜qŸw™w›<¨!Ò+Üð,Ü.1°!·'±'«lñ;ó
ð 	
ô ˜Q ¨)°YÐ)?ÀÔGØ	
€BÜ
ˆ1�7‰7ƒ|�qÒØ�Y‰Y�wÓˆÙ�b—h‘h˜q‘k QÒ&Ø�T‰T‹VˆØ€AØ—h‘h˜q‘k€OØÑØ�O‰O˜BŸH™HÓ%ˆÜˆq�w‰w‹<˜!ÒÜð/Ü14°X·^±^Ó1DñEóð ð �>‰>˜!Ñ Ò/Üð1ß17±Ø# X§^¡^°AÑ%6ó2óð ð �<‰<‹>˜AÒÜð-Ø-5¯\©\«^Ð,<¸Að?óð ô �z‰z˜(¤f§l¡l°8·?±?À9Ó3MÓ&NÑNÔOÜÐ?Ó@Ð@àÐØ�_‰_˜RŸX™XÓ&ˆÜˆr�x‰x‹=˜1ÒÜð0Ü25°h·n±nÓ2EñFóð ô 	!Ø�g 	¨9Ð5°uô	
ð �>‰>˜!Ñ Ò/Üð1ß17±Ø# X§^¡^°AÑ%6ó2óð ð �<‰<‹>˜AÒÜð-Ø-5¯\©\«^Ð,<¸Að?óð ð ˆ=Ø�B‘‰AàˆAä×Ñ˜_°B·H±HÔ=€EØÐ˜xÐ3Ø—‘“ˆØ�:‰:‹<˜1ÒÜÐOÓPÐPà€}Ø�A‰vˆØ�j‰j˜aˆjÓ  5Ñ(‰à�f‰f˜!ˆf‹n˜uÑ$ˆØˆà€}˜Ð-±$Ø˜q 8™|×0Ñ0Ó2°UÑ:Ñ:‰à˜d‘lˆØ�aÒÜ×&Ñ& q°·±Ô9ˆØ	ˆc�m‰m˜AÓÑ	€BÜ
�)‰)�B˜Ÿ™›Ÿ™›Ó
(€CÜ
�-‰-˜˜[Ó
)×
1Ñ
1Ó
3€CØ€Jr?   c                 ó$  — t        | j                  «      dkD  r!t        dt        | j                  «      z  «      ‚t        «       r6t        | j                  «      dk  r| S ddg}t	        j
                  | |«      }|S t        | dg d¢d«       t        di t        «       ¤Ž}|j                  | j                  «      }|j                  | j                  «      }t        | j                  «      dk  r| }|S |j                  dd	| gi|g|gd
œdddgi¬«       |S )aG  
    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, 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:: python
            :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)
            [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)
            [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)
            [3, 2]

    r   úŽInput(input) only support N-D (N<=2) tensor, but received length of Input(input) is %s. Perhaps you can use paddle.tensor.transpose() instead.r   r   rY   )r   r   r   r   r   r   r"   r#   r$   r'   r(   )r®   )r0   r1   r2   r   r   r   r
   r   r4   r5   r6   r7   )rY   r8   r    r<   r;   Úinput_shapes         r>   r®   r®   '  s!  € ôh ˆ5�;‰;Ó˜!ÒÜð*ä,/°·±Ó,<ñ=ó
ð 	
ô
 ÔÜˆu�{‰{Ó˜qÒ ØˆLà�1ˆvˆÜ×Ñ˜u dÓ+ˆØˆ
ä ØØÚ?Øô		
ô Ñ-¤F£HÑ-ˆØ×7Ñ7¸¿¹ÓDˆØ×?Ñ?ÀÇÁÓLˆÜˆu�{‰{Ó˜qÒ ØˆCð ˆ
ð ×ÑØ!Ø˜e˜W�~Ø!$ °+°Ñ?Ø  1˜vÐ&ð	 ô ð ˆ
r?   c                 óö   — t        | j                  «      dkD  r!t        dt        | j                  «      z  «      ‚t        «       r6t        | j                  «      dk  r| S ddg}t	        j
                  | |«      }|S y)z‰
    Inplace version of ``t`` API, the output Tensor will be inplaced with input ``input``.
    Please refer to :ref:`api_paddle_t`.
    r   rÈ   r   r   N)r0   r1   r2   r   r   rA   )rY   r8   r    r<   s       r>   Út_rË     s{   € ô ˆ5�;‰;Ó˜!ÒÜð*ä,/°·±Ó,<ñ=ó
ð 	
ô
 ÔÜˆu�{‰{Ó˜qÒ ØˆLà�1ˆvˆÜ×Ñ  tÓ,ˆØˆ
ð r?   c                 ó:  — t        «       r!|€t        n|}t        j                  | ||«      S t	        | dg d¢d«       t	        |dg d¢d«       t        d	i t        «       ¤Ž}|j                  | j                  «      }i }||d<   |j                  d| |dœd|i|¬«       |S )
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.
        y (Tensor): The second input tensor, the data type is float16, float32, float64, int32, int64.
        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, 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   r   r   r   r   r   ÚcrossrG   r:   rP   r%   r(   )rÍ   )
r   ÚK_DEFAULT_DIMr   rÍ   r
   r   r4   r5   r6   r7   )r   rG   r'   r8   r;   r<   r,   s          r>   rÍ   rÍ   ”  sµ   € ôT ÔØ $ �}°$ˆÜ�|‰|˜A˜q $Ó'Ð'ä ØØÚIØô		
ô 	!ØØÚIØô		
ô Ñ1¬«Ñ1ˆØ×7Ñ7¸¿¹Ó@ˆØˆØˆˆe‰à×ÑØØ Ñ#Ø˜C�LØð	 	ô 	
ð ˆ
r?   c                 ó   — t        «       rt        j                  | |«      S t        | dddgd«       t	        |dt
        d«       t        d
i t        «       ¤Ž}|j                  | j                  ¬«      }|j                  dd| gid|id|i¬	«       |S )aÍ  
    Computes the Cholesky decomposition of one symmetric positive-definite
    matrix or batches of symmetric positive-definite matrice.

    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, 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]])
    r6   r   r   ÚcholeskyÚupperrO   r#   r%   r(   )rÐ   )r   r   rÐ   r
   r	   r   r   r4   r5   r6   r7   )r   rÑ   r8   r;   r<   s        r>   rÐ   rÐ   Ü  s˜   € ôR ÔÜ�‰˜q %Ó(Ð(ä   G¨i¸Ð-CÀZÔPÜ�5˜'¤4¨Ô4ÜÑ4¬6«8Ñ4ˆØ×7Ñ7¸a¿g¹gÐ7ÓFˆØ×ÑØØ˜!˜�:Ø˜C�LØ˜EÐ"ð	 	ô 	
ð ˆ
r?   c                 ó  — t        «       r¢t        |t        t        j                  j
                  f«      rL|j                  | j                  k7  rt        || j                  «      }n|}d}t        j                  | |||«      S |€d}d}nt        |«      }d}t        j                  | |||«      S i }i }t        | dddgd«       | |d<   |€d|d	<   njt        |t        «      r>d|d	<   |j                  | j                  k7  rt        || j                  «      |d
<   n"||d
<   nt        |dt        d«       d|d	<   ||d<   t        |dt        d«       ||d<   t        di t!        «       ¤Ž}	|	j#                  d¬«      }
|	j%                  d|d|
i|¬«       |
S )aG  
    Computes the rank of a matrix.

    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.

    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 or float64.
        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.
        name (str, 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:: python

            >>> import paddle

            >>> a = paddle.eye(10)
            >>> b = paddle.linalg.matrix_rank(a)
            >>> print(b)
            Tensor(shape=[], dtype=int32, 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=int32, place=Place(cpu), stop_gradient=True,
            [[1, 1, 1, 1],
             [1, 1, 1, 1],
             [1, 1, 1, 1]])

    Fç        Tr   r   r   Úmatrix_rankr#   Úuse_default_tolÚ	TolTensorÚtolÚ	hermitianr   rO   r%   r(   )rÔ   )r   r/   r   r±   ÚpirÚOpResultr6   r   r   Úmatrix_rank_tolrd   rÔ   r
   r	   r   r   r4   r5   r7   )r   r×   rØ   r8   Ú
tol_tensorrÕ   Útol_attrr*   r,   r;   r<   s              r>   rÔ   rÔ     s�  € ôR ÔÜ�cœH¤f§j¡j×&9Ñ&9Ð:Ô;Ø�y‰y˜AŸG™GÒ#Ü! # q§w¡wÓ/‘
à �
Ø#ˆOÜ×)Ñ)Ø�:˜°	óð ð ˆ;ØˆHØ"‰Oä˜S“zˆHØ#ˆOÜ×!Ñ! ! X¨À	ÓJÐJàˆØˆÜ   C¨)°YÐ)?ÀÔOØˆˆs‰Øˆ;Ø'+ˆEÐ#Ò$Ü˜œXÔ&Ø',ˆEÐ#Ñ$Ø�y‰y˜AŸG™GÒ#Ü&*¨3°·±Ó&8��{Ò#à&)��{Ò#ä�s˜E¤5¨-Ô8Ø',ˆEÐ#Ñ$ØˆE�%‰LÜ�9˜k¬4°Ô?Ø&ˆˆkÑäÑ7¬f«hÑ7ˆØ×7Ñ7¸gÐ7ÓFˆØ×ÑØ v¸¸s°|È5ð 	ô 	
ð ˆ
r?   c                 óR  — t        «       rt        j                  | |«      S | j                  }|j                  }t	        |«      t	        |«      cxk(  rdk(  sn t        dj                  ||«      «      ‚|d   dk7  r.|d   dk7  r&|d   |d   k7  rt        dj                  ||«      «      ‚|d   dk7  r.|d   dk7  r&|d   |d   k7  rt        dj                  ||«      «      ‚t        di t        «       ¤Ž}|j                  | j                  ¬
«      }|j                  d	| |dœd|i¬«       |S )a,  
    Applies batched matrix multiplication to two tensors.

    Both of the two input tensors must be three-dementional and share the same batch size.

    If x is a (b, m, k) tensor, y is a (b, k, n) tensor, the output will be a (b, m, n) tensor.

    Args:
        x (Tensor): The input Tensor.
        y (Tensor): The input Tensor.
        name (str|None): A name for this layer(optional). If set None, the layer
            will be named automatically. Default: None.

    Returns:
        Tensor: The product Tensor.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> # In imperative mode:
            >>> # size x: (2, 2, 3) and y: (2, 3, 2)
            >>> x = paddle.to_tensor([[[1.0, 1.0, 1.0],
            ...                     [2.0, 2.0, 2.0]],
            ...                     [[3.0, 3.0, 3.0],
            ...                     [4.0, 4.0, 4.0]]])
            >>> y = paddle.to_tensor([[[1.0, 1.0],[2.0, 2.0],[3.0, 3.0]],
            ...                     [[4.0, 4.0],[5.0, 5.0],[6.0, 6.0]]])
            >>> out = paddle.bmm(x, y)
            >>> print(out)
            Tensor(shape=[2, 2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
            [[[6. , 6. ],
              [12., 12.]],
             [[45., 45.],
              [60., 60.]]])

    é   zRx and y should be 3-dimensional. But received x's dimention: {}, y's dimention: {}r   r^   r   zRx's width must be equal with y's height. But received x's shape: {}, y's shape: {}r   zgx's batch (shape[0]) must be equal with y's batch (shape[0]). But received x's shape: {}, y's shape: {}ÚbmmrO   rP   r%   rj   )rà   )r   r   rà   r1   r0   r2   r°   r   r4   r5   r6   r7   )r   rG   r8   r=   Úy_shaper;   r<   s          r>   rà   rà   l  sK  € ôN ÔÜ�z‰z˜!˜QÓÐà—'‘'ˆØ—'‘'ˆÜ�7‹|œs 7›|Ô0¨qÔ0ÜØd×kÑkØ˜Wóóð ð
 �1‰:˜Ò ¨¡
¨bÒ 0°W¸Q±ZÀ7È1Á:Ò5MÜØd×kÑkØ˜Wóóð ð
 �1‰:˜Ò ¨¡
¨bÒ 0°W¸Q±ZÀ7È1Á:Ò5MÜØy÷  Añ  AØ˜Wóóð ô
 Ñ/¤f£hÑ/ˆØ×7Ñ7¸a¿g¹gÐ7ÓFˆØ×ÑØ Q¨QÑ/¸%À¸ð 	ô 	
ð ˆ
r?   c           	      ó  — t        «       rt        j                  | |||«      S t        di t	        «       ¤Ž}t        | dg d¢d«       |j                  t        j                  j                  «      }|j                  dd| id|i|||dœ¬«       |S )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(or LoDTensor) 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 (int, optional): lower end of the range (inclusive). Default: 0.
        max (int, optional): upper end of the range (inclusive). Default: 0.
        name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.

    Returns:
        Tensor: data type is int64, shape is (nbins,).

    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#   ©r   r   r   r   r%   )Úbinsrp   ro   r(   )rã   )r   r   rã   r   r4   r
   r5   r   ÚVarTypeÚINT64r7   )rY   rå   rp   ro   r8   r;   r<   s          r>   rã   rã   ²  s“   € ô6 ÔÜ×Ñ  t¨S°#Ó6Ð6äÑ5¬F«HÑ5ˆÜ Ø�3Ò@À+ô	
ð ×7Ñ7¼¿¹×8MÑ8MÓNˆØ×ÑØØ˜�<Ø˜C�LØ¨°CÑ8ð	 	ô 	
ð ˆ
r?   c                 ó  — | j                   t        j                  t        j                  t        j
                  t        j                  fvrt        d«      ‚t        «       rt        j                  | ||«      S t        di t        «       ¤Ž}t        | dddgd«       |�-t        |dg d¢d«       |j                  |j                   ¬«      }n|j                  | j                   ¬«      }|j                  d| |d	œd
|id|i¬«       |S )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, 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#   r   r   ÚWeightsrä   rO   )r#   rê   r%   Ú	minlengthr(   )ré   )r6   r±   r   r   r   ÚINT32rç   Ú	TypeErrorr   r   ré   r   r4   r
   r5   r7   )r   Úweightsrë   r8   r;   r<   s         r>   ré   ré   Þ  sø   € ð> 	‡w�wÜ�‰Ü�‰Ü�‰Ü�‰ð	ñ ô ÐEÓFÐFäÔÜ�‰˜q '¨9Ó5Ð5äÑ4¬6«8Ñ4ˆä   C¨'°7Ð);¸ZÔHàÐÜ$ØØÚ8Øô	ð ×;Ñ;À'Ç-Á-Ð;ÓP‰Cà×;Ñ;À!Ç'Á'Ð;ÓJˆCØ×ÑØØ wÑ/Ø˜C�LØ 	Ð*ð	 	ô 	
ð ˆ
r?   c                 óî   — t        «       rt        j                  | |«      S d„ } || |«       t        di t	        «       ¤Ž}|j                  | j                  ¬«      }|j                  d| |dœd|i¬«       |S )aQ  
    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, 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 producted 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                 ó:  — | |dœ}|j                  «       D ]  \  }}t        ||ddgd«       Œ t        | j                  «      }t        |j                  «      }t	        |«      dk7  rt        d|› �«      ‚t	        |«      dk7  rt        dj                  |«      «      ‚y )	N)r   Úvecr   r   Úmvr   z7x should be 2-dimensional. But received x's dimention: r   z=vec should be 1-dimensional. But received vec's dimention: {})rJ   r
   r-   r1   r0   r2   r°   )r   rñ   rK   r8   rL   r=   Ú	vec_shapes          r>   rM   zmv.<locals>.__check_inputA  s§   € Ø¨Ñ,ˆIØ&Ÿ_™_Ö.‘	��cÜ(Ø˜ 	¨9Ð5°tõð /ô ˜1Ÿ7™7“mˆGÜ˜SŸY™Y›ˆIÜ�7‹|˜qÒ Ü ØMÈgÈYÐWóð ô �9‹~ Ò"Ü ØS×ZÑZØ!óóð ð #r?   rò   rO   )r#   ÚVecr%   rj   )rò   )r   r   rò   r   r4   r5   r6   r7   )r   rñ   r8   rM   r;   r<   s         r>   rò   rò     s|   € ô< ÔÜ�y‰y˜˜CÓ Ð ò	ñ& 	�a˜ÔäÑ.¤V£XÑ.ˆØ×7Ñ7¸a¿g¹gÐ7ÓFˆØ×ÑØ A¨cÑ2¸UÀC¸Lð 	ô 	
ð ˆ
r?   c                 óÆ  — t        «       rt        j                  | «      S t        | j                  dg d¢d«       t        | j                  «      }t        |«      dk\  sJ dt        |«      z  «       ‚|d   |d   k(  sJ dj                  |d   |d   «      «       ‚t        di t        «       ¤Ž}|j                  | j                  ¬
«      }|j                  d	d| gid|gi¬«       |S )ar  

    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, 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   Údetr   úNThe x must be at least 2-dimensional, but received Input x's dimensional: %s.
r^   r’   ú3Expect squared input,but received {} by {} matrix.
ÚdeterminantrO   r%   rj   )rú   )r   r   r÷   r   r6   r-   r1   r0   r°   r   r4   r5   r7   ©r   r8   rÉ   r;   r<   s        r>   r÷   r÷   ^  sõ   € ô8 ÔÜ�z‰z˜!‹}Ðä�A—G‘G˜WÒ&GÈÔOä˜1Ÿ7™7“mˆÜ�;Ó 1Ò$ð 	
ð8Ü:=¸kÓ:JñKó	
Ð$ð ˜‰O˜{¨2™Ò.ð	
àD×KÑKØ˜‰OØ˜‰Oó
ó	
Ø.ô
 Ñ7¬f«hÑ7ˆØ×7Ñ7¸a¿g¹gÐ7ÓFˆà×ÑØ¨°!° ~ÀÈÀu¸~ð 	ô 	
ð ˆ
r?   c                 óÆ  — t        «       rt        j                  | «      S t        | j                  dddgd«       t        | j                  «      }t        |«      dk\  sJ dt        |«      z  «       ‚|d   |d   k(  sJ d	j                  |d   |d   «      «       ‚t        di t        «       ¤Ž}|j                  | j                  ¬«      }|j                  d
d| gid|gi¬«       |S )a»  

    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.

    Note that for matrices that have zero determinant, this returns ``(0, -inf)``.

    Args:
        x (Tensor): the batch of matrices of size :math:`(*, n, n)`
            where math:`*` is one or more batch dimensions.
        name (str, 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.

    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   r   Úslogdetr   rø   r^   r’   rù   ÚslogdeterminantrO   r%   rj   )rþ   )r   r   rý   r   r6   r-   r1   r0   r°   r   r4   r5   r7   rû   s        r>   rý   rý   ”  sý   € ôB ÔÜ�~‰~˜aÓ Ð ä�A—G‘G˜W y°)Ð&<¸iÔHä˜1Ÿ7™7“mˆÜ�;Ó 1Ò$ð 	
ð8Ü:=¸kÓ:JñKó	
Ð$ð ˜‰O˜{¨2™Ò.ð	
àD×KÑKØ˜‰OØ˜‰Oó
ó	
Ø.ô
 Ñ;´&³(Ñ;ˆØ×7Ñ7¸a¿g¹gÐ7ÓFˆà×ÑØ"Ø˜a˜S�>Ø˜S˜E�Nð 	ô 	
ð
 ˆ
r?   c                 ó¤  — t        «       rt        j                  | |«      S t        | dddgd«       t	        |dt
        d«       t        d
i t        «       ¤Ž}|j                  | j                  ¬«      }|j                  | j                  ¬«      }|j                  | j                  ¬«      }i }||d<   |j                  dd| gi|||dœ|¬	«       |||fS )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) * VT

    Args:
        x (Tensor): The input tensor. Its shape should be `[..., N, M]`,
            where `...` is zero or more batch dimensions. N and M can be arbitraty
            positive number. Note that if x is sigular matrices, the grad is numerical
            instable. The data type of x should be float32 or float64.
        full_matrices (bool, optional): A flag to control the behavor of svd.
            If full_matrices = True, svd op will compute full U and V matrics,
            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, 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 singlar value vectors of matrics 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
    r6   r   r   r–   r�   rO   r#   ©ÚUÚVHÚSr(   )r–   )r   r   r–   r
   r	   r   r   r4   r5   r6   r7   )r   r�   r8   r;   r˜   rš   r™   r,   s           r>   r–   r–   Ñ  sÙ   € ôt ÔÜ�z‰z˜!˜]Ó+Ð+ä   G¨i¸Ð-CÀUÔKÜ�= /´4¸Ô?ÜÑ/¤f£hÑ/ˆØ×5Ñ5¸A¿G¹GÐ5ÓDˆØ×6Ñ6¸Q¿W¹WÐ6ÓEˆØ×5Ñ5¸A¿G¹GÐ5ÓDˆØˆØ!.ˆˆoÑØ×ÑØØ˜!˜�:Ø 2¨AÑ.Øð	 	ô 	
ð �!�Rˆxˆr?   c           	      óÆ  ‡	‡
‡‡— d„ Š	d„ Šˆ	ˆfd„Šdˆ	ˆˆfd„	Š
dˆ	ˆ
ˆˆfd„	}t        j                  | «      st        dt        | «      › �«      ‚| j                  d	d \  }}|€t        d||«      }n/|d
k\  r|t        ||«      k  st        d|› dt        ||«      › �«      ‚|d
k\  st        d|› d�«      ‚|s || ||d¬«      S | j                  d	d¬«      } || |z
  ||d¬«      S )aN
  
    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 arbitraty
            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, 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]])
    c                 óF   — | j                  «       r| j                  «       S | S ©N)Ú
is_complexr¸   )r   s    r>   Ú	conjugatezpca_lowrank.<locals>.conjugateX  s   € Ø�<‰<Œ>Ø—6‘6“8ˆOØˆr?   c                 ó¨   — | j                   }t        t        dt        |«      «      «      }|d d |d   gz   |d   gz   }t	        j
                  | |«      S )Nr   r’   r^   )r1   r-   Úranger0   r±   r   )r   r1   r    s      r>   r   zpca_lowrank.<locals>.transpose]  sT   € Ø—‘ˆÜ”E˜!œS ›ZÓ(Ó)ˆØ�C�Rˆy˜D ™H˜:Ñ%¨¨b©¨
Ñ2ˆÜ×Ñ  4Ó(Ð(r?   c                 ó    •—  ‰ ‰| «      «      S r  © )r   r  r   s    €€r>   Útransjugatez pca_lowrank.<locals>.transjugatec  s   ø€ Ù™ 1›Ó&Ð&r?   Nc                 ó(  •— |€dn|}| j                   dd  \  }}t        j                  j                  }t        j                  ||f| j
                  ¬«      } ‰| «      } ‰|«      }	|€o |t        j                  | |«      «      d   }
t        |«      D ]@  } |t        j                  |	|
«      «      d   }
 |t        j                  | |
«      «      d   }
ŒB |
S  ‰|«      } |t        j                  | |«      t        j                  ||«      z
  «      d   }
t        |«      D ]n  } |t        j                  |	|
«      t        j                  ||
«      z
  «      d   }
 |t        j                  | |
«      t        j                  ||
«      z
  «      d   }
Œp |
S )Nr   r’   rO   r   )r1   r±   ÚlinalgÚqrÚrandnr6   rI   r
  )r   ÚqÚniterÚMÚmÚnr  ÚRÚA_tÚA_HÚQÚiÚM_Hr  r  r   s                €€€r>   Úget_approximate_basisz*pca_lowrank.<locals>.get_approximate_basisf  s`  ø€ Ø�]‘¨ˆØ�w‰w�r�sˆ|‰ˆˆ1Ü�]‰]×Ñˆä�L‰L˜!˜Q˜ q§w¡wÔ/ˆá˜‹lˆÙ˜‹nˆØˆ9Ù”6—=‘=  AÓ&Ó'¨Ñ*ˆAÜ˜5–\�Ù”v—}‘} S¨!Ó,Ó-¨aÑ0�Ù”v—}‘} Q¨Ó*Ó+¨AÑ.‘ð "ð ˆñ ˜a“.ˆCÙ”6—=‘=  AÓ&¬¯©°q¸!Ó)<Ñ<Ó=¸aÑ@ˆAÜ˜5–\�Ù”v—}‘} S¨!Ó,¬v¯}©}¸SÀ!Ó/DÑDÓEÀaÑH�Ù”v—}‘} Q¨Ó*¬V¯]©]¸1¸aÓ-@Ñ@ÓAÀ!ÑD‘ð "ð ˆr?   é   c                 óÚ  •— |€dn|}| j                   dd  \  }}|€d }n ‰|«      } ‰| «      }||k  s||kD  �r ‰||||¬«      } ‰|«      }	|€t        j                  | |	«      }
n-t        j                  | |	«      t        j                  ||	«      z
  }
|
j                   d   |k(  sJ |
j                   |f«       ‚|
j                   d   |k(  sJ |
j                   |f«       ‚|
j                   d   |
j                   d   k  sJ |
j                   «       ‚t        j                  j	                  |
d¬«      \  }}} ‰|«      }|j                  |«      }�n ‰| |||¬«      } ‰|«      }	|€t        j                  ||	«      }n-t        j                  ||	«      t        j                  ||	«      z
  } ‰|«      }
|
j                   d   |k(  sJ |
j                   |f«       ‚|
j                   d   |k(  sJ |
j                   |f«       ‚|
j                   d   |
j                   d   k  sJ |
j                   «       ‚t        j                  j	                  |
d¬«      \  }}} ‰|«      }|j                  |«      }|||fS )Nr  r’   ©r  r  r^   Fr�   )r1   r±   rI   r  r–   )r   r  r  r  r  r  ÚM_tr  r  ÚQ_cÚB_tr  r  ÚVhÚVÚBr  r  r  r   s                   €€€€r>   Úsvd_lowrankz pca_lowrank.<locals>.svd_lowrank}  s>  ø€ Ø�‰A ˆØ�w‰w�r�sˆ|‰ˆˆ1Øˆ9Ø‰Cá˜A“,ˆCÙ˜‹lˆàˆqŠ5�A˜“EÙ% c¨1°E¸SÔAˆAÙ˜A“,ˆCØˆyÜ—m‘m A sÓ+‘ä—m‘m A sÓ+¬f¯m©m¸A¸sÓ.CÑC�Ø—9‘9˜R‘= AÒ%Ð5¨¯	©	°1 ~Ó5Ð%Ø—9‘9˜R‘= AÒ%Ð5¨¯	©	°1 ~Ó5Ð%Ø—9‘9˜R‘= C§I¡I¨b¡MÒ1Ð<°3·9±9Ó<Ð1Ü—}‘}×(Ñ(¨¸EÐ(ÓB‰HˆAˆq�"Ù˜B“ˆAØ—‘˜“ŠAá% a¨°%¸1Ô=ˆAÙ˜A“,ˆCØˆyÜ—M‘M # sÓ+‘ä—M‘M # sÓ+¬f¯m©m¸CÀÓ.EÑE�Ù˜A“,ˆCØ—9‘9˜R‘= AÒ%Ð5¨¯	©	°1 ~Ó5Ð%Ø—9‘9˜R‘= AÒ%Ð5¨¯	©	°1 ~Ó5Ð%Ø—9‘9˜R‘= C§I¡I¨b¡MÒ1Ð<°3·9±9Ó<Ð1Ü—}‘}×(Ñ(¨¸EÐ(ÓB‰HˆAˆq�"Ù˜B“ˆAØ—‘˜“ˆAà�!�Qˆwˆr?   zInput must be tensor, but got r’   r   zq(=z>) must be non-negative integer and not greater than min(m, n)=zniter(=z) must be non-negative integerr   T©r'   r\   ©r   N)r  r   N)r±   Ú	is_tensorr2   r)   r1   rp   Úmean)r   r  Úcenterr  r8   r'  r  r  ÚCr  r  r  r   s            @@@@r>   Úpca_lowrankr.    s  û€ òrò
)õ'÷÷.%ð %ôN ×Ñ˜AÔÜÐ9¼$¸q»'¸ÐCÓDÐDà�W‰W�R�Sˆ\�F€Qˆà€yÜ��1�a‹L‰Ø�1Šf˜œc ! Q›išÜØ�!�ð /Ü/2°1°a«y¨kð;ó
ð 	
ð �QŠJÜ˜7 5 'Ð)GÐHÓIÐIáÙ˜1˜a u°Ô5Ð5à	�‰�B ˆÓ%€AÙ�q˜1‘u˜a u°Ô5Ð5r?   c                 ó  — t        «       rt        j                  | |«      S t        | dddgd«       t	        |dt
        d«       t        d
i t        «       ¤Ž}|j                  | j                  ¬«      }|j                  dd| id|id|i¬	«       |S )a   

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

    Let :math:`X` be a sqaure 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, 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 ]])
    r6   r   r   Úmatrix_powerr  rO   r#   r%   r(   )r0  )r   r   r0  r
   r	   re   r   r4   r5   r6   r7   )r   r  r8   r;   r<   s        r>   r0  r0  º  sœ   € ôr ÔÜ×"Ñ" 1 aÓ(Ð(ä Øˆw˜ IÐ.°ô	
ô 	�1�cœ3 Ô/ÜÑ8¬v«xÑ8ˆØ×7Ñ7¸a¿g¹gÐ7ÓFˆØ×ÑØØ˜�8Ø˜C�LØ˜�(ð	 	ô 	
ð ˆ
r?   c                 ó’  — t        «       r$t        j                  | |«      \  }}|dk(  r|S ||fS t        | dddgd«       t	        |dt
        d«       t        di t        «       ¤Ž}|j                  | j                  ¬«      }|j                  | j                  ¬«      }i }||d<   |j                  dd| gi||d	œ|¬
«       |dk(  r|S ||fS )aÌ  
    Computes the QR decomposition of one matrix or batches of matrice (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 should be float32 or float64.
        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, 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 ;
    Úrr6   r   r   r  ÚmoderO   r#   )r  r  r(   )r  )r   r   r  r
   r	   r‚   r   r4   r5   r6   r7   )r   r3  r8   r  r2  r;   r,   s          r>   r  r  	  sÞ   € ôT ÔÜ�y‰y˜˜DÓ!‰ˆˆ1Ø�3Š;ØˆHà�a�4ˆKä   G¨i¸Ð-CÀTÔJÜ�4˜¤ dÔ+ÜÑ.¤V£XÑ.ˆØ×5Ñ5¸A¿G¹GÐ5ÓDˆØ×5Ñ5¸A¿G¹GÐ5ÓDˆØˆØˆˆf‰Ø×ÑØ˜s Q C˜j¸ÀÑ2BÈ%ð 	ô 	
ð �3Š;ØˆHà�a�4ˆKr?   c                 ól  — t        «       rt        j                  | |«      \  }}}n…t        | dddgd«       t	        di t        «       ¤Ž}|j                  | j                  ¬«      }|j                  d¬«      }|j                  d¬«      }i }||d<   |j                  dd| i|||d	œ|¬
«       |r|||fS ||fS )u4  
    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).

        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, 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=[1], 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 ;
    r6   r   r   ÚlurO   re   Úpivotr#   )r%   ÚPivotsÚInfosr(   )r5  )	r   r   r5  r
   r   r4   r5   r6   r7   )	r   r6  Ú	get_infosr8   r5  rƒ   Úinfor;   r,   s	            r>   r5  r5  F	  sÒ   € ô` ÔÜ—i‘i  5Ó)‰ˆˆA‰tä   G¨i¸Ð-CÀTÔJÜÑ.¤V£XÑ.ˆØ×6Ñ6¸Q¿W¹WÐ6ÓEˆØ×5Ñ5¸EÐ5ÓBˆØ×8Ñ8¸uÐ8ÓEˆØˆØˆˆg‰Ø×ÑØØ˜�8Ø¨!°dÑ;Øð	 	ô 	
ñ Ø�1�dˆ{Ðà�1ˆuˆr?   c                 ó@  — | j                   dk  rt        d| j                   › d�«      ‚|j                   dk  rt        d|j                   › d�«      ‚t        «       r!t        j                  | |||«      \  }}}|||fS t        | ddd	gd
«       t        di t        «       ¤Ž}|j                  | j                  ¬«      }	|j                  | j                  ¬«      }
|j                  | j                  ¬«      }i }||d<   ||d<   |j                  d
| |dœ|	|
|dœ|¬«       |	|
|fS )a½	  
    Unpack L U and P to single matrix tensor .
    unpack L and U matrix from LU, unpack permutation matrix P from Pivtos .

    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.

        y (Tensor): Pivots get from paddle.linalg.lu.

        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 Pivtos. Default: True.

        name (str, 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=[1], 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]r6   r   r   Ú	lu_unpackrO   Úunpack_ludataÚunpack_pivots)r#   r7  )ÚPmatÚLr  r(   )r>  )Úndimr2   r   r   r>  r
   r   r4   r5   r6   r7   )r   rG   r?  r@  r8   ÚPrB  r  r;   rƒ   Úlr˜   r,   s                r>   r>  r>  ¬	  sE  € ðR 	‡v�v�‚zÜØHÈÏÉÈÐPUÐVó
ð 	
ð 	‡v�v�‚zÜØJÈ1Ï6É6È(ÐRWÐXó
ð 	
ô ÔÜ×"Ñ" 1 a¨¸ÓF‰ˆˆ1ˆaØ�!�Qˆwˆä Øˆw˜ IÐ.°ô	
ô Ñ5¬F«HÑ5ˆØ×5Ñ5¸A¿G¹GÐ5ÓDˆØ×5Ñ5¸A¿G¹GÐ5ÓDˆØ×5Ñ5¸A¿G¹GÐ5ÓDˆàˆØ!.ˆˆoÑØ!.ˆˆoÑØ×ÑØØ aÑ(Ø Q¨QÑ/Øð	 	ô 	
ð �!�Qˆwˆr?   c                 ó4  — t        «       rt        j                  | «      S t        | dg d¢d«       t	        di t        «       ¤Ž}|j                  | j                  «      }|j                  | j                  «      }d| i}||dœ}|j                  d||¬«       ||fS )aX  
    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``, ``compplex64`` or ``complex128``.
        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:
        Eigenvalues(Tensors): A tensor with shape math:`[*, N]` refers to the eigen values.
        Eigenvectors(Tensors): 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   r   r   r   Úeig©ÚEigenvaluesÚEigenvectorsrj   )rH  )	r   r   rH  r
   r   r4   r5   r6   r7   )r   r8   r;   r¿   Úvr*   r+   s          r>   rH  rH  
  s•   € ôZ ÔÜ�z‰z˜!‹}Ðä ØˆsÒEÀuô	
ô Ñ/¤f£hÑ/ˆà×5Ñ5°a·g±gÓ>ˆØ×5Ñ5°a·g±gÓ>ˆà�q�ˆØ"#°QÑ7ˆØ×Ñ˜e¨F¸GÐÔDà�!ˆtˆr?   c                 ó²  — t        | j                  «      }t        |«      dk  r$t        dj	                  t        |«      |«      «      ‚|d   |d   k7  rt        d|› �«      ‚t        «       rt        j                  | «      S t        | dg d¢d«       t        di t        «       ¤Ž}|j                  | j                  ¬	«      }|j                  dd
| id|i¬«       |S )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, 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   z_The dimension of Input(x) should be at least 2, but received x's dimention = {}, x's shape = {}r^   r’   zNThe last two dimensions of Input(x) should be equal, but received x's shape = r6   rG  ÚeigvalsrO   r#   r%   rj   )rN  )r-   r1   r0   r2   r°   r   r   rN  r
   r   r4   r5   r6   r7   )r   r8   r=   r;   r<   s        r>   rN  rN  T
  sâ   € ôL �1—7‘7‹m€GÜ
ˆ7ƒ|�aÒÜØm×tÑtÜ�G“˜góó
ð 	
ð ˆr�{�g˜b‘kÒ!ÜØ\Ð]dÐ\eÐfó
ð 	
ô ÔÜ�~‰~˜aÓ Ð ä ØØÚ=Øô		
ô Ñ3¬&«(Ñ3ˆØ×7Ñ7¸a¿g¹gÐ7ÓFˆØ×Ñ˜i°°a°À5È#À,ÐÔOØˆ
r?   c                 óÂ  — t        «       rt        j                  | «      S t        | dt        t
        fd«       t        | «      D ]K  \  }}t        |dt        |«      z   dz   g d¢d«       |j                  | d   j                  k7  sŒBt        d«      ‚ t        di t        «       ¤Ž}|j                  d¬«      }|j                  |«      }|j                  dd	| id
|i¬«       |S )a×  
    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 ([Tensor]): The input tensors which is a list Tensor.
        name (str, 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:: python

            >>> import paddle

            >>> # A * B
            >>> A = paddle.rand([3, 4])
            >>> B = paddle.rand([4, 5])
            >>> out = paddle.linalg.multi_dot([A, B])
            >>> print(out.shape)
            [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)
            [10, 7]

    r   Ú	multi_dotzx[Ú])r   r   r   r   r   z:All the Tensors in the input must have the same data type.)Úinput_param_namer#   r%   rj   )rP  )r   r   rP  r	   r-   r.   r3   r
   r‚   r6   rí   r   r4   r[   r5   r7   )r   r8   Úidrµ   r;   r6   r<   s          r>   rP  rP  –
  sä   € ôn ÔÜ×Ñ Ó"Ð"ä�1�cœD¤%˜=¨+Ô6Ü! !ž‰HˆB�Ü$ØØ”s˜2“w‘ Ñ$Ú;Øô	ð �z‰z˜Q˜q™TŸZ™ZÓ'ÜØPóð ð %ô Ñ5¬F«HÑ5ˆØ×"Ñ"°CÐ"Ó8ˆØ×7Ñ7¸Ó>ˆØ×ÑØ c¨1 X¸¸s°|ð 	ô 	
ð ˆ
r?   c                 óP  — t        «       rt        j                  | |«      S d„ } || |«       t        d
i t	        «       ¤Ž}t        | dg d¢d«       |j                  | j                  ¬«      }|j                  | j                  ¬«      }|j                  dd| i||dœd|i¬	«       ||fS )ah  
    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, 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:: python

            >>> 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.9238795042037964+0j), (-0.3826833963394165+0j)],
             [ 0.3826833963394165j    , -0.9238795042037964j    ]])

    c                 ó  — t        | j                  «      }t        | j                  «      dk  r!t        dt        | j                  «      z  «      ‚|d   |d   k7  rt        d|› �«      ‚|dk7  r|dk7  rt        d|› �«      ‚y y ©	Nr   zPInput(input) only support >=2 tensor, but received length of Input(input) is %s.r^   r’   zQThe input matrix must be batches of square matrices. But received x's dimention: rB  r  z+UPLO must be L or U. But received UPLO is: ©r-   r1   r0   r2   ©r   ÚUPLOr=   s      r>   rM   zeigh.<locals>.__check_input  óš   € Ü˜1Ÿ7™7“mˆGÜ�1—7‘7‹|˜aÒÜ ð4Ü69¸!¿'¹'³lñCóð ð �r‰{˜g b™kÒ)Ü ØgÐhoÐgpÐqóð ð �sŠ{˜t sš{Ü ØAÀ$ÀÐHóð ð  +ˆ{r?   Úeighr6   rG  rO   r#   rI  rY  r(   )r[  )	r   r   r[  r   r4   r
   r5   r6   r7   )r   rY  r8   rM   r;   Ú	out_valueÚ
out_vectors          r>   r[  r[  æ
  s¹   € ôJ ÔÜ�{‰{˜1˜dÓ#Ð#ò	ñ  	�a˜ÔäÑ0¤v£xÑ0ˆÜ ØØÚ=Øô		
ð ×=Ñ=ÀAÇGÁGÐ=ÓLˆ	Ø×>Ñ>ÀQÇWÁWÐ>ÓMˆ
à×ÑØØ˜�8Ø$-¸zÑJØ˜4�.ð	 	ô 	
ð ˜*Ð$Ð$r?   c           	      ó  — t        «       �r0|�s*t        j                  | d«      \  }}}t        j                  |dgd«      }t	        j
                  || j                  ¬«      }||z  }t        d«      }	t	        j
                  |	| j                  ¬«      }	t	        j                  ||kD  d|z  d|	z  «      }
t        j                  |
dg«      }t        t        t        |j                  «      «      «      }|dd |d   gz   |d   gz   }t        j                  ||«      }||z  }t        j                  ||dd«      }|S t        j                   | d	«      \  }}t	        j"                  |«      }t        j                  |dgd«      }t	        j
                  ||j                  ¬«      }||z  }t        d«      }	t	        j
                  |	|j                  ¬«      }	t	        j                  ||kD  d|z  d|	z  «      }
t        j                  |
dg«      }||z  }t        j$                  |«      }t        j                  ||dd«      }|S |�s(t'        d*i t)        «       ¤Ž}| j                  }t+        | dddgd
«       |j-                  |«      }|j-                  |«      }|j-                  |«      }|j/                  dd| gi|||dœddi¬«       |j-                  |«      }|j/                  dd|id|idgdddœ¬«       t1        dg||¬«      }||z  }t        d«      }	t1        dg|	|¬«      }	t	        j                  ||kD  d|z  d|	z  «      }
|j-                  |¬«      }|j-                  |¬«      }|j/                  dd|
iddgi||dœ¬«       t        t        t        |j                  «      «      «      }|dd |d   gz   |d   gz   }|j-                  |«      }|j-                  |«      }|j/                  dd|gi|g|gdœd|i¬«       |j-                  |«      }|j/                  d||dœd|idddœ¬«       |j3                  |«      }|j-                  |«      }|j/                  d ||dœd|iddd!œ¬«       |S t'        d*i t)        «       ¤Ž}| j                  }t+        | d"g d#¢d
«       |t        j4                  k(  rd}n|t        j6                  k(  rd}n|}|j-                  |«      }|j-                  |«      }|j/                  d$d| i||d%œd	d&i¬«       |j-                  |«      }|j/                  d'd|id|i¬(«       |j-                  |«      }|j/                  dd|id|idgdddœ¬«       t1        dg||¬«      }||z  }t        d«      }	t1        dg|	|¬«      }	t	        j                  ||kD  d|z  d|	z  «      }
|j-                  |¬«      }|j-                  |¬«      }|j/                  dd|
iddgi||dœ¬«       |j-                  |«      }|j/                  d||dœd|idddœ¬«       |j3                  |«      }|j-                  |«      }|j/                  d)d|id|gi¬(«       |j-                  |«      }|j/                  d ||dœd|iddd!œ¬«       |S )+a	  
    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
            arbitraty positive number. The data type of x should be
            float32 or float64 or complex64 or complex128. When data
            type is complex64 or cpmplex128, hermitian should be set
            True.
        rcond (Tensor, 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, 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^   TrO   rh   r   r’   NrY  Úpinvr   r   r   r–   r#   r   r�   r(   rk   r%   rV   )r1   Ú
fill_valuer6   Ú
unsqueeze2Úaxesr$   r©   r"   r'   Úelementwise_mulrP   )r'   r•   rN   rC   r6   rG  r[  rI  rB  ri   rj   r¸   )r_  )r   r   r–   ro   r±   r´   r6   rd   Úwherer¶   r-   r
  r0   r1   r   rI   r[  ri   r¸   r   r4   r
   r5   r7   r   Úappend_activationr   r   )r   ÚrcondrØ   r8   r˜   r™   ÚvtÚmax_singular_valÚcutoffrG   ÚsingularÚstÚdimsr    rL  Úout_1Úout_2Ús_absÚu_conjr;   r6   Úst_shapeÚv_shapeÚs_types                           r>   r_  r_  5  s  € ôv ÕÚä—z‘z ! UÓ+‰HˆAˆq�"Ü%Ÿz™z¨!¨b¨T°4Ó8ÐÜ×$Ñ$ U°!·'±'Ô:ˆEØÐ-Ñ-ˆFÜ�e“ˆAÜ× Ñ  ¨!¯'©'Ô2ˆAä—|‘| A¨¡J°°A±°q¸1±uÓ=ˆHÜ×!Ñ! (¨R¨DÓ1ˆBäœœc "§(¡(›mÓ,Ó-ˆDØ˜˜�9  R¡˜zÑ)¨T°"©X¨JÑ6ˆDÜ× Ñ   TÓ*ˆAà˜‘FˆEÜ—M‘M %¨¨E°4Ó8ˆEØˆLô —;‘;˜q &Ó)‰DˆAˆqÜ—J‘J˜q“MˆEÜ%Ÿz™z¨%°"°°tÓ<ÐÜ×$Ñ$ U°!·'±'Ô:ˆEØÐ-Ñ-ˆFÜ�e“ˆAÜ× Ñ  ¨!¯'©'Ô2ˆAä—|‘| E¨F¡N°A¸±E¸1¸q¹5ÓAˆHÜ×!Ñ! (¨R¨DÓ1ˆBà˜‘FˆEÜ—[‘[ “^ˆFÜ—M‘M %¨°¸Ó=ˆEØˆLâÜ Ñ4¬6«8Ñ4ˆFØ—G‘GˆEÜ$ Q¨¨i¸Ð-CÀVÔLà×9Ñ9¸%Ó@ˆAØ×9Ñ9¸%Ó@ˆAØ×:Ñ:¸5ÓAˆBØ×ÑØØ˜a˜S�zØ r°Ñ2Ø&¨Ð.ð	 ô ð  &×HÑHÈÓOÐØ×ÑØ!Ø˜Q�xØÐ 0Ð1Ø!˜d°ÀEÑJð	 ô ô  ˜s¨u¸EÔBˆEØÐ-Ñ-ˆFÜ�e“ˆAÜ˜A˜3¨1°EÔ:ˆAä—|‘| A¨¡J°°A±°q¸1±uÓ=ˆHà×:Ñ:ÀÐ:ÓGˆBØ×@Ñ@ÀuÐ@ÓMˆHØ×ÑØ!Ø˜X�Ø ˜t�nØ "¨hÑ7ð	 ô ô œœc "§(¡(›mÓ,Ó-ˆDØ˜˜�9  R¡˜zÑ)¨T°"©X¨JÑ6ˆDØ×9Ñ9¸%Ó@ˆAØ×?Ñ?ÀÓFˆGØ×ÑØ!Ø˜b˜T�{Ø!" °¨yÑ9Ø˜t�nð	 ô ð ×=Ñ=¸eÓDˆEØ×ÑØ&Ø RÑ(Ø ˜Ø!°Ñ7ð	 ô ð ×,Ñ,¨UÓ3ˆEà×=Ñ=¸eÓDˆEØ×ÑØ Ø"¨Ñ+Ø ˜Ø"'°DÑ9ð	 ô ð ˆLä Ñ4¬6«8Ñ4ˆFØ—G‘GˆEÜ$ØØÚAØô	ð œ×)Ñ)Ò)Ø"‘Øœ&×*Ñ*Ò*Ø"‘à�à×9Ñ9¸%Ó@ˆAØ×9Ñ9¸&ÓAˆAØ×ÑØØ˜Q�xØ()¸1Ñ=Ø˜s�mð	 ô ð ×=Ñ=¸fÓEˆEØ×ÑØ C¨ 8°e¸U°^ð ô ð  &×HÑHÈÓPÐØ×ÑØ!Ø˜U�|ØÐ 0Ð1Ø!˜d°ÀEÑJð	 ô ô  ˜s¨u¸FÔCˆEØÐ-Ñ-ˆFÜ�e“ˆAÜ˜A˜3¨1°FÔ;ˆAä—|‘| E¨F¡N°A¸±E¸1¸q¹5ÓAˆHà×:Ñ:ÀÐ:ÓHˆBØ×@Ñ@ÀvÐ@ÓNˆHØ×ÑØ!Ø˜X�Ø ˜t�nØ "¨hÑ7ð	 ô ð ×=Ñ=¸eÓDˆEØ×ÑØ&Ø RÑ(Ø ˜Ø!°Ñ7ð	 ô ð ×,Ñ,¨UÓ3ˆEà×>Ñ>¸uÓEˆFØ×ÑØ S¨! H°u¸v¸hÐ6Gð ô ð ×=Ñ=¸eÓDˆEØ×ÑØ Ø"¨Ñ0Ø ˜Ø"'°DÑ9ð	 ô ð ˆLr?   c                 ó$  — t        «       rt        j                  | |«      S | g|gdœ}t        d
i t	        «       ¤Ž}t        | dddgd«       t        |dddgd«       |j                  | j                  ¬«      }|j                  d| |dœd|i¬	«       |S )a�  

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

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

    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.
        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.
        name (str, optional): Name for the operation (optional, default is None).
            For more information, please refer to :ref:`api_guide_Name`.

    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:
            >>> # 2*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.])
    rP   Úsolver   r   r   rG   rO   r%   rj   )ru  )	r   r   ru  r   r4   r
   r5   r6   r7   )r   rG   r8   r*   r;   r<   s         r>   ru  ru  &  s    € ôT ÔÜ�|‰|˜A˜qÓ!Ð!à�s ! Ñ%ˆÜÑ1¬«Ñ1ˆÜ   C¨)°YÐ)?ÀÔIÜ   C¨)°YÐ)?ÀÔIØ×7Ñ7¸a¿g¹gÐ7ÓFˆà×ÑØ q¨qÑ!1¸EÀ3¸<ð 	ô 	
ð ˆ
r?   c           	      ó4  — t        «       rt        j                  | ||||«      S | g|gdœ}t        di t	        «       ¤Ž}t        | dddgd«       t        |dddgd«       |j                  | j                  ¬«      }|j                  d| |dœd|i|||d	œ¬
«       |S )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 or float64.
        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 or float64.
        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, 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.]])
    rP   Útriangular_solver   r   r   rG   rO   r%   )rÑ   r   Úunitriangularr(   )rw  )	r   r   rw  r   r4   r
   r5   r6   r7   )	r   rG   rÑ   r   rx  r8   r*   r;   r<   s	            r>   rw  rw  _  sÄ   € ôr ÔÜ×&Ñ& q¨!¨U°I¸}ÓMÐMà�s ! Ñ%ˆÜÑ<´6³8Ñ<ˆÜ Øˆs�Y 	Ð*Ð,>ô	
ô 	!Øˆs�Y 	Ð*Ð,>ô	
ð ×7Ñ7¸a¿g¹gÐ7ÓFˆà×ÑØ#Ø Ñ#Ø˜C�LàØ&Ø!.ñð	 	ô 		
ð ˆ
r?   c                 ó  — t        «       rt        j                  | ||«      S t        di t	        «       ¤Ž}t        | dddgd«       t        |dddgd«       |j                  | j                  ¬«      }|j                  d| |dœd|id	|i¬
«       |S )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, 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   rG   rO   rP   r%   rÑ   r(   )rz  )	r   r   rz  r   r4   r
   r5   r6   r7   )r   rG   rÑ   r8   r;   r<   s         r>   rz  rz  ²  s¬   € ôH ÔÜ×$Ñ$ Q¨¨5Ó1Ð1äÑ:´³Ñ:ˆÜ Øˆs�Y 	Ð*Ð,<ô	
ô 	!Øˆs�Y 	Ð*Ð,<ô	
ð ×7Ñ7¸a¿g¹gÐ7ÓFˆà×ÑØ!Ø Ñ#Ø˜C�LØ˜EÐ"ð	 	ô 	
ð ˆ
r?   c                 ó†  — t        «       r&t        j                  | || j                  «      \  }}|S d„ } || |«       t	        d
i t        «       ¤Ž}t        | dg d¢d«       |j                  | j                  ¬«      }|j                  | j                  ¬«      }| j                  }	|j                  dd| i||dœ||	dœ¬	«       |S )u  
    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, 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                 ó  — t        | j                  «      }t        | j                  «      dk  r!t        dt        | j                  «      z  «      ‚|d   |d   k7  rt        d|› �«      ‚|dk7  r|dk7  rt        d|› �«      ‚y y rV  rW  rX  s      r>   rM   zeigvalsh.<locals>.__check_input
  rZ  r?   Úeigvalshr6   rG  rO   r#   rI  )rY  Úis_testr(   )r}  )
r   r   r}  Ústop_gradientr   r4   r
   r5   r6   r7   )
r   rY  r8   ÚvaluesÚ_rM   r;   r\  r]  r~  s
             r>   r}  r}  ë  sË   € ô4 ÔÜ—O‘O A t¨Q¯_©_Ó=‰	ˆ�Øˆò	ñ  	�a˜ÔäÑ4¬6«8Ñ4ˆÜ ØØÚ=Øô		
ð ×=Ñ=ÀAÇGÁGÐ=ÓLˆ	Ø×>Ñ>ÀQÇWÁWÐ>ÓMˆ
à—/‘/ˆØ×ÑØØ˜�8Ø$-¸zÑJØ¨GÑ4ð	 	ô 	
ð Ðr?   c           	      óð  — t        j                  «       }|dk(  r|dvrt        d|› �«      ‚|€dn|}n(d|v r|dvrt        d|› �«      ‚|€dn|}nt        d	«      ‚| j                  |j                  k(  r†| j                  t         j
                  t         j                  t         j                  j                  j                  j                  t         j                  j                  j                  j                  fv st        d
«      ‚| j                  dk  rt        d| j                  › d�«      ‚|j                  dk  rt        d|j                  › d�«      ‚| j                  d   |j                  d   k7  r,t        d| j                  d   › d|j                  d   › d�«      ‚|�€| j                  t         j
                  k(  s;| j                  t         j                  j                  j                  j                  k(  r*dt        | j                  d   | j                  d   «      z  }n�| j                  t         j                  k(  s;| j                  t         j                  j                  j                  j                  k(  r)dt        | j                  d   | j                  d   «      z  }t        «       rŠt!        j"                  | |||«      \  }}}}	|dk(  r;t        j$                  dgd¬«      }t        j$                  dg| j                  ¬«      }	n'|dk(  r"t        j$                  dg| j                  ¬«      }	||||	fS t'        d$i t)        «       ¤Ž}
t+        | dg d¢d«       t+        |dg d¢d«       |
j-                  | j                  ¬«      }|
j-                  | j                  ¬«      }|
j-                  t         j.                  ¬«      }|
j-                  | j                  ¬«      }	|
j1                  d| |dœ||||	dœ||dœ¬ «       |dk(  rEt         j2                  j5                  d!dg¬"«      }t         j2                  j5                  d#dg¬"«      }	n'|dk(  r"t         j2                  j5                  d#dg¬"«      }	||||	fS )%uE  
    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 r‡  Úgpu)Nr„  zEOnly support valid driver is 'gels' or None for CUDA inputs. But got r„  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.gH¯¼šò×z>r^   çVçž¯Ò<r   r   )r1   r6   Úlstsqr6   rG  rO   rP   )ÚSolutionÚ	ResidualsÚRankÚSingularValues)rf  Údriverr(   Úrank)r8   r1   Úsingular_values)rŠ  )r±   Ú
get_devicer2   ÚRuntimeErrorr6   r   r   ÚbaseÚcorer   ÚFLOAT32ÚFLOAT64rC  r1   ro   r   r   rŠ  Úemptyr   r4   r
   r5   r   r7   ÚstaticÚdata)r   rG   rf  r�  r8   ÚdeviceÚsolutionÚ	residualsr�  r‘  r;   s              r>   rŠ  rŠ  1  s+  € ô@ ×ÑÓ €FØ�‚ØÐBÑBÜØqÐrxÐqyÐzóð ð #˜N‘°‰Ø	�&‰Ø˜Ñ'ÜØWÐX^ÐW_Ð`óð ð "˜>‘¨v‰äÐKÓLÐLð 	
�‰�1—7‘7ÒØ�G‰Gä�N‰NÜ�N‰NÜ�K‰K×Ñ×%Ñ%×-Ñ-Ü�K‰K×Ñ×%Ñ%×-Ñ-ð	
ñ
ô ØWó
ð 	
ð 	‡v�v�‚zÜØHÈÏÉÈÐPUÐVó
ð 	
ð 	‡v�v�‚zÜØHÈÏÉÈÐPUÐVó
ð 	
ð 	‡w�wˆr�{�a—g‘g˜b‘kÒ!ÜØ# A§G¡G¨B¡K =Ð0NÈqÏwÉwÐWYÉ{ÈmÐ[sÐtó
ð 	
ð �}à�G‰G”v—~‘~Ò%Ø�w‰wœ&Ÿ+™+×*Ñ*×3Ñ3×;Ñ;Ò;àœ3˜qŸw™w r™{¨A¯G©G°B©KÓ8Ñ8‰Eà�G‰G”v—~‘~Ò%Ø�w‰wœ&Ÿ+™+×*Ñ*×3Ñ3×;Ñ;Ò;àœC §¡¨¡¨Q¯W©W°R©[Ó9Ñ9ˆEäÔÜ5;·\±\Øˆq�%˜ó6
Ñ2ˆ�)˜T ?ð �VÒÜ—<‘< q c°Ô9ˆDÜ$Ÿl™l°!°¸A¿G¹GÔD‰OØ�wÒÜ$Ÿl™l°!°¸A¿G¹GÔDˆOà˜ D¨/Ð9Ð9äÑ1¬«Ñ1ˆÜ ØØÚ=Øô		
ô 	!ØØÚ=Øô		
ð ×<Ñ<À1Ç7Á7Ð<ÓKˆØ×=Ñ=ÀAÇGÁGÐ=ÓLˆ	Ø×8Ñ8¼v¿|¹|Ð8ÓLˆØ ×CÑCØ—'‘'ð Dó 
ˆð 	×ÑØØ Ñ#à$Ø&ØØ"1ñ	ð "¨VÑ4ð 	ô 
	
ð �VÒÜ—=‘=×%Ñ%¨6¸!¸Ð%Ó=ˆDÜ$Ÿm™m×0Ñ0Ø&¨q¨cð 1ó ‰Oð �wÒÜ$Ÿm™m×0Ñ0Ø&¨q¨cð 1ó ˆOð ˜ D¨/Ð9Ð9r?   c                 óæ  — t        | j                  «      dkD  st        | j                  «      dk  r!t        dt        | j                  «      z  «      ‚t        | dddgd«       t	        | |«      }|j
                  dk(  r||z  S t        j                  |«      }t        j                  |«      r|j                  «       }t        j                  |«      }||d	d	…d	f   z  }||d	d	d	…f   z  }t        j                  |«      r\t        j                  t        j                  |j                  «       d
d«      t        j                  |j                  «       d
d«      «      S t        j                  |d
d«      }|S )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, 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   zbInput(x) only support N-D (1<=N<=2) tensor in corrcoef, but received length of Input(input) is %s.r6   r   r   Úcorrcoefr   Nr^   )r0   r1   r2   r
   r­   rC  r±   Údiagr  ÚrealÚsqrtÚcomplexÚclipÚimag)r   rº   r8   ÚcÚdÚstddevs         r>   rŸ  rŸ  ä  s8  € ôL ˆ1�7‰7ƒ|�aÒœ3˜qŸw™w›<¨!Ò+Üð,Ü.1°!·'±'«lñ;ó
ð 	
ô ˜Q ¨)°YÐ)?ÀÔLäˆAˆv‹€AØ‡v�v�‚{ð �1‰uˆä�‰�A‹€Aä×Ñ˜ÔØ�F‰F‹HˆÜ�[‰[˜‹^€FØˆ’�4�‰Ñ€AØˆ�’a�‰Ñ€Aô ×Ñ˜ÔÜ�~‰~Ü�K‰K˜Ÿ™› " aÓ(¬&¯+©+°a·f±f³hÀÀAÓ*Fó
ð 	
ô �K‰K˜˜2˜qÓ!ˆà€Hr?   c           	      ó  — t        | ddd«       t        |ddd«       t        |dt        t        fd«       |dvrt	        d|z  «      ‚d}|d	k(  rd}n|d
k(  rd}n|dk(  rd}t        | j                  «      }t        |«      dk\  sJ dt        |«      z  «       ‚t        |j                  «      }t        |«      dk\  sJ dt        |«      z  «       ‚|d   |d   k(  sJ d|d   › d|d   › d�«       ‚|dk\  s
J d|z  «       ‚| j                  d   }|j                  d   }	| j                  d   }
t        |«      }|dk(  s|	dk(  r#t        j                  ||	f| j                  ¬«      S |
dk(  r#t        j                  ||	f| j                  ¬«      S |dk(  �rD|dk(  s|dk(  �r9|dkD  s|	dkD  �r.t        j                  | j                  d«      dd¬«      }t        j                  |j                  d«      dd¬«      }t        j                  |g t        |j                   dz
  «      ¢|j                   dz
  ‘|j                   dz
  ‘¬«      }t        j                  |g t        |j                   dz
  «      ¢|j                   dz
  ‘|j                   dz
  ‘¬«      }t        j"                  | |«      dz  |z   |z   }t        j$                  |d¬«      j'                  «       }|S t        j(                  j+                  | dddd…f   |dddd…dd…f   z
  |d¬ «      S )!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, 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   ÚcdistrG   rƒ   )Ú#use_mm_for_euclid_dist_if_necessaryÚuse_mm_for_euclid_distÚdonot_use_mm_for_euclid_distzžThe 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 %s.r   r«  r¬  r   r­  r   zPThe x must be at least 2-dimensional, But received Input x's dimensional is %s.
zPThe y must be at least 2-dimensional, But received Input y's dimensional is %s.
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.
z@The p must be greater than or equal to 0, But received p is %s.
r’   rO   ra   é   Tr(  )r    rÓ   )rp   .N)rƒ   r'   )r
   r	   rd   re   r2   r-   r1   r0   r±   r˜  r6   Úzerosrz   ru   r   r
  rC  rI   r¤  r¢  r  ry   )r   rG   rƒ   Úcompute_moder8   r3  r=   rá   Úr1Úr2Úc1Úx_normÚy_normÚy_transposedÚy_norm_transposedÚress                   r>   rª  rª  *  s7  € ôX ˜Q Ð%;¸WÔEÜ˜Q Ð%;¸WÔEÜˆq�#œœs�| WÔ-àð ñ ô
 ð/à1=ñ>ó
ð 	
ð €DØÐ<Ò<Ø‰Ø	Ð1Ò	1Ø‰Ø	Ð7Ò	7Øˆä�1—7‘7‹m€GÜˆw‹<˜1Òð ð	6Ü8;¸G»ñ	EóÐô �1—7‘7‹m€GÜˆw‹<˜1Òð ð	6Ü8;¸G»ñ	EóÐð �2‰;˜' "™+Ò%ð ð	4Ø4;¸B±K°=ð A'Ø'.¨r¡{ m°3ð	8óÐ%ð
 �Š6ð ð	"Ø$%ñ	&óˆ6ð
 
�‰�‰€BØ	
�‰�‰€BØ	
�‰�‰€Bäˆa‹€Aà	ˆQ‚w�"˜’'Ü�|‰|˜R ˜H¨A¯G©GÔ4Ð4à	ˆQ‚wÜ�|‰|˜R ˜H¨A¯G©GÔ4Ð4àˆCƒx�T˜Q’Y 4¨1£9°"°r²'¸RÀ"»WÜ—‘˜AŸE™E !›H¨2°tÔ<ˆÜ—‘˜AŸE™E !›H¨2°tÔ<ˆÜ×'Ñ'ØÐ@”e˜AŸF™F Q™JÓ'Ð@¨¯©°!©Ð@°Q·V±V¸a±ZÐ@ô
ˆô #×,Ñ,ØØL”5˜Ÿ™ q™Ó)ÐL¨6¯;©;¸©?ÐL¸F¿K¹KÈ!¹OÐLô
Ðô �m‰m˜A˜|Ó,¨rÑ1Ð4EÑEÈÑNˆÜ�k‰k˜# 3Ô'×,Ñ,Ó.ˆØˆ
ä�=‰=×ÑØ	ˆ#ˆt’Qˆ,‰˜!˜C ¢qª!˜OÑ,Ñ,°¸ð ó ð r?   c           
      óÖ  — t        | j                  dg d¢d«       t        |j                  dg d¢d«       | j                  |j                  k(  sJ d«       ‚t        | j                  «      dk\  rFt        |j                  «      dk\  r.t        | j                  «      t        |j                  «      dz   k(  sJ d«       ‚| j                  d	   | j                  d
   k\  sJ d«       ‚| j                  d
   |j                  d
   k\  sJ d«       ‚t	        | j                  dd	 «      D ]+  \  }}| j                  |   |j                  |   k(  rŒ&J d«       ‚ d„ }t        | j                  «      dk(  r	 || |«      S | j                  d	d \  }}| j                  }|j                  }	| j                  d
|d	   |d
   f«      } |j                  d
|	d
   f«      }| j                  d   }
t        j                  |
||g| j                  ¬«      }t        |
«      D ]M  }t        «       r || |   ||   «      ||<   Œ t        j                  j                  || || |   ||   «      «      }ŒO |j                  |«      }|S )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, 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   rG  Úhouseholder_productÚtauz5The input x must have the same dtype with input tau.
r   r   z™The 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           
      ól  — | j                   dd  \  }}|j                   d   }t        j                  |«      j                  | j                  «      }t        t        ||«      «      D �]Â  }| |d …|f   }t        «       rd|d<   n!t        j                  j                  |dd«      }|j                  ddg«      }t        «       r®| j                  t        j                  t        j                  fv rJ|d d …|d …f   |d d …|d …f   |z  t        j                  |«      j                  z  ||   z  z
  |d d …|d …f<   ŒÑ|d d …|d …f   |d d …|d …f   |z  |j                  z  ||   z  z
  |d d …|d …f<   �Œ	t        j                  j                  |t        d «      t        |d «      f| j                  t        j                  t        j                  fv r-|d d …|d …f   |d d …|d …f   |z  |j                  z  ||   z  z
  n,|d d …|d …f   |d d …|d …f   |z  |j                  z  ||   z  z
  «      }�ŒÅ |d d …d |…f   S )Nr’   r^   r   r   )r1   r±   Úeyer¯   r6   r
  rp   r   r™  ÚsetitemrŸ   r   r   r¸   ÚTÚslice)r   r»  r  r  Úkr  r  r¿   s           r>   Ú_householder_productz1householder_product.<locals>._householder_productò  s  € Ø�w‰w�r�sˆ|‰ˆˆ1Ø�I‰I�b‰MˆÜ�J‰J�q‹M× Ñ  §¡Ó)ˆÜ”s˜1˜a“y×!ˆAØ�!‘"�a�%‘ˆAÜÔ Ø��!’ä—M‘M×)Ñ)¨!¨Q°Ó2�Ø—	‘	˜2˜q˜'Ó"ˆAÜÔ Ø—7‘7œv×0Ñ0´&×2BÑ2BÐCÑCØ ¢ A¡B ™xØš!˜Q™R˜%™ 1™¤v§{¡{°1£~×'7Ñ'7Ñ7¸#¸a¹&Ñ@ñ �A’a˜™�e’Hð  !¢ A¡B ™x¨1ªQ°±¨U©8°a©<¸!¿#¹#Ñ+=ÀÀAÁÑ+FÑG�A’a˜™�e“Hä—M‘M×)Ñ)ØÜ˜4“[¤%¨¨4£.Ð1à—w‘w¤6×#4Ñ#4´f×6FÑ6FÐ"GÑGð ’a˜™�e‘H ¢! Q¡R %¡¨1¡¨q¯s©sÑ 2°S¸±VÑ ;Ò<àš1˜a™b˜5™ Q¢q¨!©" u¡X°¡\°A·C±CÑ%7¸#¸a¹&Ñ%@ÑAó’ð "ð, ’�B�Q�B�‰xˆr?   r   rO   )r   r6   r0   r1   r3   rŸ   r±   r¯  r
  r   r™  r¾  )r   r»  r8   r9   r�  rÂ  r  r  Úorg_x_shapeÚorg_tau_shapeÚn_batchr<   r  s                r>   rº  rº     se  € ôL Ø	�‰Øò	
ð 	ô
ô Ø�	‰	Øò	
ð 	ô
ð 	
�‰�3—9‘9Òð@à?ó@Øô 	ˆA�G‰G‹˜ÒÜ�—	‘	‹N˜aÒÜ�—‘‹LœC §	¡	›N¨QÑ.Ò.ðð
	Ióð	/ð 	
�‰�‰�q—w‘w˜r‘{Ò"ðXàWóXØ"ð 	
�‰�‰�s—y‘y ‘}Ò$ð7à6ó7Ø$ä˜AŸG™G C R˜LÖ)‰ˆˆQà�G‰G�C‰L˜CŸI™I c™NÓ*ð	OàNó	OØ*ð *ò
ô8 ˆ1�7‰7ƒ|�qÒÙ# A sÓ+Ð+Ø�7‰7�2�3ˆ<�D€A€qØ—'‘'€KØ—I‘I€MØ	�	‰	�2�{ 2‘¨°B©Ð8Ó9€AØ
�+‰+�r˜=¨Ñ,Ð-Ó
.€CØ�g‰g�a‰j€GÜ
�,‰,˜  A�¨a¯g©gÔ
6€CÜ�7Ž^ˆÜÔÙ)¨!¨A©$°°A±Ó7ˆC�ŠFä—-‘-×'Ñ'Ø�QÑ,¨Q¨q©T°3°q±6Ó:ó‰Cð	 ð �+‰+�kÓ
"€CØ€Jr?   r  )FFN)r€   NFNr)  )NN)TTNNN)r   N)FNr�   )éd   r   r   N)Nr   N)NTr   N)ÚreducedN)TFN)TTN)rB  N)r‰  FN)TFFN)NNN)TN)ra   r«  N)BÚnumpyrn   r±   r   Úpaddle.base.libpaddler   Úpaddle.common_ops_importr   Úpaddle.utils.inplace_utilsr   Úbase.data_feederr   r	   r
   Úcommon_ops_importr   Ú	frameworkr   r   r   Úcreationr   Úmanipulationr   Úmathr   Ú__all__rÎ   r   rA   rI   ry   r†   r¥   r§   r­   r®   rË   rÍ   rÐ   rÔ   rà   rã   ré   rò   r÷   rý   r–   r.  r0  r  r5  r>  rH  rN  rP  r[  r_  ru  rw  rz  r}  rŠ  rŸ  rª  rº  r  r?   r>   Ú<module>rÓ     sc  ðó ã Ý Ý *Ý ,Ý Cç PÑ PÝ (ß LÑ LÝ Ý Ý "à
€ð €ó`ðF ò*ó ð*óAóH]
ó@oódh
óVXóvwótUðp òó ðó(EóP6órTónCóL)óX>óB<ó~3ól:ózKó\X6óvHóV>óBcóLfóR<ó~?óDMó`L%ó^nób6ðt BFóPóf6órCóLp:ófCðN KOósôlr?   