a
    p=icDB                     @  s  d dl mZ ddlmZmZ ddlmZ d dlmZ erTd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ddddddZdddddddddZddddd Zd d!dddd"d#d$Zdd
dd%d&Zdddd'd(Zdddd)d*Zdddd+d,d-Zdd.d/ddd0dd1d2d3Zdddd4d5d6Z dd7dd8dd9d:d;Z!dddd<d=Z"dddd+d>d?Z#dd7dd8dd9d@dAZ$dBdCddDddEdFdGZ%ddddHdIZ&dJdK Z'dddd+dLdMZ(dNdOddddPdQdRZ)ddSddTdUZ*dVdWdddXddYdZd[Z+d d!dddd"d\d]Z,dddddddd^d_Z-dddVd`ddaddbddcdddeZ.g dfZ/dS )g    )annotations   )_floating_dtypes_numeric_dtypes)Array)TYPE_CHECKING)LiteralOptionalSequenceTupleUnion)
NamedTupleNc                   @  s   e Zd ZU ded< ded< dS )
EighResultr   ZeigenvaluesZeigenvectorsN__name__
__module____qualname____annotations__ r   r   g/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/numpy/array_api/linalg.pyr      s   
r   c                   @  s   e Zd ZU ded< ded< dS )QRResultr   QRNr   r   r   r   r   r      s   
r   c                   @  s   e Zd ZU ded< ded< dS )SlogdetResultr   signZ	logabsdetNr   r   r   r   r   r      s   
r   c                   @  s&   e Zd ZU ded< ded< ded< dS )	SVDResultr   USZVhNr   r   r   r   r   r      s   
r   F)upperr   bool)xr   returnc               C  s:   | j tvrtdtj| j}|r0t|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   _newZmT)r    r   Lr   r   r   r&   "   s    
r&   axisint)x1x2r,   r!   c               C  sr   | j tvs|j tvrtd| j|jkr0td| jdkrBtd| j| dkrXt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 3r+   )r"   r   r#   shape
ValueErrorndimr   r(   r$   crossr'   )r.   r/   r,   r   r   r   r4   2   s    
r4   )r    r!   c                C  s&   | 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   r5   D   s    
r5   )offset)r    r7   r!   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.
    r*   r7   Zaxis1Zaxis2)r   r(   r$   diagonalr'   r    r7   r   r   r   r:   Q   s    r:   c                C  s,   | 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'   r6   r   r   r   r=   \   s    
r=   c                C  s&   | j tvrtdt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)	r"   r   r#   r   r(   r$   r%   eigvalshr'   r6   r   r   r   r>   l   s    
r>   c                C  s&   | j tvrtdt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)	r"   r   r#   r   r(   r$   r%   invr'   r6   r   r   r   r?   y   s    
r?   )r.   r/   r!   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'   r.   r/   r   r   r   r@      s    r@   Zfro)keepdimsordz2Optional[Union[int, float, Literal['fro', 'nuc']]])r    rB   rC   r!   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)r8   r*   r,   rB   rC   )	r"   r   r#   r   r(   r$   r%   normr'   )r    rB   rC   r   r   r   matrix_norm   s    
rG   )r    nr!   c                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    rH   r   r   r   rI      s    
rI   )rtolzOptional[Union[float, Array]])r    rJ   r!   c               C  s   | j dk rtjdtjj| jdd}|du r`|jdddt| jd	d  t|j	j
 }n2t|trp|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Z
compute_uvNr*   T)r,   rB   r8   .r+   )r3   r$   r%   ZLinAlgErrorsvdr'   maxr1   finfor"   eps
isinstancer   asarrayZnewaxisr(   Zcount_nonzero)r    rJ   r   Ztolr   r   r   matrix_rank   s    
0
"rS   c                C  s(   | j dk rtdtt| jddS )NrK   z5x must be at least 2-dimensional for matrix_transposer*   r8   )r3   r2   r   r(   r$   Zswapaxesr'   r6   r   r   r   matrix_transpose   s    
rT   c                C  sN   | j tvs|j tvrtd| jdks0|jdkr8t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#   r3   r2   r   r(   r$   outerr'   rA   r   r   r   rU      s
    rU   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 pinvNr8   )Zrcond)r"   r   r#   rN   r1   r$   rO   rP   r   r(   r%   pinvr'   )r    rJ   r   r   r   rV      s
    
 rV   ZreducedmodezLiteral['reduced', 'complete'])r    rX   r!   c               C  s0   | 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 qrrW   )r"   r   r#   r   r<   r   r(   r$   r%   qrr'   )r    rX   r   r   r   rY      s    
rY   c                C  s,   | 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)r"   r   r#   r   r<   r   r(   r$   r%   slogdetr'   r6   r   r   r   rZ   	  s    
rZ   c                 C  s   ddl m}m}m}m}m}m}m} ddlm	}	 || \} }
||  ||  ||\}}|| |\}}|j
dkrx|	j}n|	j}||rdnd}||}|| |||d}||j|dd	S )
NrK   )
_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)Zlinalg.linalgr[   r\   r]   r^   r_   r`   ra   r%   rb   r3   Zsolve1solveZastype)abr[   r\   r]   r^   r_   r`   ra   rb   _wraptZresult_tZgufuncrc   rd   rr   r   r   _solve!  s    $
rm   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(   rm   r'   rA   r   r   r   rf   <  s    rf   Tfull_matrices)r    ro   r!   c               C  s0   | 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.svd <numpy.linalg.svd>`.

    See its docstring for more information.
    z-Only floating-point dtypes are allowed in svdrn   )r"   r   r#   r   r<   r   r(   r$   r%   rM   r'   )r    ro   r   r   r   rM   I  s    
