
    `i                     ^    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Z	dd	Z
dd
ZdS )    N)device)runtime)_util)_dtypeFc                 >   ddl m} ddl m} |dvrt          d          t	          j        | d          \  }}|j                                        }|j                                        }	|                     |d| 	          }
| j	        \  }}t          j        ||          }t          j        d
t          j                  }t          j                    j        }|r|j        }n|j        }|dk    r|j        }n|j        }t*          j        sf|j        dvrt/          d          t1          j        |          }t1          j        |          }|                                }	 |                    |||||||
j        j        |||j        j        |          \  }}t          j        |d          }t          j        |d          }|                    |||||||
j        j        |||j        j        ||j        j        ||j        j        ||j        j                   |                     |           n# |                     |           w xY wt          j!        j        "                    |j        |           n|dk    r|j#        }|j$        }nN|dk    r|j%        }|j&        }n9|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        j        
  
         t          j!        j        "                    ||           |                    |	d          |
                    |d          fS )Nr   )cublas)cusolver)LUz UPLO argument must be 'L' or 'U'F)reject_float16F)ordercopy r
   fdFDz>Only float32, float64, complex64, and complex128 are supportedbfdD)r   )+cupy_backends.cuda.libsr   r	   
ValueErrorr   linalg_common_typecharlowerastypeshapecupyemptynumpyint32r   Devicecusolver_handleCUSOLVER_EIG_MODE_VECTORCUSOLVER_EIG_MODE_NOVECTORCUBLAS_FILL_MODE_LOWERCUBLAS_FILL_MODE_UPPERr   is_hipRuntimeErrorr   to_cuda_dtypecreateParamsxsyevd_bufferSizedataptrxsyevdctypesdestroyParamslinalg3_check_cusolver_dev_info_if_synchronization_allowedssyevd_bufferSizessyevddsyevd_bufferSizedsyevdcheevd_bufferSizecheevdzheevd_bufferSizezheevd)aUPLOwith_eigen_vectoroverwrite_ar   r	   dtypev_dtype
real_dtypew_dtypevmldawdev_infohandlejobzuplotype_vtype_wparamswork_device_sizework_host_sizsework_device	work_hostbuffer_sizesyevd	work_sizeworks                                k/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/linalg/_eigenvalue.py_syevdrW   
   s   ......000000:?@@@ -aFFFNE7!!##Jl  ""G 	
cK88AWFAs
1j!!Az"ek**H]__,F 302s{{,,> .:V##  : ; ; ;%e,,%j11&&((	+080J0JdAvqvz3
F1, 1,-o *%5s;;KOS99IOOdAvqvz3
F $&6 %8I	K K K ""6****H""6****MMOX	' 	' 	' 	' C<<"4KOEEc\\"4KOEEc\\"4KOEEc\\"4KOEE  : ; ; ;  KD$16:sAFJ@ @	z)U++D$16:sFJ	y(-2C	E 	E 	E 	MM8	 	 	 88G%8((!((7(*G*GGGs   "B6H. .Ir
   c                    ddl }t          j        |            t          j        |            | j        dk    rpt          j        |           \  }}|j                                        }t          j	        | j
        dd         |          }t          j	        | j
        |          }||fS | j        dk    st          j        r#|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cupyx.cusolverr   _assert_stacked_2d_assert_stacked_squaresizer   r   r   r   r   r   ndimr   r'   r	   syevjrW   )r;   r<   cupyx_r@   rB   rF   rC   s           rV   eighrd   ^   s    @ 	Q	 ###v{{-a00
7,$$&&Jqwss|W--Jqw((!tvzzW^z~##AtT221!tat$$$    c                    ddl }t          j        |            t          j        |            | j        dk    rRt          j        |           \  }}|j                                        }t          j	        | j
        dd         |          S | j        dk    st          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   NrY   rZ   Fr[   )r;   r<   rb   rc   r@   rB   s         rV   eigvalshrg      s    4 	Q	 ###v{{-a00
7,$$&&z!'#2#,000vzzW^z~##AtU333au%%a((re   )F)r
   )r   r   	cupy.cudar   r   cupy.linalgr   
cupy._corer   rW   rd   rg   r   re   rV   <module>rk      s                             NH NH NH NHh/% /% /% /%j&) &) &) &) &) &)re   