o �J�h���!@sdZddlmZmZmZddlZddlmZmZddl m Z m Z dgZ dd�Z d d �Zd d �Zd-d d�Zd-dd�Zdd�Zdd�ZGdd�dejj�Z             d.dedeedeedeedeedeedeedeedeed eed!dd"eeeefd#eeeefd$eeeefd%eeeffd&d�Z             d.dedeedeedeedeedeedeedeedeed eed!dd"eeeefd#eeeefd$eeeefd%eeeffd'd(�ZGd)d*�d*�ZejZd+d,�Z dS)/z@Locally Optimal Block Preconditioned Conjugate Gradient methods.�)�Dict�Optional�TupleN)� _linalg_utils�Tensor)�handle_torch_function�has_torch_function�lobpcgc Csn|�d�|�d�}|jddd��td��|�d�|j��}t�|t�t� |�t�||�||��}|S)N������������dim1�dim2�inf) � unsqueeze�diagonal�fill_�float�pow_�mT� contiguous�torch�matmul� diag_embed)�D_grad�U_grad�A�D�U�F�Ut�res�r"�KC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\torch\_lobpcg.py�$_symeig_backward_complete_eigenspaces  "�r$c Cs�|jd}t|j�}|dd7<|�|�}d|d<d|d<td|d�D]0}|jr/|��n|}|�d|||d�}||�d|dd�|�d||d|d�8}|}q&|�dd|d�S)ad Given the `roots` of a polynomial, find the polynomial's coefficients. If roots = (r_1, ..., r_n), then the method returns coefficients (a_0, a_1, ..., a_n (== 1)) so that p(x) = (x - r_1) * ... * (x - r_n) = x^n + a_{n-1} * x^{n-1} + ... a_1 * x_1 + a_0 Note: for better performance requires writing a low-level kernel r ��).r).r )�shape�list� new_zeros�range� requires_grad�clone�narrow)�rootsZ poly_orderZpoly_coeffs_shapeZ poly_coeffs�iZpoly_coeffs_new�outr"r"r#�$_polynomial_coefficients_given_rootss   �r1cCs<|��}t|�d�ddd�D] }||||d|f�}q|S)a� A generic method for computing poly(x) using the Horner's rule. Args: poly (Tensor): the (possibly batched) 1D Tensor representing polynomial coefficients such that poly[..., i] = (a_{i_0}, ..., a{i_n} (==1)), and poly(x) = poly[..., 0] * zero_power + ... + poly[..., n] * x^n x (Tensor): the value (possible batched) to evalate the polynomial `poly` at. zero_power (Tensor): the representation of `x^0`. It is application-specific. transition (Callable): the function that accepts some intermediate result `int_val`, the `x` and a specific polynomial coefficient `poly[..., k]` for some iteration `k`. It basically performs one iteration of the Horner's rule defined as `x * int_val + poly[..., k] * zero_power`. Note that `zero_power` is not a parameter, because the step `+ poly[..., k] * zero_power` depends on `x`, whether it is a vector, a matrix, or something else, so this functionality is delegated to the user. r r%.)r,r*�size)�poly�x� zero_power� transitionr!�kr"r"r#�_polynomial_valueIsr8cCsxdd�}|dur5tj|�d�|�d�|j|jd�jgdgtt|jdd����|�d��|�d��R�}t ||||�S)z~ Evaluates `poly(x)` for the (batched) matrix input `x`. Check out `_polynomial_value` function for more details. cSs(|�|�}|jddd��|�d��|S)Nr r r )rr�add_r�Z curr_poly_valr4Z poly_coeffr!r"r"r#r6os z,_matrix_polynomial_value.<locals>.transitionNr ��dtype�devicer&r ) r�eyer2r<r=�view�lenr(r'r8�r3r4r5r6r"r"r#�_matrix_polynomial_valuehs�����rBcCs0dd�}|dur|�d��|j�}t||||�S)z~ Evaluates `poly(x)` for the (batched) vector input `x`. Check out `_polynomial_value` function for more details. cSst�|�d�||�}|S)Nr )r�addcmulrr:r"r"r#r6�sz,_vector_polynomial_value.<locals>.transitionNr&)�new_ones�expandr'r8rAr"r"r#�_vector_polynomial_value|srFc Cs`|j��}|�|� }|jddd��d�t�|j�}|�tjg|j dd��|� d�|� d��R|j |j|d��} | j��} t |�} |} | � | j �} td| � d��D]}t| d|d�f|�}| | |�d�7} |�| �} qTt| |�}t�| t�|| ��}|r�|ddkr�dnd}tj�||�}t|||||�}|| �|t�| �| �|���|�8}|S)Nr r r r&)r<r=� generator.r%)rrrrr9r� Generatorr=�randnr'r2r<r1r)r*rFrrB�linalg�choleskyr$�cholesky_solve)rrrrr�largestr Z proj_U_ortho�genZU_orthoZ U_ortho_tZ chr_poly_DZU_grad_projectedZ series_accr7Zpoly_DZchr_poly_D_at_AZchr_poly_D_at_A_to_U_orthoZchr_poly_D_at_A_to_U_ortho_signZchr_poly_D_at_A_to_U_ortho_Lr!r"r"r#�#_symeig_backward_partial_eigenspace�sN   &��     � � ����rOcCs6|�d�|�d�krt|||||�St||||||�S)Nr r )r2r$rO)rrrrrrMr"r"r#�_symeig_backward�srPc"@s�eZdZe             ddedeedeedeedeedeedeed eed eed ee d dd ee e efdee e efdee e efde eeffdd��Z edd��Z dS)�LOBPCGAutogradFunctionNrr7�B�X�n�iK�niter�tolrM�method�tracker� ortho_iparams� ortho_fparams� ortho_bparams�returncCsp|js|��n|}|dur|js|��n|}t||||||||| | | | | |�\}}|�||||�| |_||fS�N)� is_sparser�_lobpcg�save_for_backwardrM)�ctxrr7rRrSrTrUrVrWrMrXrYrZr[r\rrr"r"r#�forwards,�zLOBPCGAutogradFunction.forwardc Cs�d}}dgd}|j\}}}} |j} |js"|dur&|jr&|jdr&td��|jtjtjfvs<|dur@|jtjtjfvr@td��|durHtd��| durNd} |dur[t ||||| | �}||d<||d<t |�S)N�r%zWlobpcg.backward does not support sparse input yet.Note that lobpcg.forward does though.zXlobpcg.backward does not support complex input yet.Note that lobpcg.forward does though.z:lobpcg.backward does not support backward with B != I yet.Tr) � saved_tensorsrMr_�needs_input_grad� ValueErrorr<r� complex64� complex128rP�tuple) rbrrZA_gradZB_grad�gradsrrRrrrMr"r"r#�backward/s2 ���zLOBPCGAutogradFunction.backward� NNNNNNNNNNNNN)�__name__� __module__� __qualname__� staticmethodrr�intr�bool�strrrrcrlr"r"r"r#rQs`�������� � � � � ���  �-rQrr7rRrSrTrUrVrWrMrXrYrZr[r\r]cCstj��s2||||f}ttt|���tjtd�f�s2t|�r2t t ||||||||||| | | | | d�Stj ��sh|j sA|durg|j rg||j d}|durS||j dnd}t�|||||||||| | | | | �Sn|j sr|durv|j rvtd��t|||||||||| | | | | �S)aFind the k largest (or smallest) eigenvalues and the corresponding eigenvectors of a symmetric positive definite generalized eigenvalue problem using matrix-free LOBPCG methods. This function is a front-end to the following LOBPCG algorithms selectable via `method` argument: `method="basic"` - the LOBPCG method introduced by Andrew Knyazev, see [Knyazev2001]. A less robust method, may fail when Cholesky is applied to singular input. `method="ortho"` - the LOBPCG method with orthogonal basis selection [StathopoulosEtal2002]. A robust method. Supported inputs are dense, sparse, and batches of dense matrices. .. note:: In general, the basic method spends least time per iteration. However, the robust methods converge much faster and are more stable. So, the usage of the basic method is generally not recommended but there exist cases where the usage of the basic method may be preferred. .. warning:: The backward method does not support sparse and complex inputs. It works only when `B` is not provided (i.e. `B == None`). We are actively working on extensions, and the details of the algorithms are going to be published promptly. .. warning:: While it is assumed that `A` is symmetric, `A.grad` is not. To make sure that `A.grad` is symmetric, so that `A - t * A.grad` is symmetric in first-order optimization routines, prior to running `lobpcg` we do the following symmetrization map: `A -> (A + A.t()) / 2`. The map is performed only when the `A` requires gradients. Args: A (Tensor): the input tensor of size :math:`(*, m, m)` B (Tensor, optional): the input tensor of size :math:`(*, m, m)`. When not specified, `B` is interpreted as identity matrix. X (tensor, optional): the input tensor of size :math:`(*, m, n)` where `k <= n <= m`. When specified, it is used as initial approximation of eigenvectors. X must be a dense tensor. iK (tensor, optional): the input tensor of size :math:`(*, m, m)`. When specified, it will be used as preconditioner. k (integer, optional): the number of requested eigenpairs. Default is the number of :math:`X` columns (when specified) or `1`. n (integer, optional): if :math:`X` is not specified then `n` specifies the size of the generated random approximation of eigenvectors. Default value for `n` is `k`. If :math:`X` is specified, the value of `n` (when specified) must be the number of :math:`X` columns. tol (float, optional): residual tolerance for stopping criterion. Default is `feps ** 0.5` where `feps` is smallest non-zero floating-point number of the given input tensor `A` data type. largest (bool, optional): when True, solve the eigenproblem for the largest eigenvalues. Otherwise, solve the eigenproblem for smallest eigenvalues. Default is `True`. method (str, optional): select LOBPCG method. See the description of the function above. Default is "ortho". niter (int, optional): maximum number of iterations. When reached, the iteration process is hard-stopped and the current approximation of eigenpairs is returned. For infinite iteration but until convergence criteria is met, use `-1`. tracker (callable, optional) : a function for tracing the iteration process. When specified, it is called at each iteration step with LOBPCG instance as an argument. The LOBPCG instance holds the full state of the iteration process in the following attributes: `iparams`, `fparams`, `bparams` - dictionaries of integer, float, and boolean valued input parameters, respectively `ivars`, `fvars`, `bvars`, `tvars` - dictionaries of integer, float, boolean, and Tensor valued iteration variables, respectively. `A`, `B`, `iK` - input Tensor arguments. `E`, `X`, `S`, `R` - iteration Tensor variables. For instance: `ivars["istep"]` - the current iteration step `X` - the current approximation of eigenvectors `E` - the current approximation of eigenvalues `R` - the current residual `ivars["converged_count"]` - the current number of converged eigenpairs `tvars["rerr"]` - the current state of convergence criteria Note that when `tracker` stores Tensor objects from the LOBPCG instance, it must make copies of these. If `tracker` sets `bvars["force_stop"] = True`, the iteration process will be hard-stopped. ortho_iparams, ortho_fparams, ortho_bparams (dict, optional): various parameters to LOBPCG algorithm when using `method="ortho"`. Returns: E (Tensor): tensor of eigenvalues of size :math:`(*, k)` X (Tensor): tensor of eigenvectors of size :math:`(*, m, k)` References: [Knyazev2001] Andrew V. Knyazev. (2001) Toward the Optimal Preconditioned Eigensolver: Locally Optimal Block Preconditioned Conjugate Gradient Method. SIAM J. Sci. Comput., 23(2), 517-541. (25 pages) https://epubs.siam.org/doi/abs/10.1137/S1064827500366124 [StathopoulosEtal2002] Andreas Stathopoulos and Kesheng Wu. (2002) A Block Orthogonalization Procedure with Constant Synchronization Requirements. SIAM J. Sci. Comput., 23(6), 2165-2182. (18 pages) https://epubs.siam.org/doi/10.1137/S1064827500370883 [DuerschEtal2018] Jed A. Duersch, Meiyue Shao, Chao Yang, Ming Gu. (2018) A Robust and Efficient Implementation of LOBPCG. SIAM J. Sci. Comput., 40(5), C655-C676. (22 pages) https://epubs.siam.org/doi/abs/10.1137/17M1129830 N) r7rRrSrTrUrVrWrMrXrYrZr[r\r%z�Script and require grads is not supported atm.If you just want to do the forward, use .detach()on A and B before calling into lobpcg)r�jit� is_scripting�set�map�type�issubsetrrrr � _jit_internalr+rrQ�apply� RuntimeErrorr`)rr7rRrSrTrUrVrWrMrXrYrZr[r\� tensor_opsZA_symZB_symr"r"r#r Ys� !  ��� ����c Csh|jd|jdksJ|j��|dur!|j|jks!J|j|jf��t�|�}|j}|dur;tjdtjdi|}|d}|jd}|durO|durJdn|jdn|}|dur]|dur[|n|n|jd}|d|krstd|�d |�d ���| duryd n| } ||||dur�d n|d �}d|i}d|dur�dn|i}| d kr�| dur�|�| �| dur�|�| �| dur�|�| �|� dd�|d<|� dd�|d<|� d|�|d<|� d|�|d<|� d|�|d<|� dd�|d<tj � �s�t t _t|j�dk�r�tt�t�|jdd����}|�|f|jdd��}|du�r#|�|f|jdd��nd}|du�r7|�|f|jdd��nd}tj||f||d�}tj|||f||d�}t|�D]h}||}|du�ra||nd}|du�rrtj||f||d�n||}t|j�dk�r�|j||fk�s�J|j||ff��||d<t |||||||| | � }|��|jd|�||<|jdd�d|�f||<�qRtj � ��s�tt _|�|jdd�|f�|�|jdd�||f�fS|du�r�tj||f||d�n|}t|j�dk�r|j||fk�s J|j||ff��t |||||||| | � }|��tj � ��s"tt _|jd|�|jdd�d|�ffS)Nr r g+i�)+�>g�(ƹ��<g�?r&�z?LPBPCG algorithm is not applicable when the number of A rows (=z;) is smaller than 3 x the number of requested eigenpairs (=�)�orthoi�)�mrTr7rVrWrMT� ortho_i_max� ortho_j_max� ortho_tol�ortho_tol_drop�ortho_tol_replace�ortho_use_dropFr%r;Z batch_index)r'�_utils�get_floating_dtyper=r�float32�float64rg�update�getrurv�LOBPCG_call_tracker�LOBPCG� call_trackerr@rr�prod�tensor�reshape�emptyr*rI�run�ErS�LOBPCG_call_tracker_orig) rr7rRrSrTrUrVrWrMrXrYrZr[r\r<r=Zfepsr��iparams�fparams�bparams�NZbAZbBZbXZbEZbXretr/ZA_ZB_ZX_�workerr"r"r#r`Fs�  "" ����    (( $�2 6"2 $r`c@s�eZdZdZdeedeededeedeeefdeee fdeee fd ed d d d fd d�Z dd�Z dd�Z dd�Zdd�Zdd�Zdd�Zejjdd��Zdd�Zdd �Zd!d"�Zd#ed$e d%e d efd&d'�Zd(d)�Zd S)*r�zWorker class of LOBPCG methods.rrRrSrUr�r�r�rXrYNr]c Cs�||_||_||_||_||_||_||_| |_|d} |d} ||_t j | f|j |j d�|_ t j | | f|j |j d�|_t j | d| f|j |j d�|_i|_ddi|_ddi|_dd i|_dS) Nr�rTr;r�istepr�_�F)rrRrUr�r�r�rXrYrSr�zerosr<r=r��R�S�tvars�ivars�fvars�bvars) �selfrrRrSrUr�r�r�rXrYr�rTr"r"r#�__init__�s$   zLOBPCG.__init__cCs�dg}|d|j��g7}|d|j��g7}|d|j��g7}|d|j��g7}|d|j��g7}|d|j��g7}|d|j��g7}|d |j��g7}|d |j��g7}|d |j ��g7}|d |j ��g7}|d |j ��g7}d}|D]}||d7}qs|S)NzLOPBCG:z iparams=z fparams=z bparams=z ivars=z fvars=z bvars=z tvars=z A=z B=z iK=z X=z E=�� ) r�r�r�r�r�r�r�rrRrUrSr�)r��lines�r�liner"r"r#�__str__�s"zLOBPCG.__str__cCs�|jddkrRtt�|j��}|d}tt�t�|j|j���|}tt�t�|j|j���|}||j d<||j d<||j d<|j d|jd<d|jd <d|jd <|j d kr\|� �n|� �|jdd |jd<|jdd |jd<d S)z#Set and update iteration variables.r�rr �X_norm�A_norm�B_normrV�iterations_left�converged_count� converged_endr�r&N)r�rr�normrSr�rrrRr�r�rX� _update_ortho� _update_basic)r�r�ZiX_normr�r�r"r"r#r��s        z LOBPCG.updatecCs.tj}||j|j�||j|j�|j|_dS)z"Update residual R from A, B, X, E.N)r�rrrSrRr�r�)r��mmr"r"r#�update_residuals(zLOBPCG.update_residualc Cs�|jd}|jd}|jd}|jd}|j|j|j}}}t�|dd�t�|dd�||d|jd�|d}|j |k} d } | D] } | sKn| d 7} qE| |ks_Jd |�d | �d ���| |jd<||j d<| S)z�Determine the number of converged eigenpairs using backward stable convergence criterion, see discussion in Sec 4.3 of [DuerschEtal2018]. Users may redefine this method for custom convergence criteria. r�rWr�r�r%)rNr rr&z(the number of converged eigenpairs (was z, got z) cannot decrease�rerr) r�r�r�r�rSr�rr�r'�realr�) r�Z prev_countrWr�r�r�rSr�r�Z converged�count�br"r"r#�update_converged_counts*     *��   �  zLOBPCG.update_converged_countcCs0|j�dd�p|jddkp|jd|jdkS)z�Return True to stop iterations. Note that tracker (if defined) can force-stop iterations by setting ``worker.bvars['force_stop'] = True``. Z force_stopFr�rr�r7)r�r�r�r��r�r"r"r#�stop_iteration%s  ��zLOBPCG.stop_iterationcCs`|��tj��s|jdur|��|��s.|��tj��s(|jdur(|��|��rdSdS)z�Run LOBPCG iterations. Use this method as a template for implementing LOBPCG iteration scheme with custom tracker that is compatible with TorchScript. N)r�rrurvrYr�r�r�r"r"r#r�1s�z LOBPCG.runcCsdS)z�Interface for tracking iteration process in Python mode. Tracking the iteration process is disabled in TorchScript mode. In fact, one should specify tracker=None when JIT compiling functions using lobpcg. Nr"r�r"r"r#r�CszLOBPCG.call_trackerc Csltj}|jd}|jd}|jd}|jd}|jddkr�|�|j�}t�t�|j |j�|�}t� ||�\}} ||j||| ��|jdd�<||j dd�<d} |� �|� �}|j|jdd|�f<t�|j|j�} || | jd |jd<}| |jdd�|| |�f<dS|jdd�||�f} |�| �}t�t�|j | �|�}t� ||�\} } || ||| dd�d||�f��|jdd�|d�f<| d||�|j |d�<|| ||| dd�|d ||�f��}|jd } |� �|� �}|j|jdd|�f<||jdd�||| �f<t�|j|jdd�|d�f�} || | jd |jd<}| |jdd�|| |�f<dS) zT Update or initialize iteration variables when `method == "basic"`. r�r�rTrMr�rN.r r%)rrr�r�r��_get_rayleigh_ritz_transformrSr��qformr�symeigr�r�r�r�rUr�r'�r�r��ns�ncrTrMZRi�Mr��Z�np�WZS_ZE_�Pr"r"r#r�OsB      6(  zLOBPCG._update_basicc Csrtj}|jd}|jd}|jd}|jd}|jddkr}|�|j�}t�t�|j |j�|�}t� ||�\}} ||j||| ��|_|� �d} |� �}|j|j dd�d|�f<|�|j|j�} || | jd}|jd<| |j dd�|| |�f<dS|j dd�||�f} t� t�|j | �|�\} } || | dd�d||�f�|jdd�|d�f<| d||�|j|d�<|| || dd�||d�ft�| d||�||d�fj���}|jd} |� �|� �}|j|j dd�d|�f<||j dd�||| �f<|�|jdd�|d�f|j dd�d|| �f�} || | jd}|jd<| |j dd�|| |�f<dS) zT Update or initialize iteration variables when `method == "ortho"`. r�r�rTrMr�rNr )rrr�r�r�r�rSr�r�rr�r�r�r�� _get_orthor�r'r��basisrr�r"r"r#r�zs<     0D 4zLOBPCG._update_orthocCsl|j}tj}t�||�}|�ddd�d}|�|jdd�}tjj |||dd�}tjj ||� �ddd �S) a�Return a transformation matrix that is used in Rayleigh-Ritz procedure for reducing a general eigenvalue problem :math:`(S^TAS) C = (S^TBS) C E` to a standard eigenvalue problem :math: `(Ri^T S^TAS Ri) Z = Z E` where `C = Ri Z`. .. note:: In the original Rayleight-Ritz procedure in [DuerschEtal2018], the problem is formulated as follows:: SAS = S^T A S SBS = S^T B S D = (<diagonal matrix of SBS>) ** -1/2 R^T R = Cholesky(D SBS D) Ri = D R^-1 solve symeig problem Ri^T SAS Ri Z = Theta Z C = Ri Z To reduce the number of matrix products (denoted by empty space between matrices), here we introduce element-wise products (denoted by symbol `*`) so that the Rayleight-Ritz procedure becomes:: SAS = S^T A S SBS = S^T B S d = (<diagonal of SBS>) ** -1/2 # this is 1-d column vector dd = d d^T # this is 2-d matrix R^T R = Cholesky(dd * SBS) Ri = R^-1 * d # broadcasting solve symeig problem Ri^T SAS Ri Z = Theta Z C = Ri Z where `dd` is 2-d matrix that replaces matrix products `D M D` with one element-wise product `M * dd`; and `d` replaces matrix product `D M` with element-wise product `M * d`. Also, creating the diagonal matrix `D` is avoided. Args: S (Tensor): the matrix basis for the search subspace, size is :math:`(m, n)`. Returns: Ri (tensor): upper-triangular transformation matrix of size :math:`(n, n)`. rr r ��r&T)�upperF)r��left) rRrrr�r�rr�r'rJrK�solve_triangularr)r�r�rRr�ZSBSZd_row�d_colr�r"r"r#r��s-  �z#LOBPCG._get_rayleigh_ritz_transformr�drop�tauc Cs�t�|�dkr |St�|j|�}|�ddd�}t�t|�dk�}t|�dks*J|��t|d�t|�krj|dd�|df}t�|�dkrG|St�|j|�}|�ddd�}t�t|�dk�}t|d�t|�ksjJ�|d� |j dd�}|||j }t� |�\} } |t| �� �} |r�t�| | k�} t| �dks�J| ��| | d} | dd�| df} || d}n | | t�| | k�d<t�||j | | d�S)a�Return B-orthonormal U. .. note:: When `drop` is `False` then `svqb` is based on the Algorithm 4 from [DuerschPhD2015] that is a slight modification of the corresponding algorithm introduced in [StathopolousWu2002]. Args: U (Tensor) : initial approximation, size is (m, n) drop (bool) : when True, drop columns that contribution to the `span([U])` is small. tau (float) : positive tolerance Returns: U (Tensor) : B-orthonormal columns (:math:`U^T B U = I`), size is (m, n1), where `n1 = n` if `drop` is `False, otherwise `n1 <= n`. rr r r�r&Nr�)r�numelr�r�rRr�where�absr@r�r'rr��maxr) r�rr�r��UBU�dZnzr�ZDUBUDr�r��t�keepr"r"r#� _get_svqb�s4  zLOBPCG._get_svqbc Cs�tj}tj}|jd}|jd}|jd}|jd}|jd} |jd} |jd} t|j���D]} | � d�rB| � d �rB|j� | �q0|j � d d �|j � d d �t� ||j|��} ||j|�}||j|�}d }}d }t| �D]�}||||�}d}|}t| �D]x}| r�|�|||�}d}|}n|�|d|�}t�|�d kr�||j d <||j d <|S||j|�}||j|�}t� |�}t� |�}|tj|jd|j|jd�}t� |�}t|�t||�d}d|�d|�d�} ||j| <||kr�nq�||j|�}t� |�}t� |�}t|�t| |�d}d|�d�} ||j| <||k�r(n/||jd|jdk�rV|j}|du�s?J�td|jd�d|jd�d|jd�d���qp||j d <||j d <|S)a�Return B-orthonormal U with columns are B-orthogonal to V. .. note:: When `bparams["ortho_use_drop"] == False` then `_get_ortho` is based on the Algorithm 3 from [DuerschPhD2015] that is a slight modification of the corresponding algorithm introduced in [StathopolousWu2002]. Otherwise, the method implements Algorithm 6 from [DuerschPhD2015] .. note:: If all U columns are B-collinear to V then the returned tensor U will be empty. Args: U (Tensor) : initial approximation, size is (m, n) V (Tensor) : B-orthogonal external basis, size is (m, k) Returns: U (Tensor) : B-orthonormal columns (:math:`U^T B U = I`) such that :math:`V^T B U=0`, size is (m, n1), where `n1 = n` if `drop` is `False, otherwise `n1 <= n`. r�r�r�r�r�r�r�Zortho_Z_rerrZortho_irZortho_jr�FTr )r=r<zortho_UBUmI_rerr[z, �]zortho_VBU_rerr[Nz$Overdetermined shape of U: #B-cols(=z) >= #U-cols(=z ) + #V-cols(=z ) must hold)rrr�r�r�r�r(r��keys� startswith�endswith�popr�r�rRrr*r�r�r>r'r=r<rrg)r�r�Vr�Zmm_Br�Z tau_orthoZtau_dropZ tau_replaceZi_maxZj_maxZuse_dropZvkeyZBV_normZBUZVBUr/�j�statsr�Ztau_svqbr�ZU_normZBU_normr�ZR_normr�ZVBU_normrRr"r"r#r�s�        �             �      ����� zLOBPCG._get_ortho)rnrorp�__doc__rrrrtrrrrsr�r�r�r�r�r�r�rru�unusedr�r�r�r�r�r�r"r"r"r#r��sH���� � � � � � �"   +-8 =r�cCs|�|�dSr^)rYr�r"r"r#r��sr�r^rm)!r��typingrrrrrr�r�torch.overridesrr�__all__r$r1r8rBrFrOrP�autograd�FunctionrQrrrrsrtr r`r�r�r�r�r"r"r"r#�<module>s�*  k[��������� � � � � ��  �p��������� � � � � ��  �mQ 
Memory