a
    XgG                     @  s  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rd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 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/d0d1Z)dd2d3ddd4dd5d6d7Z*dddd8d9d:Z+dd;dd<dd=d>d?Z,ddd"d@dAZ-dddd/dBdCZ.dd;dd<dd=dDdEZ/dFdGddHddIdJdKZ0ddd"dLdMZ1dNdO Z2dddd/dPdQZ3dRdSddddTdUdVZ4ddWd"dXdYZ5ddZddd[dd\d]d^Z6d dd_ddd`ddadbdcZ7ddddddddddeZ8ddddfddgddhddidjdkZ9g dlZ:dS )m    )annotations   )_floating_dtypes_numeric_dtypesfloat32float64	complex64
complex128)reshape)conj)Array   )normalize_axis_tuple)TYPE_CHECKING)LiteralOptionalSequenceTupleUnionDtype)
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   d/var/www/html/cobodadashboardai.evdpl.com/venv/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  sT   | j tvrtdtj| j}|rJt|j	}|j t
tfv rFt|}|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mTr   r	   r   )r)   r'   Lr%   r   r   r   r/   -   s    
r/   axisint)x1x2r5   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 3r4   )r+   r   r,   shape
ValueErrorndimr   r1   r-   crossr0   )r7   r8   r5   r   r   r   r=   @   s    
r=   )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   r1   r-   r.   detr0   r)   r   r   r   r>   R   s    
r>   )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.
    r3   )r@   axis1axis2)r   r1   r-   diagonalr0   )r)   r@   r   r   r   rD   _   s    rD   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   r1   r-   r.   eighr0   r?   r   r   r   rF   j   s    
rF   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   r1   r-   r.   eigvalshr0   r?   r   r   r   rG   z   s    
rG   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   r1   r-   r.   invr0   r?   r   r   r   rH      s    
rH   )r7   r8   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   r1   r-   matmulr0   r7   r8   r   r   r   rI      s    rI   Zfro)keepdimsordz2Optional[Union[int, float, Literal['fro', 'nuc']]])r)   rK   rL   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)rA   r3   r5   rK   rL   )	r+   r   r,   r   r1   r-   r.   normr0   )r)   rK   rL   r   r   r   matrix_norm   s    
rP   )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   r1   r-   r.   matrix_powerr0   )r)   rQ   r   r   r   rR      s    
rR   )rtolzOptional[Union[float, Array]])r)   rS   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.
    r   zA1-dimensional array given. Array must be at least two-dimensionalFZ
compute_uvNr3   T)r5   rK   rA   .r4   )r<   r-   r.   ZLinAlgErrorsvdr0   maxr:   finfor+   eps
isinstancer   asarrayZnewaxisr1   Zcount_nonzero)r)   rS   r&   Ztolr   r   r   matrix_rank   s    
0
"r[   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_transposer3   rA   )r<   r;   r   r1   r-   Zswapaxesr0   r?   r   r   r   matrix_transpose   s    
r\   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,   r<   r;   r   r1   r-   outerr0   rJ   r   r   r   r]      s
    r]   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 pinvNrA   )Zrcond)r+   r   r,   rV   r:   r-   rW   rX   r   r1   r.   pinvr0   )r)   rS   r   r   r   r^      s
    
 r^   ZreducedmodezLiteral['reduced', 'complete'])r)   r`   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 qrr_   )r+   r   r,   r   rE   r   r1   r-   r.   qrr0   )r)   r`   r   r   r   ra     s    
ra   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"   rE   r   r1   r-   r.   slogdetr0   r?   r   r   r   rb     s    
rb   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}tj|ddddd	 || ||d
}W d    n1 s0    Y  ||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callignore)rk   invalidZoverdivideZunder)	signatureF)copy)Zlinalg.linalgrc   rd   re   rf   rg   rh   ri   r.   rj   r<   Zsolve1solver-   ZerrstateZastype)abrc   rd   re   rf   rg   rh   ri   rj   _wraptZresult_tZgufuncro   rr   r   r   _solve/  s     $
,rx   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   r1   rx   r0   rJ   r   r   r   rq   K  s    rq   Tfull_matrices)r)   rz   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 svdry   )r+   r   r,   r$   rE   r   r1   r-   r.   rU   r0   )r)   rz   r   r   r   rU   X  s    
rU   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 svdvalsFrT   )	r+   r   r,   r   r1   r-   r.   rU   r0   r?   r   r   r   svdvalsi  s    
r{   axesz/Union[int, Tuple[Sequence[int], Sequence[int]]])r7   r8   r}   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 tensordotr|   )r+   r   r,   r   r1   r-   	tensordotr0   )r7   r8   r}   r   r   r   r~   q  s    r~   )r@   r+   zOptional[Dtype])r)   r@   r+   r*   c               C  sZ   | j tvrtd|du r8| j tkr*t}n| j tkr8t}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 traceNrA   r3   )r@   rB   rC   r+   )r+   r   r,   r   r   r   r	   r   r1   r-   rZ   tracer0   )r)   r@   r+   r   r   r   r   z  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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 axisr3   .).N).r   r   )r+   r   r,   rV   r<   tupler:   r;   r-   Zbroadcast_arraysr0   Zmoveaxisr   r1   )	r7   r8   r5   r<   Zx1_shapeZx2_shapeZx1_Zx2_resr   r   r   vecdot  s    r   rN   z%Optional[Union[int, Tuple[int, ...]]]zOptional[Union[int, float]])r)   r5   rK   rL   r*   c         
        s  | j tvrtd| j |du r.   d}nt|trt|| jtfddt	 jD }|| }t
 |t
j fdd|D tdg fdd|D R  d}n|}tt
jj ||d	}|rt| j}t|du rt	| jn|| j}|D ]}	d
||	< qt|t|}|S )rM   z.Only floating-point dtypes are allowed in normNr   c                 3  s   | ]}| vr|V  qd S )Nr   .0i)normalized_axisr   r   	<genexpr>      zvector_norm.<locals>.<genexpr>c                   s   g | ]} j | qS r   )r:   r   )rr   r   r   
<listcomp>  r   zvector_norm.<locals>.<listcomp>)r+   )r5   rL   r   )r+   r   r,   r0   ZravelrY   r   r   r<   ranger-   Z	transposer
   prodr6   r   r1   r.   rO   listr:   )
r)   r5   rK   rL   Z_axisrestZnewshaper   r:   r   r   )rr   r   r   vector_norm  s.    

0

r   )r/   r=   r>   rD   rF   rG   rH   rI   rP   rR   r[   r\   r]   r^   ra   rb   rq   rU   r{   r~   r   r   r   );
__future__r   Z_dtypesr   r   r   r   r   r	   Z_manipulation_functionsr
   Z_elementwise_functionsr   Z_array_objectr   Zcore.numericr   typingr   Z_typingr   r   r   r   r   r   r   Znumpy.linalgnumpyr-   r   r   r"   r$   r/   r=   r>   rD   rF   rG   rH   rI   rP   rR   r[   r\   r]   r^   ra   rb   rx   rq   rU   r{   r~   r   r   r   __all__r   r   r   r   <module>   sP     	 -