
    ~OdE                       d dl mZ ddlmZmZ ddlmZ ddlmZ ddl	m
Z
 d dlmZ erdd	lmZmZmZmZmZ d d
lmZ d dlZd dlZ G d de          Z G d de          Z G d de          Z G d de          ZdddSdZdddTd"ZdUd#Zd d$dVd&ZdWd'ZdUd(Z dUd)Z!dXd*Z"dd+d,dYd0Z#dZd2Z$dd3d[d6Z%dUd7Z&dXd8Z'dd3d[d9Z(d:d;d\d>Z)d]d?Z*d@ Z+dXdAZ,dBdCd^dEZ-d_dGZ.ddHd`dKZ/d d$dVdLZ0dddTdMZ1ddddNdadQZ2g dRZ3dS )b    )annotations   )_floating_dtypes_numeric_dtypes)reshape)Array   )normalize_axis_tuple)TYPE_CHECKING)LiteralOptionalSequenceTupleUnion)
NamedTupleNc                  $    e Zd ZU ded<   ded<   dS )
EighResultr   eigenvalueseigenvectorsN__name__
__module____qualname____annotations__     6lib/python3.11/site-packages/numpy/array_api/linalg.pyr   r      s*         r   r   c                  $    e Zd ZU ded<   ded<   dS )QRResultr   QRNr   r   r   r   r   r      s"         HHHHHHHHr   r   c                  $    e Zd ZU ded<   ded<   dS )SlogdetResultr   sign	logabsdetNr   r   r   r   r#   r#      s'         KKKr   r#   c                  .    e Zd ZU ded<   ded<   ded<   dS )	SVDResultr   USVhNr   r   r   r   r'   r'      s+         HHHHHHIIIIIr   r'   F)upperxr   r+   boolreturnc                  | j         t          vrt          d          t          j                            | j                  }|rt          j        |          j	        S t          j        |          S )z
    Array API compatible wrapper for :py:func:`np.linalg.cholesky <numpy.linalg.cholesky>`.

    See its docstring for more information.
    z2Only floating-point dtypes are allowed in cholesky)
