o
    T=ºiëC  ã                   @  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   ZeigenvaluesZeigenvectorsN©Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© r   r   ú\C:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\numpy/array_api/linalg.pyr      ó   
 r   c                   @  r   )ÚQRResultr   ÚQÚRNr   r   r   r   r   r      r   r   c                   @  r   )ÚSlogdetResultr   ÚsignZ	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ÚSZ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 choleskyN)
Údtyper   Ú	TypeErrorÚnpÚlinalgÚcholeskyÚ_arrayr   Ú_newZmT)r!   r    ÚLr   r   r   r(   "   s   

r(   éÿÿÿÿ©ÚaxisÚx1Úx2r.   Ú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 3r-   N)r$   r   r%   ÚshapeÚ
ValueErrorÚndimr   r*   r&   Úcrossr)   )r/   r0   r.   r   r   r   r6   2   s   
r6   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 detN)	r$   r   r%   r   r*   r&   r'   Údetr)   ©r!   r   r   r   r8   D   s   
r8   )Ú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.
    éþÿÿÿr,   ©r:   Zaxis1Zaxis2N)r   r*   r&   Údiagonalr)   ©r!   r:   r   r   r   r=   Q   s   r=   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 eighN)r$   r   r%   r   Úmapr   r*   r&   r'   Úeighr)   r9   r   r   r   rA   \   ó   
rA   c                C  r7   )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 eigvalshN)	r$   r   r%   r   r*   r&   r'   Úeigvalshr)   r9   r   r   r   rC   l   ó   
rC   c                C  r7   )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 invN)	r$   r   r%   r   r*   r&   r'   Úinvr)   r9   r   r   r   rE   y   rD   rE   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 matmulN)r$   r   r%   r   r*   r&   Úmatmulr)   ©r/   r0   r   r   r   rF   ˆ   s   rF   Zfro)ÚkeepdimsÚordrH   rI   ú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;   r,   ©r.   rH   rI   N)	r$   r   r%   r   r*   r&   r'   Únormr)   )r!   rH   rI   r   r   r   Úmatrix_normœ   s   
rN   Ú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_powerN)	r$   r   r%   r   r*   r&   r'   Úmatrix_powerr)   )r!   rO   r   r   r   rP   ª   s   
rP   )ÚrtolrQ   ú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©Z
compute_uvNr,   T)r.   rH   r;   .r-   )r5   r&   r'   ZLinAlgErrorÚsvdr)   Úmaxr3   Úfinfor$   ÚepsÚ
isinstancer   ÚasarrayZnewaxisr*   Zcount_nonzero)r!   rQ   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 )NrS   z5x must be at least 2-dimensional for matrix_transposer,   r;   )r5   r4   r   r*   r&   Zswapaxesr)   r9   r   r   r   Úmatrix_transposeÑ   s   
r\   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-dimensionalN)
r$   r   r%   r5   r4   r   r*   r&   Úouterr)   rG   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 pinvNr;   )Zrcond)r$   r   r%   rV   r3   r&   rW   rX   r   r*   r'   Úpinvr)   )r!   rQ   r   r   r   r^   é   s
   
 r^   Zreduced©Úmoder`   ú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 qrr_   N)r$   r   r%   r   r@   r   r*   r&   r'   Úqrr)   )r!   r`   r   r   r   rc   ú   ó   
rc   c                C  r?   )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 slogdetN)r$   r   r%   r   r@   r   r*   r&   r'   Úslogdetr)   r9   r   r   r   re   	  rB   re   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 )
NrS   )Ú
_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.linalgrf   rg   rh   ri   rj   rk   rl   r'   rm   r5   Zsolve1ÚsolveZastype)ÚaÚbrf   rg   rh   ri   rj   rk   rl   rm   Ú_ÚwrapÚtZresult_tZgufuncrn   ro   Ú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 solveN)r$   r   r%   r   r*   rx   r)   rG   r   r   r   rq   <  s   rq   T©Úfull_matricesrz   c               C  rb   )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   N)r$   r   r%   r   r@   r   r*   r&   r'   rU   r)   )r!   rz   r   r   r   rU   I  rd   rU   ú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   r*   r&   r'   rU   r)   r9   r   r   r   ÚsvdvalsZ  s   
r|   rS   ©Ú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)   )r/   r0   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;   r,   r<   N)	r$   r   r%   r   r*   r&   rZ   Útracer)   r>   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 axisr,   .).N).r   r   )r$   r   r%   rV   r5   Útupler3   r4   r&   Zbroadcast_arraysr)   Zmoveaxisr   r*   )	r/   r0   r.   r5   Zx1_shapeZx2_shapeZx1_Zx2_Úresr   r   r   Úvecdotx  s   r„   rL   ú%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 )	rK   z.Only floating-point dtypes are allowed in normNr   c                 3  s   � | ]	}|ˆ vr|V  qd S )Nr   ©Ú.0Úir-   r   r   Ú	<genexpr>   s   € zvector_norm.<locals>.<genexpr>c                   s   g | ]}ˆ j | ‘qS r   )r3   r‡   )rr   r   r   Ú
<listcomp>¢  s    zvector_norm.<locals>.<listcomp>rL   )r$   r   r%   r)   ÚflattenrY   r‚   Úranger5   r&   Z	transposeZreshapeÚprodr   r*   r'   rM   )r!   r.   rH   rI   ÚrestZnewshaper   )rr   r.   r   Úvector_normŽ  s   

<r�   )r(   r6   r8   r=   rA   rC   rE   rF   rN   rP   r[   r\   r]   r^   rc   re   rq   rU   r|   r€   r�   r„   r�   )r!   r   r    r"   r#   r   )r/   r   r0   r   r.   r1   r#   r   )r!   r   r#   r   )r!   r   r:   r1   r#   r   )r!   r   r#   r   )r/   r   r0   r   r#   r   )r!   r   rH   r"   rI   rJ   r#   r   )r!   r   rO   r1   r#   r   )r!   r   rQ   rR   r#   r   )r!   r   r`   ra   r#   r   )r!   r   r#   r   )r!   r   rz   r"   r#   r   )r!   r   r#   r{   )r/   r   r0   r   r~   r   r#   r   )
r!   r   r.   r…   rH   r"   rI   r†   r#   r   )0Ú
__future__r   Z_dtypesr   r   Z_array_objectr   Útypingr   Z_typingr   r	   r
   r   r   r   Znumpy.linalgZnumpyr&   r   r   r   r   r(   r6   r8   r=   rA   rC   rE   rF   rN   rP   r[   r\   r]   r^   rc   re   rx   rq   rU   r|   r€   r�   r„   r�   Ú__all__r   r   r   r   Ú<module>   sL    










	