
    NgG                    4   d dl mZ ddlmZmZmZmZmZm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 erdd
lmZ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dWdZ"dddXd#Z#dYd$Z$d d%dZd'Z%d[d(Z&dYd)Z'dYd*Z(d\d+Z)dd,d-d]d1Z*d^d3Z+dd4d_d7Z,dYd8Z-d\d9Z.dd4d_d:Z/d;d<d`d?Z0dad@Z1dA Z2d\dBZ3dCdDdbdFZ4dcdHZ5ddIdddLZ6d ddMdedPZ7dddXdQZ8ddddRdfdUZ9g dVZ:dS )g    )annotations   )_floating_dtypes_numeric_dtypesfloat32float64	complex64
complex128)reshape)conj)Array   )normalize_axis_tuple)TYPE_CHECKING)LiteralOptionalSequenceTupleUnionDtype)
NamedTupleNc                  $    e Zd ZU ded<   ded<   dS )
EighResultr   eigenvalueseigenvectorsN__name__
__module____qualname____annotations__     R/var/www/html/ai-engine/env/lib/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   r1   boolreturnc              .   | j         t          vrt          d          t          j                            | j                  }|r?t          j        |          j	        }|j         t          t          fv rt          |          }|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mTr	   r
   r   )r2   r1   Lr.   s       r#   r:   r:   -   s     	w&&&LMMM
	18$$A JqMM7y*---QA:a==r"   axisx1x2rA   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@   )r6   r   r7   shape
ValueErrorndimr   r<   r8   crossr;   )rB   rC   rA   s      r#   rJ   rJ   @   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)	r6   r   r7   r   r<   r8   r9   detr;   r2   s    r#   rL   rL   R   sA     	w&&&GHHH:bimmAH--...r"   )offsetrN   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.
    r?   )rN   axis1axis2)r   r<   r8   diagonalr;   )r2   rN   s     r#   rS   rS   _   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)r6   r   r7   r   mapr   r<   r8   r9   eighr;   rM   s    r#   rV   rV   j   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)	r6   r   r7   r   r<   r8   r9   eigvalshr;   rM   s    r#   rX   rX   z   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)	r6   r   r7   r   r<   r8   r9   invr;   rM   s    r#   rZ   rZ      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)r6   r   r7   r   r<   r8   matmulr;   rB   rC   s     r#   r\   r\      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)rP   r?   rA   r_   r`   )	r6   r   r7   r   r<   r8   r9   normr;   )r2   r_   r`   s      r#   matrix_normrf      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)	r6   r   r7   r   r<   r8   r9   matrix_powerr;   )r2   rg   s     r#   ri   ri      sG     	w&&&ghhh :bi,,QXq99:::r"   )rtolrj   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_uvNr?   T)rA   r_   rP   .r@   )rI   r8   r9   LinAlgErrorsvdr;   maxrG   finfor6   eps
isinstancer   asarraynewaxisr<   count_nonzero)r2   rj   r/   tols       r#   matrix_rankry      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_transposer?   rP   )rI   rH   r   r<   r8   swapaxesr;   rM   s    r#   matrix_transposer|      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)
r6   r   r7   rI   rH   r   r<   r8   outerr;   r]   s     r#   r~   r~      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 pinvNrP   )rcond)r6   r   r7   rq   rG   r8   rr   rs   r   r<   r9   pinvr;   )r2   rj   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   )r6   r   r7   r%   rU   r   r<   r8   r9   qrr;   )r2   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)r6   r   r7   r)   rU   r   r<   r8   r9   slogdetr;   rM   s    r#   r   r     sL     	w&&&KLLL #ej")*;*;AH*E*EFFGGr"   c                   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}t          j        |dddd	          5   || ||
          }d d d            n# 1 swxY w Y    ||                    |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callignore)r   invalidoverdivideunder)	signatureF)copy)linalg.linalgr   r   r   r   r   r   r   r9   r   rI   solve1solver8   errstateastype)abr   r   r   r   r   r   r   r   _wraptresult_tgufuncr   rs                    r#   _solver   /  s   > > > > > > > > > > > > > > > > > > '&&&&&:a==DAqq1jmmGAt+a##KAx 	v{{%$ )=++8I	5v"88