dtyper   	TypeErrornplinalgcholesky_arrayr   _newmT)r,   r+   Ls      r   r4   r4   %   s_     	w&&&LMMM
	18$$A  z!}}:a==r   axisx1x2r;   intc              p   | j         t          vs|j         t          vrt          d          | j        |j        k    rt	          d          | j        dk    rt	          d          | j        |         dk    rt	          d          t          j        t          j	        | j
        |j
        |                    S )zz
    Array API compatible wrapper for :py:func:`np.cross <numpy.cross>`.

    See its docstring for more information.
    z(Only numeric dtypes are allowed in crossz"x1 and x2 must have the same shaper   z/cross() requires arrays of dimension at least 1   zcross() dimension must equal 3r:   )r0   r   r1   shape
ValueErrorndimr   r6   r2   crossr5   )r<   r=   r;   s      r   rD   rD   5   s     
x&&"(/*I*IBCCC	x28=>>>	w!||JKKK	x~9::::bhry")$???@@@r   c                   | j         t          vrt          d          t          j        t
          j                            | j                            S )z
    Array API compatible wrapper for :py:func:`np.linalg.det <numpy.linalg.det>`.

    See its docstring for more information.
    z-Only floating-point dtypes are allowed in det)	r0   r   r1   r   r6   r2   r3   detr5   r,   s    r   rF   rF   G   sA     	w&&&GHHH:bimmAH--...r   )offsetrH   c              `    t          j        t          j        | j        |dd                    S )z
    Array API compatible wrapper for :py:func:`np.diagonal <numpy.diagonal>`.

    See its docstring for more information.
    r9   rH   axis1axis2)r   r6   r2   diagonalr5   r,   rH   s     r   rN   rN   T   s)     :bk!(62NNNOOOr   c                   | j         t          vrt          d          t          t	          t
          j        t          j        	                    | j
                             S )z
    Array API compatible wrapper for :py:func:`np.linalg.eigh <numpy.linalg.eigh>`.

    See its docstring for more information.
    z.Only floating-point dtypes are allowed in eigh)r0   r   r1   r   mapr   r6   r2   r3   eighr5   rG   s    r   rR   rR   _   sJ     	w&&&HIII s5:ry~~ah'?'?@@AAr   c                   | j         t          vrt          d          t          j        t
          j                            | j                            S )z
    Array API compatible wrapper for :py:func:`np.linalg.eigvalsh <numpy.linalg.eigvalsh>`.

    See its docstring for more information.
    z2Only floating-point dtypes are allowed in eigvalsh)	r0   r   r1   r   r6   r2   r3   eigvalshr5   rG   s    r   rT   rT   o   sC     	w&&&LMMM:bi((22333r   c                   | j         t          vrt          d          t          j        t
          j                            | j                            S )z
    Array API compatible wrapper for :py:func:`np.linalg.inv <numpy.linalg.inv>`.

    See its docstring for more information.
    z-Only floating-point dtypes are allowed in inv)	r0   r   r1   r   r6   r2   r3   invr5   rG   s    r   rV   rV   |   sA     	w&&&GHHH:bimmAH--...r   c                   | j         t          vs|j         t          vrt          d          t          j        t          j        | j        |j                            S )z|
    Array API compatible wrapper for :py:func:`np.matmul <numpy.matmul>`.

    See its docstring for more information.
    z)Only numeric dtypes are allowed in matmul)r0   r   r1   r   r6   r2   matmulr5   r<   r=   s     r   rX   rX      sL     
x&&"(/*I*ICDDD:bi	2955666r   fro)keepdimsordr[   r\   2Optional[Union[int, float, Literal['fro', 'nuc']]]c                  | j         t          vrt          d          t          j        t
          j                            | j        d||                    S )
    Array API compatible wrapper for :py:func:`np.linalg.norm <numpy.linalg.norm>`.

    See its docstring for more information.
    z5Only floating-point dtypes are allowed in matrix_norm)rJ   r9   r;   r[   r\   )	r0   r   r1   r   r6   r2   r3   normr5   )r,   r[   r\   s      r   matrix_normrb      sJ     	w&&&OPPP:binnQXHxUXnYYZZZr   nc                   | j         t          vrt          d          t          j        t
          j                            | j        |                    S )z
    Array API compatible wrapper for :py:func:`np.matrix_power <numpy.matrix_power>`.

    See its docstring for more information.
    zMOnly floating-point dtypes are allowed for the first argument of matrix_power)	r0   r   r1   r   r6   r2   r3   matrix_powerr5   )r,   rc   s     r   re   re      sG     	w&&&ghhh :bi,,QXq99:::r   )rtolrf   Optional[Union[float, Array]]c              Z   | j         dk     rt          j                            d          t          j                            | j        d          }|T|                    dd          t          | j        d	d                   z  t          j        |j	                  j
        z  }nZt          |t                    r|j        }|                    dd          t          j        |          d
t          j        f         z  }t          j        t          j        ||k    d                    S )z
    Array API compatible wrapper for :py:func:`np.matrix_rank <numpy.matrix_rank>`.

    See its docstring for more information.
    r	   zA1-dimensional array given. Array must be at least two-dimensionalF
compute_uvNr9   T)r;   r[   rJ   .r:   )rC   r2   r3   LinAlgErrorsvdr5   maxrA   finfor0   eps
isinstancer   asarraynewaxisr6   count_nonzero)r,   rf   r)   tols       r   matrix_rankru      s     	vzzi##$ghhh
	ah511A|eede++c!'"##,.?.??"(17BSBSBWWdE"" 	;D eede++BJt,<,<S"*_,MM:b&q3wR888999r   c                   | j         dk     rt          d          t          j        t	          j        | j        dd                    S )Nr	   z5x must be at least 2-dimensional for matrix_transposer9   rJ   )rC   rB   r   r6   r2   swapaxesr5   rG   s    r   matrix_transposerx      s<    vzzPQQQ:bk!(B33444r   c                  | j         t          vs|j         t          vrt          d          | j        dk    s|j        dk    rt	          d          t          j        t          j        | j	        |j	                            S )zz
    Array API compatible wrapper for :py:func:`np.outer <numpy.outer>`.

    See its docstring for more information.
    z(Only numeric dtypes are allowed in outerr   z/The input arrays to outer must be 1-dimensional)
r0   r   r1   rC   rB   r   r6   r2   outerr5   rY   s     r   rz   rz      sr     
x&&"(/*I*IBCCC 
w!||rw!||JKKK:bhry")44555r   c              &   | j         t          vrt          d          |;t          | j        dd                   t          j        | j                   j        z  }t          j	        t
          j
                            | j        |                    S )z
    Array API compatible wrapper for :py:func:`np.linalg.pinv <numpy.linalg.pinv>`.

    See its docstring for more information.
    z.Only floating-point dtypes are allowed in pinvNrJ   )rcond)r0   r   r1   rm   rA   r2   rn   ro   r   r6   r3   pinvr5   )r,   rf   s     r   r}   r}      sw     	w&&&HIII |17233<  28AG#4#4#88:binnQXTn::;;;r   reducedmoder   Literal['reduced', 'complete']c         	         | j         t          vrt          d          t          t	          t
          j        t          j        	                    | j
        |                     S )z
    Array API compatible wrapper for :py:func:`np.linalg.qr <numpy.linalg.qr>`.

    See its docstring for more information.
    z,Only floating-point dtypes are allowed in qrr   )r0   r   r1   r   rQ   r   r6   r2   r3   qrr5   )r,   r   s     r   r   r      sN     	w&&&FGGG SRY\\!(\%F%FGGHHr   c                   | j         t          vrt          d          t          t	          t
          j        t          j        	                    | j
                             S )z
    Array API compatible wrapper for :py:func:`np.linalg.slogdet <numpy.linalg.slogdet>`.

    See its docstring for more information.
    z1Only floating-point dtypes are allowed in slogdet)r0   r   r1   r#   rQ   r   r6   r2   r3   slogdetr5   rG   s    r   r   r     sL     	w&&&KLLL #ej")*;*;AH*E*EFFGGr   c                z   ddl m}m}m}m}m}m}m} ddlm	}	  ||           \  } }
 ||             ||             ||          \  }} || |          \  }}|j
        dk    r|	j        }n|	j        } ||          rdnd} ||          } || |||          } ||                    |d	                    S )
Nr	   )
_makearray_assert_stacked_2d_assert_stacked_square_commonTypeisComplexTypeget_linalg_error_extobj_raise_linalgerror_singular)_umath_linalgr   zDD->Dzdd->d)	signatureextobjF)copy)linalg.linalgr   r   r   r   r   r   r   r3   r   rC   solve1solveastype)abr   r   r   r   r   r   r   r   _wraptresult_tgufuncr   r   rs                     r   _solver   $  sK   > > > > > > > > > > > > > > > > > > '&&&&&:a==DAqq1jmmGAt+a##KAx 	v{{%$ )=++8I$$%@AAFq!y888A4..///r   c                   | j         t          vs|j         t          vrt          d          t          j        t          | j        |j                            S )z
    Array API compatible wrapper for :py:func:`np.linalg.solve <numpy.linalg.solve>`.

    See its docstring for more information.
    z/Only floating-point dtypes are allowed in solve)r0   r   r1   r   r6   r   r5   rY   s     r   r   r   ?  sL     
x'''28;K+K+KIJJJ:fRY	22333r   Tfull_matricesr   c         	         | j         t          vrt          d          t          t	          t
          j        t          j        	                    | j
        |                     S )z
    Array API compatible wrapper for :py:func:`np.linalg.svd <numpy.linalg.svd>`.

    See its docstring for more information.
    z-Only floating-point dtypes are allowed in svdr   )r0   r   r1   r'   rQ   r   r6   r2   r3   rl   r5   )r,   r   s     r   rl   rl   L  sN     	w&&&GHHH c%*bimmAHMm&Z&Z[[\\r   Union[Array, Tuple[Array, ...]]c                   | j         t          vrt          d          t          j        t
          j                            | j        d                    S )Nz1Only floating-point dtypes are allowed in svdvalsFri   )	r0   r   r1   r   r6   r2   r3   rl   r5   rG   s    r   svdvalsr   ]  sC    w&&&KLLL:bimmAHm??@@@r   axesr   /Union[int, Tuple[Sequence[int], Sequence[int]]]c                  | j         t          vs|j         t          vrt          d          t          j        t          j        | j        |j        |                    S )Nz,Only numeric dtypes are allowed in tensordotr   )r0   r   r1   r   r6   r2   	tensordotr5   )r<   r=   r   s      r   r   r   e  sQ     
x&&"(/*I*IFGGG:bl29bidCCCDDDr   c         
         | j         t          vrt          d          t          j        t          j        t          j        | j        |dd                              S )zz
    Array API compatible wrapper for :py:func:`np.trace <numpy.trace>`.

    See its docstring for more information.
    z(Only numeric dtypes are allowed in tracerJ   r9   rK   )	r0   r   r1   r   r6   r2   rq   tracer5   rO   s     r   r   r   n  sR     	wo%%BCCC :bj!(6SU!V!V!VWWXXXr   c              R   | j         t          vs|j         t          vrt          d          t          | j        |j                  }d|| j        z
  z  t          | j                  z   }d||j        z
  z  t          |j                  z   }||         ||         k    rt          d          t          j	        | j
        |j
                  \  }}t          j        ||d          }t          j        ||d          }|dd d d f         |d         z  }t          j        |d                   S )Nz)Only numeric dtypes are allowed in vecdot)r   z6x1 and x2 must have the same size along the given axisr9   .).N).r   r   )r0   r   r1   rm   rC   tuplerA   rB   r2   broadcast_arraysr5   moveaxisr   r6   )	r<   r=   r;   rC   x1_shapex2_shapex1_x2_ress	            r   vecdotr   {  s
   	x&&"(/*I*ICDDDrw  DTBG^$uRX6HTBG^$uRX6H~$''QRRR"29bi88HC
+c4
$
$C
+c4
$
$C
c4l
c)n
,C:c)n%%%r   r`   %Optional[Union[int, Tuple[int, ...]]]Optional[Union[int, float]]c              8  
 | j         t          vrt          d          | j        
