o
    Õ0 i  ć                   @   sb   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZ dddZ	dd
dZ
dddZdS )é    N)Śdevice)Śruntime)Ś_util)Ś_dtypeFc                 C   sv  ddl m} ddl m} |dvrtdtj| dd\}}|j ” }|j ” }	| j|d| d	}
| j	\}}t
 ||”}t
 d
tj”}t ” j}|rM|j}n|j}|dkrX|j}n|j}tjsĢ|jdvrgtdt |”}t |”}| ” }zF| |||||||
jj|||jj|”\}}t
 |d”}t |d”}| |||||||
jj|||jj||jj||jj||jj” W |  |” n|  |” w t
j!j "|j|” na|dkr×|j#}|j$}n%|dkrā|j%}|j&}n|dkrķ|j'}|j(}n|dkrų|j)}|j*}ntd||||||
jj||jj}t
 ||”}||||||
jj||jj|jj||jj
 t
j!j "||” |j|	dd|
j|ddfS )Nr   )Ścublas)Ścusolver)ŚLŚUz UPLO argument must be 'L' or 'U'F)Zreject_float16ŚF)ŚorderŚcopy© r   ZfdFDz>Only float32, float64, complex64, and complex128 are supportedŚbŚfŚdŚD)r   )+Zcupy_backends.cuda.libsr   r   Ś
ValueErrorr   Ślinalg_common_typeŚcharŚlowerZastypeŚshapeŚcupyŚemptyŚnumpyZint32r   ZDeviceZcusolver_handleZCUSOLVER_EIG_MODE_VECTORZCUSOLVER_EIG_MODE_NOVECTORZCUBLAS_FILL_MODE_LOWERZCUBLAS_FILL_MODE_UPPERr   Śis_hipŚRuntimeErrorr   Zto_cuda_dtypeZcreateParamsZxsyevd_bufferSizeŚdataZptrZxsyevdŚctypesZdestroyParamsZlinalgZ3_check_cusolver_dev_info_if_synchronization_allowedZssyevd_bufferSizeZssyevdZdsyevd_bufferSizeZdsyevdZcheevd_bufferSizeZcheevdZzheevd_bufferSizeZzheevd)ŚaŚUPLOZwith_eigen_vectorZoverwrite_ar   r   ZdtypeŚv_dtypeZ
real_dtypeŚw_dtypeŚvŚmZldaŚwZdev_infoŚhandleZjobzZuploZtype_vZtype_wŚparamsZwork_device_sizeZwork_host_sizseZwork_deviceZ	work_hostŚbuffer_sizeZsyevdZ	work_sizeZworkr   r   śc/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/cupy/linalg/_eigenvalue.pyŚ_syevd
   s   







ž
ü’’ž’r)   r   c                 C   s¢   ddl }t | ” t | ” | jdkr5t | ”\}}|j ” }t 	| j
dd |”}t 	| j
|”}||fS | jdks=tjrK|j | |d”\}}||fS t| |dS )a¢  
    Return the eigenvalues and eigenvectors of a complex Hermitian
    (conjugate symmetric) or a real symmetric matrix.

    Returns two objects, a 1-D array containing the eigenvalues of `a`, and
    a 2-D square array or matrix (depending on the input type) of the
    corresponding eigenvectors (in columns).

    Args:
        a (cupy.ndarray): A symmetric 2-D square matrix ``(M, M)`` or a batch
            of symmetric 2-D square matrices ``(..., M, M)``.
        UPLO (str): Select from ``'L'`` or ``'U'``. It specifies which
            part of ``a`` is used. ``'L'`` uses the lower triangular part of
            ``a``, and ``'U'`` uses the upper triangular part of ``a``.
    Returns:
        tuple of :class:`~cupy.ndarray`:
            Returns a tuple ``(w, v)``. ``w`` contains eigenvalues and
            ``v`` contains eigenvectors. ``v[:, i]`` is an eigenvector
            corresponding to an eigenvalue ``w[i]``. For batch input,
            ``v[k, :, i]`` is an eigenvector corresponding to an eigenvalue
            ``w[k, i]`` of ``a[k]``.

    .. warning::
        This function calls one or more cuSOLVER routine(s) which may yield
        invalid results if input conditions are not met.
        To detect these invalid results, you can set the `linalg`
        configuration to a value that is not `ignore` in
        :func:`cupyx.errstate` or :func:`cupyx.seterr`.

    .. seealso:: :func:`numpy.linalg.eigh`
    r   Né’’’’é   T©Zcupyx.cusolverr   Z_assert_stacked_2dZ_assert_stacked_squareŚsizer   r   r   r   r   r   Śndimr   r   r   Zsyevjr)   )r   r   ŚcupyxŚ_r    r!   r$   r"   r   r   r(   Śeigh^   s    



r1   c                 C   s   ddl }t | ” t | ” | jdkr*t | ”\}}|j ” }t 	| j
dd |”S | jdks2tjr:|j | |d”S t| |dd S )a-  
    Compute the eigenvalues of a complex Hermitian or real symmetric matrix.

    Main difference from eigh: the eigenvectors are not computed.

    Args:
        a (cupy.ndarray): A symmetric 2-D square matrix ``(M, M)`` or a batch
            of symmetric 2-D square matrices ``(..., M, M)``.
        UPLO (str): Select from ``'L'`` or ``'U'``. It specifies which
            part of ``a`` is used. ``'L'`` uses the lower triangular part of
            ``a``, and ``'U'`` uses the upper triangular part of ``a``.
    Returns:
        cupy.ndarray:
            Returns eigenvalues as a vector ``w``. For batch input,
            ``w[k]`` is a vector of eigenvalues of matrix ``a[k]``.

    .. warning::
        This function calls one or more cuSOLVER routine(s) which may yield
        invalid results if input conditions are not met.
        To detect these invalid results, you can set the `linalg`
        configuration to a value that is not `ignore` in
        :func:`cupyx.errstate` or :func:`cupyx.seterr`.

    .. seealso:: :func:`numpy.linalg.eigvalsh`
    r   Nr*   r+   Fr,   )r   r   r/   r0   r    r!   r   r   r(   Śeigvalsh   s   



r2   )F)r   )r   r   Z	cupy.cudar   r   Zcupy.linalgr   Z
cupy._corer   r)   r1   r2   r   r   r   r(   Ś<module>   s    

T5