U
    d
                     @   s   d Z ddlmZ ddlZddlmZ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eeeeef dd d!ZdS )#z:Various linear algebra utility methods for internal use.

    )TensorN)OptionalTuplec                 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-ua33x9lu/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 )z9Return transpose of a matrix or batches of matrices.
          )lenshape	transpose)r
   ndimr   r   r   r   7   s    
r   c                 C   s   t t| S )zCReturn 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 )z7Return bilinear form of matrices: :math:`X^T A Y`.
    )r   r   )r   r
   r   r   r   r   bformD   s    r    r
   Sc                 C   s   t || |S )z+Return quadratic form :math:`S^T A S`.
    )r    r!   r   r   r   qformJ   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   basisP   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 )z4Return eigenpairs of A with specified ordering.
    NFU)ZUPLO))Zdims)r   r$   ZeighZflip)r
   r'   EZr   r   r   symeig[   s    r,   )out)inputr
   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.)RuntimeError)r.   r
   r-   r   r   r   solvei   s    r0   )F)__doc__r   r   typingr   r   r   r   r   r   r   r   r    r#   r&   boolr,   r0   r   r   r   r   <module>   s   

 