a
    hÝEb½?  ã                   @  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   úV/home/ja/django-apps/lartica_env/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   r6   D   s    
r6   )Úoffset)r    r8   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*   ©r8   Zaxis1Zaxis2)r   r(   r$   Údiagonalr'   ©r    r8   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'   r7   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'   r7   r   r   r   r?   n   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'   r7   r   r   r   r@   {   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   rA   Š   s    rA   Zfro)ÚkeepdimsÚordz2Optional[Union[int, float, Literal['fro', 'nuc']]])r    rC   rD   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)r9   r*   ©r,   rC   rD   )	r"   r   r#   r   r(   r$   r%   Únormr'   )r    rC   rD   r   r   r   Úmatrix_normž   s    
rH   )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    rI   r   r   r   rJ   ¬   s    
rJ   )ÚrtolzOptional[Union[float, Array]])r    rK   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,   rC   r9   .r+   )r3   r$   r%   ZLinAlgErrorÚsvdr'   Úmaxr1   Úfinfor"   ÚepsÚ
isinstancer   ÚasarrayZnewaxisr(   Zcount_nonzero)r    rK   r   Ztolr   r   r   Úmatrix_rank»   s    
0
"rT   c                C  s(   | j dk rtdƒ‚t t | jdd¡¡S )NrL   z5x must be at least 2-dimensional for matrix_transposer*   r9   )r3   r2   r   r(   r$   Zswapaxesr'   r7   r   r   r   Úmatrix_transposeÓ   s    
rU   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'   rB   r   r   r   rV   Ù   s
    rV   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 pinvNr9   )Zrcond)r"   r   r#   rO   r1   r$   rP   rQ   r   r(   r%   Úpinvr'   )r    rK   r   r   r   rW   ë   s
    
 rW   Zreduced©ÚmodezLiteral['reduced', 'complete'])r    rY   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 qrrX   )r"   r   r#   r   r=   r   r(   r$   r%   Úqrr'   )r    rY   r   r   r   rZ   ü   s    
rZ   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'   r7   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}||ƒrŠdnd}||ƒ}|| |||d�}||j|dd	�ƒS )
NrL   )Ú
_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`   ra   rb   r%   rc   r3   Zsolve1ÚsolveZastype)ÚaÚbr\   r]   r^   r_   r`   ra   rb   rc   Ú_ÚwrapÚtZresult_tZgufuncrd   re   Úrr   r   r   Ú_solve#  s    $
rn   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(   rn   r'   rB   r   r   r   rg   >  s    rg   T©Úfull_matrices)r    rp   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 svdro   )r"   r   r#   r   r=   r   r(   r$   r%   rN   r'   )r    rp   r   r   r   rN   K  s    
rN   zUnion[Array, Tuple[Array, ...]]c                C  s   t  tjj| jdd�¡S )NFrM   )r   r(   r$   r%   rN   r'   r7   r   r   r   Úsvdvals\  s    rq   rL   ©Úaxesz/Union[int, Tuple[Sequence[int], Sequence[int]]])r.   r/   rs   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 tensordotrr   )r"   r   r#   r   r(   r$   Ú	tensordotr'   )r.   r/   rs   r   r   r   rt   b  s    rt   c            
   C  s    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.
    r9   r*   r:   )r   r(   r$   rS   Útracer'   r<   r   r   r   ru   k  s    ru   c               C  s   t | ||f|ffd�S )Nrr   )rt   r5   r   r   r   Úvecdotv  s    rv   rF   z%Optional[Union[int, Tuple[int, int]]]zOptional[Union[int, float]])r    r,   rC   rD   r!   c                 s¶   | j tvrtdƒ‚| j‰ ˆdu r.ˆ  ¡ ‰ d‰nntˆtƒrœt‡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 )	rE   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   rw   )rh   r   r   Ú
<listcomp>“  r{   zvector_norm.<locals>.<listcomp>rF   )r"   r   r#   r'   ÚflattenrR   ÚtupleÚranger3   r$   Z	transposeZreshapeÚprodr   r(   r%   rG   )r    r,   rC   rD   ÚrestZnewshaper   )rh   r,   r   Úvector_norm  s    

<r‚   )r&   r4   r6   r;   r>   r?   r@   rA   rH   rJ   rT   rU   rV   rW   rZ   r[   rg   rN   rq   rt   ru   rv   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   r6   r;   r>   r?   r@   rA   rH   rJ   rT   rU   rV   rW   rZ   r[   rn   rg   rN   rq   rt   ru   rv   r‚   Ú__all__r   r   r   r   Ú<module>   sJ   		 