|
                                
d}nt          |t                    rt          || j                  t          fdt          
j                  D                       }||z   }t          j        
|                              t          j        
fd|D             t                    g
fd|D             R           
d}n|}t          j        t          j                            
||                    }|rft'          | j                  }t          |t          | j                  n|| j                  }|D ]}	d	||	<   t          |t          |                    }|S )
r_   z.Only floating-point dtypes are allowed in normNr   c              3  $   K   | ]
}|v|V  d S )Nr   ).0inormalized_axiss     r   	<genexpr>zvector_norm.<locals>.<genexpr>  s-      JJ1/1I1IQ1I1I1I1IJJr   c                *    g | ]}j         |         S r   rA   r   r   r   s     r   
<listcomp>zvector_norm.<locals>.<listcomp>  s    ///Qagaj///r   )r0   c                *    g | ]}j         |         S r   r   r   s     r   r   zvector_norm.<locals>.<listcomp>  s    >X>X>Xaqwqz>X>X>Xr   )r;   r\   r   )r0   r   r1   r5   ravelrp   r   r
   rC   ranger2   	transposer   prodr>   r   r6   r3   ra   listrA   )r,   r;   r[   r\   _axisrestnewshaper   rA   r   r   r   s             @@r   vector_normr     s    	w&&&HIII 	
A|GGII	D%	 	  
 /tQV<<JJJJafJJJJJ$;LH%%--W////$///s;;;Y>X>X>X>XSW>X>X>XYY[ [
*RY^^AEs^;;
<
<C ) QW$dlU16]]]afUU 	 	AE!HHc5<<((Jr   )r4   rD   rF   rN   rR   rT   rV   rX   rb   re   ru   rx   rz   r}   r   r   r   rl   r   r   r   r   r   )r,   r   r+   r-   r.   r   )r<   r   r=   r   r;   r>   r.   r   )r,   r   r.   r   )r,   r   rH   r>   r.   r   )r,   r   r.   r   )r<   r   r=   r   r.   r   )r,   r   r[   r-   r\   r]   r.   r   )r,   r   rc   r>   r.   r   )r,   r   rf   rg   r.   r   )r,   r   r   r   r.   r   )r,   r   r.   r#   )r,   r   r   r-   r.   r'   )r,   r   r.   r   )r<   r   r=   r   r   r   r.   r   )
r,   r   r;   r   r[   r-   r\   r   r.   r   )4
__future__r   _dtypesr   r   _manipulation_functionsr   _array_objectr   core.numericr
   typingr   _typingr   r   r   r   r   r   numpy.linalgnumpyr2   r   r   r#   r'   r4   rD   rF   rN   rR   rT   rV   rX   rb   re   ru   rx   rz   r}   r   r   r   r   rl   r   r   r   r   r   __all__r   r   r   <module>r      sp   " " " " " " 6 6 6 6 6 6 6 6 , , , , , ,             / / / / / /             CBBBBBBBBBBBBBB                         z       J       
    ,1        35 A A A A A A$
/ 
/ 
/ 
/ ,- P P P P P PB B B B 4 4 4 4/ / / /7 7 7 7( 27rw [ [ [ [ [ [; ; ; ; GK : : : : : :05 5 5 56 6 6 6$ @D < < < < < <" ?H I I I I I IH H H H00 0 064 4 4 4 /3 ] ] ] ] ] ]"A A A A cd E E E E E E )* 
Y 
Y 
Y 
Y 
Y 
Y 46 & & & & & &, OSej  PQ + + + + + +Z F  F  Fr   