o
    0cDB                     @  s  d dl mZ ddlmZ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
 d
eZG dd deZG dd deZG dd deZdddiddZdddjd d!Zdkd"d#Zd d$dld&d'Zdmd(d)Zdkd*d+Zdkd,d-Zdnd.d/Zdd0d1dod5d6Zdpd8d9Z dd:dqd=d>Z!dkd?d@Z"dndAdBZ#dd:dqdCdDZ$dEdFdrdIdJZ%dsdKdLZ&dMdN Z'dndOdPZ(dQdRdtdTdUZ)dudWdXZ*dYdZdvd]d^Z+d d$dld_d`Z,dddjdadbZ-dddYdcdwdfdgZ.g dhZ/dS )x    )annotations   )_floating_dtypes_numeric_dtypes)Array)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__ r   r   L/var/www/html/gps/gps/lib/python3.10/site-packages/numpy/array_api/linalg.pyr         
 r   c                   @  r   )QRResultr   QRNr   r   r   r   r   r      r   r   c                   @  r   )SlogdetResultr   sign	logabsdetNr   r   r   r   r   r      r   r   c                   @  s&   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   
 r    F)upperxr   r$   boolreturnc               C  s:   | j tvr	tdtj| j}|rt|j	S t|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$   Lr   r   r   r,   "   s   

r,   axisx1x2r3   intc               C  sr   | 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tj	| j
|j
|d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 3r2   )r(   r   r)   shape
ValueErrorndimr   r.   r*   crossr-   )r4   r5   r3   r   r   r   r;   2   s   
r;   c                C  &   | j tvr	tdt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)	r(   r   r)   r   r.   r*   r+   detr-   r%   r   r   r   r=   D   s   
r=   )offsetr?   c               C  s   t tj| j|dddS )z
    Array API compatible wrapper for :py:func:`np.diagonal <numpy.diagonal>`.

    See its docstring for more information.
    r1   r?   axis1axis2)r   r.   r*   diagonalr-   r%   r?   r   r   r   rD   Q   s   rD   c                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)r(   r   r)   r   mapr   r.   r*   r+   eighr-   r>   r   r   r   rH   \      
rH   c                C  r<   )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)	r(   r   r)   r   r.   r*   r+   eigvalshr-   r>   r   r   r   rJ   l      
rJ   c                C  r<   )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)	r(   r   r)   r   r.   r*   r+   invr-   r>   r   r   r   rL   y   rK   rL   c                C  s2   | j tvs
|j tvrtdtt| 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)r(   r   r)   r   r.   r*   matmulr-   r4   r5   r   r   r   rM      s   rM   fro)keepdimsordrP   rQ   2Optional[Union[int, float, Literal['fro', 'nuc']]]c               C  s.   | j tvr	tdttjj| jd||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)r@   r1   r3   rP   rQ   )	r(   r   r)   r   r.   r*   r+   normr-   )r%   rP   rQ   r   r   r   matrix_norm   s   
rV   nc                C  s(   | j tvr	tdt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)	r(   r   r)   r   r.   r*   r+   matrix_powerr-   )r%   rW   r   r   r   rX      s   
rX   )rtolrY   Optional[Union[float, Array]]c               C  s   | j dk rtjdtjj| jdd}|du r0|jdddt| jd	d  t|j	j
 }nt|tr8|j}|jdddt|d
tjf  }ttj||kddS )z
    Array API compatible wrapper for :py:func:`np.matrix_rank <numpy.matrix_rank>`.

    See its docstring for more information.
       zA1-dimensional array given. Array must be at least two-dimensionalF
compute_uvNr1   T)r3   rP   r@   .r2   )r:   r*   r+   LinAlgErrorsvdr-   maxr8   finfor(   eps
isinstancer   asarraynewaxisr.   count_nonzero)r%   rY   r"   tolr   r   r   matrix_rank   s   
0
"rh   c                C  s(   | j dk r	tdtt| jddS )Nr[   z5x must be at least 2-dimensional for matrix_transposer1   r@   )r:   r9   r   r.   r*   swapaxesr-   r>   r   r   r   matrix_transpose   s   
rj   c                C  sN   | j tvs
|j tvrtd| jdks|jdkrtdtt| 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)
r(   r   r)   r:   r9   r   r.   r*   outerr-   rN   r   r   r   rk      s
   rk   c               C  sR   | j tvr	td|du rt| jdd t| j j }t	tj
