U
    eE                     @  s  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rld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/d0Z"dd1d2ddd3dd4d5d6Z#dddd7d8d9Z$dd:dd;dd<d=d>Z%ddd!d?d@Z&dddd.dAdBZ'dd:dd;dd<dCdDZ(dEdFddGddHdIdJZ)ddd!dKdLZ*dMdN Z+dddd.dOdPZ,dQdRddddSdTdUZ-ddVd!dWdXZ.ddYdddZdd[d\d]Z/d d$dddd%d^d_Z0dddddddd`daZ1ddddbddcdddddedfdgZ2dd d#d'd)d+d-d0d6d9d>d@dBdDdJdLdPdUdXd]d_dadggZ3dS )h    )annotations   )_floating_dtypes_numeric_dtypes)reshape)Array   )normalize_axis_tuple)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   W/var/www/html/assets/scripts/venv/lib/python3.8/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k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ks|j tk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*   )r1   r2   r/   r   r   r   r7   5   s    
r7   )r#   r$   c                C  s&   | j tk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   r8   G   s    
r8   )offset)r#   r:   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-   r:   Zaxis1Zaxis2)r   r+   r'   diagonalr*   r#   r:   r   r   r   r=   T   s    r=   c                C  s,   | j tk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*   r9   r   r   r   r@   _   s    
r@   c                C  s&   | j tk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*   r9   r   r   r   rA   o   s    
rA   c                C  s&   | j tk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*   r9   r   r   r   rB   |   s    
rB   )r1   r2   r$   c                C  s2   | j tks|j tk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*   r1   r2   r   r   r   rC      s    rC   Zfro)keepdimsordz4Optional[Union[int, float, Literal[('fro', 'nuc')]]])r#   rE   rF   r$   c               C  s.   | j tk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;   r-   r/   rE   rF   )	r%   r   r&   r   r+   r'   r(   normr*   )r#   rE   rF   r   r   r   matrix_norm   s    
rJ   )r#   nr$   c                C  s(   | j tk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#   rK   r   r   r   rL      s    
rL   )rtolzOptional[Union[float, Array]])r#   rM   r$   c               C  s   | j dk rtjdtjj| jdd}|dk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.
    r   zA1-dimensional array given. Array must be at least two-dimensionalFZ
compute_uvNr-   T)r/   rE   r;   .r.   )r6   r'   r(   ZLinAlgErrorsvdr*   maxr4   finfor%   eps
isinstancer   asarrayZnewaxisr+   Zcount_nonzero)r#   rM   r    Ztolr   r   r   matrix_rank   s    
0
"rU   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_transposer-   r;   )r6   r5   r   r+   r'   Zswapaxesr*   r9   r   r   r   matrix_transpose   s    
rV   c                C  sN   | j tks|j tk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&   r6   r5   r   r+   r'   outerr*   rD   r   r   r   rW      s
    rW   c               C  sR   | j tkrtd|dk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;   )Zrcond)r%   r   r&   rP   r4   r'   rQ   rR   r   r+   r(   pinvr*   )r#   rM   r   r   r   rX      s
    
 rX   Zreducedmodez Literal[('reduced', 'complete')])r#   rZ   r$   c               C  s0   | j tk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 qrrY   )r%   r   r&   r   r?   r   r+   r'   r(   qrr*   )r#   rZ   r   r   r   r[      s    
r[   c                C  s,   | j tk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*   r9   r   r   r   r\     s    
r\   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 )
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)Zlinalg.linalgr]   r^   r_   r`   ra   rb   rc   r(   rd   r6   Zsolve1solveZastype)abr]   r^   r_   r`   ra   rb   rc   rd   _wraptZresult_tZgufuncre   rf   rr   r   r   _solve$  s    $
ro   c                C  s0   | j tks|j tk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+   ro   r*   rD   r   r   r   rh   ?  s    rh   Tfull_matrices)r#   rq   r$   c               C  s0   | j tk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 svdrp   )r%   r   r&   r   r?   r   r+   r'   r(   rO   r*   )r#   rq   r   r   r   rO   L  s    
rO   zUnion[Array, Tuple[Array, ...]]c                C  s*   | j tkrtdttjj| jddS )Nz1Only floating-point dtypes are allowed in svdvalsFrN   )	r%   r   r&   r   r+   r'   r(   rO   r*   r9   r   r   r   svdvals]  s    
rr   axesz/Union[int, Tuple[Sequence[int], Sequence[int]]])r1   r2   rt   r$   c               C  s6   | j tks|j tkrtdttj| j|j|dS )Nz,Only numeric dtypes are allowed in tensordotrs   )r%   r   r&   r   r+   r'   	tensordotr*   )r1   r2   rt   r   r   r   ru   e  s    ru   c            
   C  s2   | j tk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;   r-   r<   )	r%   r   r&   r   r+   r'   rT   tracer*   r>   r   r   r   rv   n  s    
rv   c         	      C  s   | j tks|j tk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&   rP   r6   tupler4   r5   r'   Zbroadcast_arraysr*   Zmoveaxisr   r+   )	r1   r2   r/   r6   Zx1_shapeZx2_shapeZx1_Zx2_resr   r   r   vecdot{  s    ry   rH   z%Optional[Union[int, Tuple[int, ...]]]zOptional[Union[int, float]])r#   r/   rE   rF   r$   c         
        s  | j tkrtd| j |dkr.   d}nt|trt|| jtfddt	 jD }|| }t
 |t
j fdd|D tdf fdd|D  d}n|}tt
jj ||d	}|rt| j}t|dkrt	| jn|| j}|D ]}	d
||	< qt|t|}|S )rG   z.Only floating-point dtypes are allowed in normNr   c                 3  s   | ]}| kr|V  qd S )Nr   .0i)normalized_axisr   r   	<genexpr>  s      zvector_norm.<locals>.<genexpr>c                   s   g | ]} j | qS r   )r4   rz   )ri   r   r   
<listcomp>  s     zvector_norm.<locals>.<listcomp>)r%   )r/   rF   r   )r%   r   r&   r*   ZravelrS   rw   r	   r6   ranger'   Z	transposer   prodr0   r   r+   r(   rI   listr4   )
r#   r/   rE   rF   Z_axisrestZnewshaperx   r4   r|   r   )ri   r}   r   vector_norm  s.    

.

r   )4
__future__r   Z_dtypesr   r   Z_manipulation_functionsr   Z_array_objectr   Zcore.numericr	   typingr
   Z_typingr   r   r   r   r   r   Znumpy.linalgnumpyr'   r   r   r   r   r)   r7   r8   r=   r@   rA   rB   rC   rJ   rL   rU   rV   rW   rX   r[   r\   ro   rh   rO   rr   ru   rv   ry   r   __all__r   r   r   r   <module>   sN   	 -