E 
E 
E . .F1a9---. . . . . . . . . . . . . . . 4..///s   B77B;>B;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)r6   r   r7   r   r<   r   r;   r]   s     r#   r   r   K  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   )r6   r   r7   r-   rU   r   r<   r8   r9   rp   r;   )r2   r   s     r#   rp   rp   X  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 svdvalsFrm   )	r6   r   r7   r   r<   r8   r9   rp   r;   rM   s    r#   svdvalsr   i  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   )r6   r   r7   r   r<   r8   	tensordotr;   )rB   rC   r   s      r#   r   r   q  sQ     
x&&"(/*I*IFGGG:bl29bidCCCDDDr"   )rN   r6   r6   Optional[Dtype]c              "   | j         t          vrt          d          |/| j         t          k    rt          }n| j         t
          k    rt          }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 traceNrP   r?   )rN   rQ   rR   r6   )r6   r   r7   r   r   r	   r
   r   r<   r8   ru   tracer;   )r2   rN   r6   s      r#   r   r   z  s     	wo%%BCCC }7gEEW	!!E :bj!(6SU]b!c!c!cddeeer"   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 axisr?   .).N).r   r   )r6   r   r7   rq   rI   tuplerG   rH   r8   broadcast_arraysr;   moveaxisr   r<   )	rB   rC   rA   rI   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"   rd   %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 )
rc   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!   rG   r   r   r   s     r#   
<listcomp>zvector_norm.<locals>.<listcomp>  s    ///Qagaj///r"   )r6   c                *    g | ]}j         |         S r!   r   r   s     r#   r   zvector_norm.<locals>.<listcomp>  s    >X>X>Xaqwqz>X>X>Xr"   )rA   r`   r   )r6   r   r7   r;   ravelrt   r   r   rI   ranger8   	transposer   prodrD   r   r<   r9   re   listrG   )r2   rA   r_   r`   _axisrestnewshaper   rG   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"   )r:   rJ   rL   rS   rV   rX   rZ   r\   rf   ri   ry   r|   r~   r   r   r   r   rp   r   r   r   r   r   )r2   r   r1   r3   r4   r   )rB   r   rC   r   rA   rD   r4   r   )r2   r   r4   r   )r2   r   rN   rD   r4   r   )r2   r   r4   r   )rB   r   rC   r   r4   r   )r2   r   r_   r3   r`   ra   r4   r   )r2   r   rg   rD   r4   r   )r2   r   rj   rk   r4   r   )r2   r   r   r   r4   r%   )r2   r   r4   r)   )r2   r   r   r3   r4   r-   )r2   r   r4   r   )rB   r   rC   r   r   r   r4   r   )r2   r   rN   rD   r6   r   r4   r   )
r2   r   rA   r   r_   r3   r`   r   r4   r   );
__future__r   _dtypesr   r   r   r   r	   r
   _manipulation_functionsr   _elementwise_functionsr   _array_objectr   core.numericr   typingr   _typingr   r   r   r   r   r   r   numpy.linalgnumpyr8   r   r%   r)   r-   r:   rJ   rL   rS   rV   rX   rZ   r\   rf   ri   ry   r|   r~   r   r   r   r   r   rp   r   r   r   r   r   __all__r!   r"   r#   <module>r      s   " " " " " "                - , , , , , ( ( ( ( ( (             / / / / / /             JIIIIIIIIIIIIIIII                         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 084 4 4 4 /3 ] ] ] ] ] ]"A A A A cd E E E E E E )*D f f f f f f* 46 & & & & & &, OSej  PQ + + + + + +Z F  F  Fr"   