rM   z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 svdvalsFrL   )	r"   r   r#   r   r(   r$   r%   rM   r'   r6   r   r   r   svdvalsZ  s    
rp   rK   axesz/Union[int, Tuple[Sequence[int], Sequence[int]]])r.   r/   rr   r!   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 tensordotrq   )r"   r   r#   r   r(   r$   	tensordotr'   )r.   r/   rr   r   r   r   rs   b  s    rs   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 tracer8   r*   r9   )	r"   r   r#   r   r(   r$   rR   tracer'   r;   r   r   r   rt   k  s    
rt   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rrt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 axisr*   .).N).r   r   )r"   r   r#   rN   r3   tupler1   r2   r$   Zbroadcast_arraysr'   Zmoveaxisr   r(   )	r.   r/   r,   r3   Zx1_shapeZx2_shapeZx1_Zx2_resr   r   r   vecdotx  s    rw   rE   z%Optional[Union[int, Tuple[int, ...]]]zOptional[Union[int, float]])r    r,   rB   rC   r!   c                 s   | j tvrtd| j du r.   dnnttrt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 )	rD   z.Only floating-point dtypes are allowed in normNr   c                 3  s   | ]}| vr|V  qd S )Nr   .0ir+   r   r   	<genexpr>      zvector_norm.<locals>.<genexpr>c                   s   g | ]} j | qS r   )r1   rx   )rg   r   r   
<listcomp>  r|   zvector_norm.<locals>.<listcomp>rE   )r"   r   r#   r'   flattenrQ   ru   ranger3   r$   Z	transposeZreshapeprodr   r(   r%   rF   )r    r,   rB   rC   restZnewshaper   )rg   r,   r   vector_norm  s    

<r   )r&   r4   r5   r:   r=   r>   r?   r@   rG   rI   rS   rT   rU   rV   rY   rZ   rf   rM   rp   rs   rt   rw   r   )0
__future__r   Z_dtypesr   r   Z_array_objectr   typingr   Z_typingr   r	   r
   r   r   r   Znumpy.linalgnumpyr$   r   r   r   r   r&   r4   r5   r:   r=   r>   r?   r@   rG   rI   rS   rT   rU   rV   rY   rZ   rm   rf   rM   rp   rs   rt   rw   r   __all__r   r   r   r   <module>   sJ   	 