j| j|d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 pinvNr@   )rcond)r(   r   r)   r`   r8   r*   ra   rb   r   r.   r+   pinvr-   )r%   rY   r   r   r   rm      s
   
 rm   reducedmoderp   Literal['reduced', 'complete']c               C  0   | j tvr	tdtttjtjj	| j
|d 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 qrro   )r(   r   r)   r   rG   r   r.   r*   r+   qrr-   )r%   rp   r   r   r   rs         
rs   c                C  rF   )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)r(   r   r)   r   rG   r   r.   r*   r+   slogdetr-   r>   r   r   r   ru   	  rI   ru   c                 C  s   ddl m}m}m}m}m}m}m} ddlm	}	 || \} }
||  ||  ||\}}|| |\}}|j
dkr<|	j}n|	j}||rEdnd}||}|| |||d}||j|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.linalgrv   rw   rx   ry   rz   r{   r|   r+   r}   r:   solve1solveastype)abrv   rw   rx   ry   rz   r{   r|   r}   _wraptresult_tgufuncr~   r   rr   r   r   _solve!  s   $
r   c                C  s0   | j tvs
|j tvrtdt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)r(   r   r)   r   r.   r   r-   rN   r   r   r   r   <  s   r   Tfull_matricesr   c               C  rr   )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   )r(   r   r)   r    rG   r   r.   r*   r+   r_   r-   )r%   r   r   r   r   r_   I  rt   r_   Union[Array, Tuple[Array, ...]]c                C  s*   | j tvr	tdttjj| jddS )Nz1Only floating-point dtypes are allowed in svdvalsFr\   )	r(   r   r)   r   r.   r*   r+   r_   r-   r>   r   r   r   svdvalsZ  s   
r   r[   axesr   /Union[int, Tuple[Sequence[int], Sequence[int]]]c               C  s6   | j tvs
|j tvrtdttj| j|j|dS )Nz,Only numeric dtypes are allowed in tensordotr   )r(   r   r)   r   r.   r*   	tensordotr-   )r4   r5   r   r   r   r   r   b  s   r   c            
   C  s2   | j tvr	tdtttj| j|d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 tracer@   r1   rA   )	r(   r   r)   r   r.   r*   rd   tracer-   rE   r   r   r   r   k  s   
 r   c         	      C  s   | j tvs
|j tvrtdt| j|j}d|| j  t| j }d||j  t|j }|| || kr9tdt	| j
|j
\}}t||d}t||d}|dd d d f |d  }t|d S )Nz)Only numeric dtypes are allowed in vecdot)r   z6x1 and x2 must have the same size along the given axisr1   .).N).r   r   )r(   r   r)   r`   r:   tupler8   r9   r*   broadcast_arraysr-   moveaxisr   r.   )	r4   r5   r3   r:   x1_shapex2_shapex1_x2_resr   r   r   vecdotx  s   r   rT   %Optional[Union[int, Tuple[int, ...]]]Optional[Union[int, float]]c                 s   | j tvr	td| j du r   dn7ttrNtfddt jD }| }t	
 |t	 fddD g fdd|D R  dtt	jj ||dS )	rS   z.Only floating-point dtypes are allowed in normNr   c                 3  s    | ]	}| vr|V  qd S )Nr   .0ir2   r   r   	<genexpr>  s    zvector_norm.<locals>.<genexpr>c                   s   g | ]} j | qS r   )r8   r   )r   r   r   
<listcomp>  s    zvector_norm.<locals>.<listcomp>rT   )r(   r   r)   r-   flattenrc   r   ranger:   r*   	transposereshapeprodr   r.   r+   rU   )r%   r3   rP   rQ   restnewshaper   )r   r3   r   vector_norm  s   

<r   )r,   r;   r=   rD   rH   rJ   rL   rM   rV   rX   rh   rj   rk   rm   rs   ru   r   r_   r   r   r   r   r   )r%   r   r$   r&   r'   r   )r4   r   r5   r   r3   r6   r'   r   )r%   r   r'   r   )r%   r   r?   r6   r'   r   )r%   r   r'   r   )r4   r   r5   r   r'   r   )r%   r   rP   r&   rQ   rR   r'   r   )r%   r   rW   r6   r'   r   )r%   r   rY   rZ   r'   r   )r%   r   rp   rq   r'   r   )r%   r   r'   r   )r%   r   r   r&   r'   r    )r%   r   r'   r   )r4   r   r5   r   r   r   r'   r   )
r%   r   r3   r   rP   r&   rQ   r   r'   r   )0
__future__r   _dtypesr   r   _array_objectr   typingr   _typingr   r	   r
   r   r   r   numpy.linalgnumpyr*   r   r   r   r    r,   r;   r=   rD   rH   rJ   rL   rM   rV   rX   rh   rj   rk   rm   rs   ru   r   r   r_   r   r   r   r   r   __all__r   r   r   r   <module>   sL    










	