
    Pg3              
       Z   d Z ddlmZmZ ddlZddlmZ d Zd Zdee   ded	efd
Zdedee   ded	efdZ	dee   defdZ
d Zddedee   d	eeef   fdZdddd	efdZdddeded	eeef   fdZdddeded	eeef   fdZ	 	 dddd	eeef   fdZ	 dddddeded	eeef   fdZy) z8Various linear algebra utility methods for internal use.    )OptionalTupleN)Tensorc                     t        | t        j                        r| j                  t        j                  k(  S d}t        j
                  j                         s|dt        |        z  }t        |      )z$Check if tensor A is a sparse tensorzexpected Tensorz	 but got )	
isinstancetorchr   layout
sparse_coojitis_scriptingtype	TypeError)A	error_strs     Z/var/www/html/suriana-translation/venv/lib/python3.12/site-packages/torch/_linalg_utils.py	is_sparser   
   sZ    !U\\"xx5++++!I99!!#ya	**	
I
    c                     | j                   }|t        j                  t        j                  t        j                  fv r|S t        j                  S )zTReturn the floating point dtype of tensor A.

    Integer types map to float32.
    )dtyper   float16float32float64)r   r   s     r   get_floating_dtyper      s7    
 GGEu}}====r   r   Breturnc                     | |S t        |       r t        j                  j                  | |      S t        j                  | |      S )ziMultiply two matrices.

    If A is None, return B. A can be sparse or dense. B is always
    dense.
    )r   r   sparsemmmatmul)r   r   s     r   r   r       s;     	y|||q!$$<<1r   XYc                 B    t        | j                  t        ||            S )z2Return bilinear form of matrices: :math:`X^T A Y`.)r   mT)r    r   r!   s      r   bformr$   -   s    !$$q!%%r   Sc                     t        || |      S )z&Return quadratic form :math:`S^T A S`.)r$   )r   r%   s     r   qformr'   2   s    Aq>r   c                 T    t         j                  j                  |       j                  S )z%Return orthogonal basis of A columns.)r   linalgqrQ)r   s    r   basisr,   7   s    <<??1r   largestc                     |d}t         j                  j                  | d      \  }}|r.t        j                  |d      }t        j                  |d      }||fS )z/Return eigenpairs of A with specified ordering.FU)UPLO))dims)r   r)   eighflip)r   r-   EZs       r   symeigr7   <   sU    <<QS)DAqJJqu%JJqu%a4Kr   )outc                    t        d      )NzThis function was deprecated since version 1.9 and is now removed.
Please use the `torch.linalg.matrix_rank` function instead. The parameter 'symmetric' was renamed in `torch.linalg.matrix_rank()` to 'hermitian'.RuntimeError)inputtol	symmetricr8   s       r   matrix_rankr?   J   s    
	` r   r<   c                    t        d      )Na  This function was deprecated since version 1.9 and is now removed. `torch.solve` is deprecated in favor of `torch.linalg.solve`. `torch.linalg.solve` has its arguments reversed and does not return the LU factorization.

To get the LU factorization see `torch.lu`, which can be used with `torch.lu_solve` or `torch.lu_unpack`.
X = torch.solve(B, A).solution should be replaced with:
X = torch.linalg.solve(A, B)r:   r<   r   r8   s      r   solverB   R   s    
	' r   c                    t        d      )Na  This function was deprecated since version 1.9 and is now removed. `torch.lstsq` is deprecated in favor of `torch.linalg.lstsq`.
`torch.linalg.lstsq` has reversed arguments and does not return the QR decomposition in the returned tuple (although it returns other information about the problem).

To get the QR decomposition consider using `torch.linalg.qr`.

The returned solution in `torch.lstsq` stored the residuals of the solution in the last m - n columns of the returned value whenever m > n. In torch.linalg.lstsq, the residuals are in the field 'residuals' of the returned named tuple.

The unpacking of the solution, as in
X, _ = torch.lstsq(B, A).solution[:A.size(1)]
should be replaced with:
X = torch.linalg.lstsq(A, B).solutionr:   rA   s      r   lstsqrD   ^   s    
	0 r   c                    t        d      )Na  This function was deprecated since version 1.9 and is now removed. The default behavior has changed from using the upper triangular portion of the matrix by default to using the lower triangular portion.

L, _ = torch.symeig(A, upper=upper) should be replaced with:
L = torch.linalg.eigvalsh(A, UPLO='U' if upper else 'L')

and

L, V = torch.symeig(A, eigenvectors=True) should be replaced with:
L, V = torch.linalg.eigh(A, UPLO='U' if upper else 'L')r:   )r<   eigenvectorsupperr8   s       r   _symeigrH   o   s     		B r   )evselfrF   c                    t        d      )Na  This function was deprecated since version 1.9 and is now removed. `torch.linalg.eig` returns complex tensors of dtype `cfloat` or `cdouble` rather than real tensors mimicking complex tensors.

L, _ = torch.eig(A) should be replaced with:
L_complex = torch.linalg.eigvals(A)

and

L, V = torch.eig(A, eigenvectors=True) should be replaced with:
L_complex, V_complex = torch.linalg.eig(A)r:   )rK   rF   rI   rJ   s       r   eigrM      s     		5 r   )F)NF)FT)__doc__typingr   r   r   r   r   r   r   r$   r'   r,   boolr7   r?   rB   rD   rH   rM    r   r   <module>rR      sk   > "  
hv 
6 
f 
&V &( &V & &
Xf & 
 
	f 	x~ 	%:O 	 &  ,0 	 	F 	E&&.4I 	 ,0  F E&&.4I & 

 	 66>.  

 66>r   