U
    Kc                     @   s8  d Z ddlmZmZ ddlZddlmZ dd Zdd Zee eed	d
dZdd Z	dd Z
dd Zeee eedddZee edddZdd Zd+eee eeef dddZd,ddedd d!Zddeeeeef d"d#d$Zddeeeeef d"d%d&Zd-ddd'eeeeef d(d)d*ZdS ).z:Various linear algebra utility methods for internal use.

    )OptionalTupleN)Tensorc                 C   sD   t | tjr| jtjkS d}tj s8|dt| 7 }t	|dS )z$Check if tensor A is a sparse tensorzexpected Tensorz but got {}N)

isinstancetorchr   ZlayoutZ
sparse_cooZjitZis_scriptingformattype	TypeError)AZ	error_str r   7/tmp/pip-unpacked-wheel-gikjz4vx/torch/_linalg_utils.py	is_sparse   s    
r   c                 C   s$   | j }|tjtjtjfkr|S tjS )zTReturn the floating point dtype of tensor A.

    Integer types map to float32.
    )dtyper   Zfloat16Zfloat32Zfloat64)r
   r   r   r   r   get_floating_dtype   s    r   )r
   Breturnc                 C   s.   | dkr|S t | r"tj| |S t| |S )ziMultiply two matrices.

    If A is None, return B. A can be sparse or dense. B is always
    dense.
    N)r   r   sparsemmmatmul)r
   r   r   r   r   r   !   s
    r   c                 C   s   |   r|  S | S )z]Return conjugate of tensor A.

    .. note:: If A's dtype is not complex, A is returned.
    )Z
is_complexZconjr
   r   r   r   	conjugate.   s    r   c                 C   s   t | j}| |d |d S )z4Return transpose of a matrix or batches of matrices.      )lenshape	transpose)r
   ndimr   r   r   r   8   s    
r   c                 C   s   t t| S )z>Return transpose conjugate of a matrix or batches of matrices.)r   r   r   r   r   r   transjugate>   s    r   )Xr
   Yr   c                 C   s   t t| t ||S )z2Return bilinear form of matrices: :math:`X^T A Y`.)r   r   )r   r
   r   r   r   r   bformC   s    r    r
   Sc                 C   s   t || |S )z&Return quadratic form :math:`S^T A S`.)r    r!   r   r   r   qformH   s    r#   c                 C   s*   | j rtj| j}ntjt|  }|S )z%Return orthogonal basis of A columns.)Zis_cudar   linalgZqrQZorgqrZgeqrf)r
   r%   r   r   r   basisM   s    r&   F)r
   largestr   c                 C   sH   |dkrd}t jj| dd\}}|r@t j|dd}t j|dd}||fS )z/Return eigenpairs of A with specified ordering.NFU)ZUPLO))Zdims)r   r$   ZeighZflip)r
   r'   EZr   r   r   symeigW   s    r,   )out)r   c                C   s   t ddd S )NBThis function was deprecated since version 1.9 and is now removed.z;Please use the `torch.linalg.matrix_rank` function instead.RuntimeError)inputZtolZ	symmetricr-   r   r   r   matrix_ranke   s    r2   )r1   r
   r   c                C   s   t dd S )NzxThis function was deprecated since version 1.9 and is now removed. Please use the `torch.linalg.solve` function instead.r/   r1   r
   r-   r   r   r   solvel   s    r4   c                C   s   t ddd S )Nr.   z5Please use the `torch.linalg.lstsq` function instead.r/   r3   r   r   r   lstsqr   s    r5   )ev)selfeigenvectorsr   c                C   s   t dd S )NzvThis function was deprecated since version 1.9 and is now removed. Please use the `torch.linalg.eig` function instead.r/   )r8   r9   r6   r7   r   r   r   eigy   s    r:   )F)NF)F)__doc__typingr   r   r   r   r   r   r   r   r   r   r    r#   r&   boolr,   r2   r4   r5   r:   r   r   r   r   <module>   s2   

      
