ó
    EñiÉ¬  ã            !       ó€  • S r SSKrSSKJrJr  SSKJrJr  S/rS r	S r
S rS#S	 jrS#S
 jrS rS r " S S\R                   R"                  5      r             S$S\S\S-  S\S-  S\S-  S\S-  S\S-  S\S-  S\S-  S\S-  S\S-  SSS\\\4   S-  S\\\4   S-  S\\\4   S-  S\\\4   4S jjr             S$S\S\S-  S\S-  S\S-  S\S-  S\S-  S\S-  S\S-  S\S-  S\S-  SSS\\\4   S-  S\\\4   S-  S\\\4   S-  S\\\4   4S jjr " S  S!5      r\R8                  rS" rg)%z@Locally Optimal Block Preconditioned Conjugate Gradient methods.é    N)Ú_linalg_utilsÚTensor)Úhandle_torch_functionÚhas_torch_functionÚlobpcgc           
      ó¦  • UR                  S5      UR                  S5      -
  nUR                  SSS9R                  [        S5      5        UR	                  S5        UR
                  R                  5       n[        R                  " U[        R                  " [        R                  " U 5      [        R                  " Xa5      U-  -   U5      5      nU$ )Néþÿÿÿéÿÿÿÿ©Údim1Údim2Úinf)
Ú	unsqueezeÚdiagonalÚfill_ÚfloatÚpow_ÚmTÚ
contiguousÚtorchÚmatmulÚ
diag_embed)ÚD_gradÚU_gradÚAÚDÚUÚFÚUtÚress           ÚJ/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/_lobpcg.pyÚ$_symeig_backward_complete_eigenspacer"      sœ   € à	�‰�B‹˜!Ÿ+™+ b›/Ñ)€AØ‡J�J�B˜R€JÐ ×&Ñ&¤u¨U£|Ô4Ø‡F�Fˆ2„Jð 
�‰�‰Ó	€BÜ
�,Š,Ø	Œ5�<Š<œ×(Ò(¨Ó0´5·<²<ÀÓ3KÈaÑ3OÑOÐQSÓTó€Cð €Jó    c           	      óÔ  • U R                   S   n[        U R                   5      nUS==   S-  ss'   U R                  U5      nSUS'   SUS'   [        SUS-   5       Ht  nU R                  (       a  UR                  5       OUnUR                  SX-
  US-   5      nX`R                  SUS-
  S5      UR                  SX-
  S-   US-   5      -  -  nUnMv     UR                  SSUS-   5      $ )aH  
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)ÚrootsÚ
poly_orderÚpoly_coeffs_shapeÚpoly_coeffsÚiÚpoly_coeffs_newÚouts          r!   Ú$_polynomial_coefficients_given_rootsr5      s  € ð —‘˜R‘€JÜ˜UŸ[™[Ó)Ðð �bÓ˜QÑÓØ—/‘/Ð"3Ó4€KØ€K�ÑØ€K�Ñô �1�j 1‘nÖ%ˆð 27×1D×1D˜+×+Ñ+Ô-È+ˆØ×$Ñ$ R¨©¸¸Q¹Ó?ˆØ�|‰|˜B  A¡ qÓ)¨K×,>Ñ,>Ø�
‘ Ñ" A¨¡Eó-
ñ 
ñ 	
ˆð &Šñ &ð" ×Ñ˜b ! Z°!¡^Ó4Ð4r#   c                 óŽ   • UR                  5       n[        U R                  S5      S-
  SS5       H  nU" XAU SU4   5      nM     U$ )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 evaluate 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    Úks         r!   Ú_polynomial_valuer=   G   sK   € ð2 ×
Ñ
Ó
€CÜ�4—9‘9˜R“= 1Ñ$ b¨"Ö-ˆÙ˜  c¨1 f¡Ó.Šñ .à€Jr#   c                 ób  • S nUcž  [         R                  " UR                  S5      UR                  S5      UR                  UR                  S9R
                  " / S/[        [        UR                  SS 5      5      -  QUR                  S5      PUR                  S5      P76 n[        XX#5      $ )zr
Evaluates `poly(x)` for the (batched) matrix input `x`.
Check out `_polynomial_value` function for more details.
c                 ó„   • UR                  U 5      nUR                  SSS9R                  UR                  S5      5        U$ )Nr	   r
   r   )r   r   Úadd_r   ©Úcurr_poly_valr9   Ú
poly_coeffr    s       r!   r;   Ú,_matrix_polynomial_value.<locals>.transitionm   s;   € Ø�h‰h�}Ó%ˆØ�‰˜" 2ˆÐ&×+Ñ+¨J×,@Ñ,@ÀÓ,DÔEØˆ
r#   Nr
   ©ÚdtypeÚdevicer&   r	   )
r   Úeyer7   rF   rG   ÚviewÚlenr(   r'   r=   ©r8   r9   r:   r;   s       r!   Ú_matrix_polynomial_valuerL   f   s£   € òð
 ÑÜ—Y’YØ�F‰F�2‹J˜Ÿ™˜r›
¨!¯'©'¸!¿(¹(ñ
ç
‰$ðð Ià�”sœ4 §¡¨¨ Ó-Ó.Ñ.ðIà12·±¸³ðIà=>¿V¹VÀB»ZòIˆ
ô ˜T jÓ=Ð=r#   c                 óz   • S nUc*  UR                  S5      R                  UR                  5      n[        XX#5      $ )zr
Evaluates `poly(x)` for the (batched) vector input `x`.
Check out `_polynomial_value` function for more details.
c                 óR   • [         R                  " UR                  S5      X5      nU$ )Nr
   )r   Úaddcmulr   rA   s       r!   r;   Ú,_vector_polynomial_value.<locals>.transition�   s"   € Ü�mŠm˜J×0Ñ0°Ó4°aÓGˆØˆ
r#   r&   )Únew_onesÚexpandr'   r=   rK   s       r!   Ú_vector_polynomial_valuerS   z   s8   € òð ÑØ—Z‘Z “]×)Ñ)¨!¯'©'Ó2ˆ
ä˜T jÓ=Ð=r#   c           	      óz  • UR                   R                  5       nUR                  U5      * nUR                  SSS9R	                  S5        [
        R                  " UR                  5      nUR                  [
        R                  " / UR                  S S QUR                  S5      UR                  S5      -
  P7UR                  UR                  US95      n	U	R                   R                  5       n
[        U5      nUnUR                  UR                  5      n[        SUR                  S5      5       H=  n[        USUS 24   U5      nXÜUR!                  S5      -  -  nUR                  U5      nM?     [#        X²5      n[
        R                  " U
[
        R                  " UU	5      5      nU(       a  WS-  S:X  a  SOSn[
        R$                  R'                  UU-  5      n[)        XX#U5      nUU	R                  U[
        R*                  " U
R                  U5      U5      -  5      R                  U5      -  nU$ )Nr	   r
   r   r&   )rF   rG   Ú	generator.r%   )r   r   r   r   r@   r   Ú	GeneratorrG   Úrandnr'   r7   rF   r5   r)   r*   rS   r   rL   ÚlinalgÚcholeskyr"   Úcholesky_solve)r   r   r   r   r   Úlargestr   Úproj_U_orthoÚgenÚU_orthoÚ	U_ortho_tÚ
chr_poly_DÚU_grad_projectedÚ
series_accr<   Úpoly_DÚchr_poly_D_at_AÚchr_poly_D_at_A_to_U_orthoÚchr_poly_D_at_A_to_U_ortho_signÚchr_poly_D_at_A_to_U_ortho_Lr    s                        r!   Ú#_symeig_backward_partial_eigenspacerh   ‹   s	  € ð 
�‰�‰Ó	€BØ—H‘H˜R“L�=€LØ×Ñ˜r¨ÐÐ+×0Ñ0°Ô3ô �/Š/˜!Ÿ(™(Ó
#€Cð ×!Ñ!Ü�ŠØ4ˆa�g‰g�c�rˆlÐ4˜AŸF™F 2›J¨¯©°«Ñ3Ñ4Ø—'‘'Ø—8‘8Øñ		
ó€Gð —
‘
×%Ñ%Ó'€Iô
 6°aÓ8€Jð< ÐØ!×+Ñ+Ð,<×,BÑ,BÓC€JÜ�1�j—o‘o bÓ)Ö*ˆÜ)¨*°S¸!¹"°WÑ*=¸qÓAˆØ¨×)9Ñ)9¸"Ó)=Ñ=Ñ=ˆ
ØŸ8™8Ð$4Ó5Òñ +ô /¨zÓ=€Oô "'§¢Ø”5—<’< °Ó9ó"Ðö .5¸!¸a¹%À1»*¡bÈBÐ#Ü#(§<¡<×#8Ñ#8Ø'Ð*DÑDó$Ð ô
 /¨v¸qÀQÓ
G€Cð ˆ7�>‰>Ø'Ü
×
Ò
Ø×Ñ˜ZÓ(Ð*Fó
ñ	
ó÷
 �fˆRƒjñ€Cð €Jr#   c                 ó~   • UR                  S5      UR                  S5      :X  a  [        XX#U5      $ [        XX#XE5      $ )Nr
   r	   )r7   r"   rh   )r   r   r   r   r   r[   s         r!   Ú_symeig_backwardrj   ö   s8   € à‡v�vˆbƒz�Q—V‘V˜B“ZÓÜ3°FÀAÈ!ÓLÐLä2°6À1ÈÓTÐTr#   c            "       ó  • \ rS rSr\             SS\S\S-  S\S-  S\S-  S\S-  S\S-  S	\S-  S
\S-  S\S-  S\	S-  SSS\
\	\4   S-  S\
\	\4   S-  S\
\	\4   S-  S\\\4   4S jj5       r\S 5       rSrg)ÚLOBPCGAutogradFunctionéþ   Nr   r<   ÚBÚXÚnÚiKÚniterÚtolr[   ÚmethodÚtrackerÚortho_iparamsÚortho_fparamsÚortho_bparamsÚreturnc                 ó  • UR                   (       d  UR                  5       OUnUb#  UR                   (       d  UR                  5       OUn[        UUUUUUUUU	U
UUUU5      u  nnU R                  XUU5        X�l        UU4$ ©N)Ú	is_sparser   Ú_lobpcgÚsave_for_backwardr[   )Úctxr   r<   rn   ro   rp   rq   rr   rs   r[   rt   ru   rv   rw   rx   r   r   s                    r!   ÚforwardÚLOBPCGAutogradFunction.forwardÿ   s‰   € ð( $%§;§;ˆA�L‰LŒN°QˆØ‰=Ø'(§{§{�—‘”¸ˆAäØØØØØØØØØØØØØØó
‰ˆˆ1ð" 	×Ñ˜a A qÔ)ØŒà�!ˆtˆr#   c                 ó  • S =p4S /S-  nU R                   u  pgp‰U R                  n
UR                  (       d(  Ub0  UR                  (       a  U R                  S   (       a  [	        S5      eUR
                  [        R                  [        R                  4;   d1  Ub9  UR
                  [        R                  [        R                  4;   a  [	        S5      eUb  [	        S5      eU
c  Sn
Uc  [        XXhXš5      nX5S'   XES'   [        U5      $ )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_tensorsr[   r|   Úneeds_input_gradÚ
ValueErrorrF   r   Ú	complex64Ú
complex128rj   Útuple)r   r   r   ÚA_gradÚB_gradÚgradsr   rn   r   r   r[   s              r!   ÚbackwardÚLOBPCGAutogradFunction.backward-  s  € àÐˆØ�˜‘ˆà×&Ñ&‰
ˆˆaØ—+‘+ˆð �;�;˜1™=¨Q¯[¯[¸S×=QÑ=QÐRS×=TÜð8óð ð
 �G‰GœŸ™¬×)9Ñ)9Ð:Ó:Ø‰}Ø—‘œEŸO™O¬U×-=Ñ-=Ð>Ó>äð8óð ð ‰=ÜØLóð ð ‰?ØˆGð ‰9Ü% f°a¸AÓGˆFð ˆa‰àˆa‰Ü�U‹|Ðr#   © ©NNNNNNNNNNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ústaticmethodr   Úintr   ÚboolÚstrÚdictr‰   r€   r�   Ú__static_attributes__r�   r#   r!   rl   rl   þ   s;  † Øð ØØØØ Ø Ø Ø#Ø!ØØ/3Ø15Ø04ñ+àð+ð �‰:ð+ð �D‰=ð	+ð
 �D‰=ð+ð �‰:ð+ð �T‰Mð+ð �T‰zð+ð �T‰\ð+ð ˜‘ð+ð �d‘
ð+ð ð+ð ˜C ˜H‘~¨Ñ,ð+ð ˜C ˜JÑ'¨$Ñ.ð+ð ˜C ˜I‘¨Ñ-ð+ð  
ˆv�vˆ~Ñ	ô!+ó ð+ðZ ñ&ó ó&r#   rl   r   r<   rn   ro   rp   rq   rr   rs   r[   rt   ru   rv   rw   rx   ry   c                 óè  • [         R                  R                  5       (       dv  XX54n[        [	        [
        U5      5      R                  [         R                  [        S5      45      (       d,  [        U5      (       a  [        [        UU UUUUUUUUU	U
UUUS9$ [         R                  R                  5       (       do  U R                  (       d  UbZ  UR                  (       aI  X R                  -   S-  nUb  X"R                  -   S-  OSn[        R                  UUUUUUUUUU	U
UUU5      $ O0U R                  (       d  Ub  UR                  (       a  [!        S5      e[#        U UUUUUUUUU	U
UUU5      $ )aö  Find 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.

.. warning:: LOBPCG algorithm is not applicable when the number of `A`'s rows
  is smaller than 3x the number of requested eigenpairs `n`.

Args:

  A (Tensor): the input tensor of size :math:`(*, m, m)`

  k (integer, optional): the number of requested
              eigenpairs. Default is the number of :math:`X`
              columns (when specified) or `1`.

  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.

  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, any provided value of `n` is
              ignored and `n` is automatically set to the number of
              columns in :math:`X`.

  iK (tensor, optional): the input tensor of size :math:`(*, m,
              m)`. When specified, it will be used as preconditioner.

  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`.

  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".

  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://arxiv.org/abs/1704.07458

N)r<   rn   ro   rp   rq   rr   rs   r[   rt   ru   rv   rw   rx   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Úissubsetr   r   r   r   Ú_jit_internalr+   r   rl   ÚapplyÚRuntimeErrorr}   )r   r<   rn   ro   rp   rq   rr   rs   r[   rt   ru   rv   rw   rx   Ú
tensor_opsÚA_symÚB_syms                    r!   r   r   W  s‚  € ôF �9‰9×!Ñ!×#Ñ#Ø˜A�]ˆ
Ü”3”t˜ZÓ(Ó)×2Ñ2Ü�\‰\œ4 ›:Ð&÷
ñ 
ä  ×,Ñ,Ü(ÜØØØØØØØØØØØØØ+Ø+Ø+ñ!ð ô& ×Ñ×+Ñ+×-Ñ-Ø�?�?˜q™}°··ð Ÿ™‘X ‘NˆEØ'(¡}�QŸ™‘X ’N¸4ˆEä)×/Ñ/ØØØØØØØØØØØØØØóð øð" �?�?˜q™}°··Üð8óð ô Ø	Ø	Ø	Ø	Ø	Ø
ØØØØØØØØóð r#   c                 ó¶
  • U R                   S   U R                   S   :w  a  [        SU R                    35      eUb?  U R                   UR                   :w  a%  [        SU R                    SUR                    35      e[        R                  " U 5      nU R                  nUc*  [
        R                  S[
        R                  S0U   nUS-  nU R                   S   nUc  Uc  S	OUR                   S   OUnUc  Uc  UOUOUR                   S   nUS
U-  :  a  [        SU SU S35      eU	c  SOU	n	UUUUc  SOUS.nSU0nSUc  SOU0nU	S:X  aº  Ub  UR                  U5        Ub  UR                  U5        Ub  UR                  U5        UR                  SS
5      US'   UR                  SS
5      US'   UR                  SU5      US'   UR                  SU5      US'   UR                  SU5      US'   UR                  SS5      US'   [
        R                  R                  5       (       d  [        [        l        [!        U R                   5      S:”  Ga/  [#        [
        R$                  " [
        R&                  " U R                   S S 5      5      5      nU R)                  U4U R                   SS  -   5      nUb"  UR)                  U4U R                   SS  -   5      OS nUb"  UR)                  U4UR                   SS  -   5      OS n[
        R*                  " UU4XïS9n[
        R*                  " UUU4XïS9n[-        U5       HÊ  nUU   nUb  UU   OS nUc  [
        R.                  " UU4XïS9OUU   n[!        UR                   5      S:X  a  UR                   UU4:X  d  [        SUR                    SUU4 35      eUUS'   [        UUUUUUUXš5	      nUR1                  5         UR2                  S U UU'   UR4                  S S 2S U24   UU'   MÌ     [
        R                  R                  5       (       d  [6        [        l        UR)                  U R                   S S U4-   5      UR)                  U R                   S S UU4-   5      4$ Uc  [
        R.                  " UU4XïS9OUn[!        UR                   5      S:X  a  UR                   UU4:X  d  [        S UR                    SUU4 35      e[        XX5UUUXš5	      nUR1                  5         [
        R                  R                  5       (       d  [6        [        l        UR2                  S U UR4                  S S 2S U24   4$ )!Nr	   r
   zA must be square, got shape z"A and B must have same shape, got z vs 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è  )Úmrp   r<   rr   rs   r[   TÚortho_i_maxÚortho_j_maxÚ	ortho_tolÚortho_tol_dropÚortho_tol_replaceÚortho_use_dropFr%   rE   zX_ shape mismatch: got z, expected Úbatch_indexzX shape mismatch: got )r'   ÚAssertionErrorÚ_utilsÚget_floating_dtyperG   r   Úfloat32Úfloat64r†   ÚupdateÚgetrœ   r�   ÚLOBPCG_call_trackerÚLOBPCGÚcall_trackerrJ   r–   ÚprodÚtensorÚreshapeÚemptyr*   rW   ÚrunÚEro   ÚLOBPCG_call_tracker_orig) r   r<   rn   ro   rp   rq   rr   rs   r[   rt   ru   rv   rw   rx   rF   rG   Úfepsr¬   ÚiparamsÚfparamsÚbparamsÚNÚbAÚbBÚbXÚbEÚbXretr2   ÚA_ÚB_ÚX_Úworkers                                    r!   r}   r}   G  s  € ð" 	‡w�wˆr�{�a—g‘g˜b‘kÓ!ÜÐ;¸A¿G¹G¸9ÐEÓFÐFØ�}à�7‰7�a—g‘gÓÜ Ø4°Q·W±W°I¸TÀ!Ç'Á'ÀÐKóð ô ×%Ò% aÓ(€EØ�X‰X€FØ
�{Ü—‘˜w¬¯©°xÐ@ÀÑGˆØ�C‰iˆà	�‰�‰€AØ-.©Yˆa‰i‰˜QŸW™W Rš[¸A€AØ#$¡9ˆa‰i‰™Q°!·'±'¸"±+€Aàˆ1ˆq‰5ƒyÜØMÈaÈSð QIØIJÈÈ1ðNó
ð 	
ð
 ™‰W¨F€Fð ØØØ™‘¨Eñ	€Gð 	ˆsð€Gð  '¡/™$°wÐ?€Gà�ÓØÑ$Ø�N‰N˜=Ô)ØÑ$Ø�N‰N˜=Ô)ØÑ$Ø�N‰N˜=Ô)Ø!(§¡¨]¸AÓ!>ˆ�ÑØ!(§¡¨]¸AÓ!>ˆ�ÑØ&Ÿ{™{¨;¸Ó<ˆ�ÑØ$+§K¡KÐ0@À#Ó$FˆÐ Ñ!Ø'.§{¡{Ð3FÈÓ'LˆÐ#Ñ$Ø$+§K¡KÐ0@À%Ó$HˆÐ Ñ!ä�9‰9×!Ñ!×#Ñ#Ü1ŒÔä
ˆ1�7‰7ƒ|�aÔÜ”—
’
œ5Ÿ<š<¨¯©°°¨Ó5Ó6Ó7ˆØ�Y‰Y˜�t˜aŸg™g b c˜lÑ*Ó+ˆØ/0©}ˆQ�Y‰Y˜�t˜aŸg™g b c˜lÑ*Ô+À$ˆØ/0©}ˆQ�Y‰Y˜�t˜aŸg™g b c˜lÑ*Ô+À$ˆÜ�[Š[˜!˜Q˜ uÑ<ˆÜ—’˜Q  1˜I¨UÑBˆä�q–ˆAØ�A‘ˆBØ™.��A’¨dˆBàCEÁ:”—’˜Q ˜F¨%Ò?ÐSUÐVWÑSXð ô ˜Ÿ™“M QÓ&¨2¯8©8¸¸1°vÓ+=Ü$Ø-¨b¯h©h¨Z°{ÀAÀqÀ6À(ÐKóð ð &'ˆG�MÑ"Ü˜B  B¨¨G°W¸gÀvÓWˆFØ�J‰JŒLØ—H‘H˜R˜a�LˆBˆq‰EØ—x‘x¢ 2 A 2 ‘ˆE�!‹Hñ ô  �y‰y×%Ñ%×'Ñ'Ü":ŒFÔà�z‰z˜!Ÿ'™' # 2˜,¨!¨Ñ-Ó.°·±¸a¿g¹gÀcÀr¸lÈaÐQRÈVÑ>SÓ0TÐTÐTà;<¹9Œ�Š�Q˜�F %Ò7È!€AÜ�—‘‹L˜AÓ !§'¡'¨a°¨VÓ"3ÜÐ5°a·g±g°Y¸kÈ1ÈaÈ&ÈÐRÓSÐSä�A˜! ¨'°7¸FÓL€Fà
‡J�J„Lä�9‰9×!Ñ!×#Ñ#Ü6ŒÔà�8‰8�B�Qˆ<˜Ÿ™¢! R a R %™Ð(Ð(r#   c                   ó  • \ rS rSrSrS\S-  S\S-  S\S\S-  S\\\4   S	\\\	4   S
\\\
4   S\SSSS4S jrS rS rS rS rS rS r\R&                  R(                  S 5       rS rS rS rS\S\
S\	S\4S jrS rSrg)r¼   i¼  zWorker class of LOBPCG methods.r   Nrn   ro   rq   rÆ   rÇ   rÈ   rt   ru   ry   c
                 óð  • Xl         X l        X@l        XPl        X`l        Xpl        X€l        X�l        US   n
US   nX0l        [        R                  " U4UR                  UR                  S9U l        [        R                  " X«4UR                  UR                  S9U l        [        R                  " U
SU-  4UR                  UR                  S9U l        0 U l        SS0U l        SS0U l        SS	0U l        g )
Nr¬   rp   rE   r©   Úistepr   Ú_ç        F)r   rn   rq   rÆ   rÇ   rÈ   rt   ru   ro   r   ÚzerosrF   rG   rÃ   ÚRÚSÚtvarsÚivarsÚfvarsÚbvars)Úselfr   rn   ro   rq   rÆ   rÇ   rÈ   rt   ru   r¬   rp   s               r!   Ú__init__ÚLOBPCG.__init__¿  sÍ   € ð ŒØŒØŒØŒØŒØŒØŒØŒØ�C‰LˆØ�C‰Lˆð ŒÜ—’˜a˜T¨¯©¸¿¹ÑBˆŒÜ—’˜a˜V¨1¯7©7¸1¿8¹8ÑDˆŒÜ—’˜a  Q¡˜Z¨q¯w©w¸q¿x¹xÑHˆŒØ(*ˆŒ
Ø&-¨q \ˆŒ
Ø(+¨S zˆŒ
Ø'*¨E lˆ�
r#   c                 óø  • S/nUSU R                    3/-  nUSU R                   3/-  nUSU R                   3/-  nUSU R                   3/-  nUSU R                   3/-  nUSU R
                   3/-  nUSU R                   3/-  nUS	U R                   3/-  nUS
U R                   3/-  nUSU R                   3/-  nUSU R                   3/-  nUSU R                   3/-  nSnU H
  nX#S-   -  nM     U$ )NzLOPBCG: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Û   r   rn   rq   ro   rÃ   )rß   ÚlinesÚrÚlines       r!   Ú__str__ÚLOBPCG.__str__á  sE  € Ø�ˆØ�J˜tŸ|™|˜nÐ-Ð.Ñ.ˆØ�J˜tŸ|™|˜nÐ-Ð.Ñ.ˆØ�J˜tŸ|™|˜nÐ-Ð.Ñ.ˆØ�H˜TŸZ™Z˜LÐ)Ð*Ñ*ˆØ�H˜TŸZ™Z˜LÐ)Ð*Ñ*ˆØ�H˜TŸZ™Z˜LÐ)Ð*Ñ*ˆØ�H˜TŸZ™Z˜LÐ)Ð*Ñ*ˆØ�D˜Ÿ™˜�/Ð"Ñ"ˆØ�D˜Ÿ™˜�/Ð"Ñ"ˆØ�E˜$Ÿ'™'˜Ð#Ð$Ñ$ˆØ�D˜Ÿ™˜�/Ð"Ñ"ˆØ�D˜Ÿ™˜�/Ð"Ñ"ˆØˆÛˆDØ˜‘ÑŠAñ àˆr#   c                 óZ  • U R                   S   S:X  Ga(  [        [        R                  " U R                  5      5      nUS-  n[        [        R                  " [
        R                  " U R                  U R                  5      5      5      U-  n[        [        R                  " [
        R                  " U R                  U R                  5      5      5      U-  nXR                  S'   X0R                  S'   X@R                  S'   U R                  S   U R                   S'   SU R                   S	'   SU R                   S
'   U R                  S:X  a  U R                  5         OU R                  5         U R                   S   S-
  U R                   S'   U R                   S   S-   U R                   S'   g)z#Set and update iteration variables.rÕ   r   r
   ÚX_normÚA_normÚB_normrr   Úiterations_leftÚconverged_countÚconverged_endr«   r&   N)rÜ   r   r   Únormro   rµ   r   r   rn   rÝ   rÆ   rt   Ú_update_orthoÚ_update_basic)rß   rë   ÚiX_normrì   rí   s        r!   r¹   ÚLOBPCG.updateô  s@  € à�:‰:�gÑ !Ô#Üœ5Ÿ:š: d§f¡fÓ-Ó.ˆFØ˜b‘jˆGÜœ5Ÿ:š:¤f§m¢m°D·F±F¸D¿F¹FÓ&CÓDÓEÈÑOˆFÜœ5Ÿ:š:¤f§m¢m°D·F±F¸D¿F¹FÓ&CÓDÓEÈÑOˆFØ#)�J‰J�xÑ Ø#)�J‰J�xÑ Ø#)�J‰J�xÑ Ø,0¯L©L¸Ñ,AˆD�J‰JÐ(Ñ)Ø,-ˆD�J‰JÐ(Ñ)Ø*+ˆD�J‰J�Ñ'à�;‰;˜'Ó!Ø×ÑÕ à×ÑÔ à(,¯
©
Ð3DÑ(EÈÑ(Iˆ�
‰
Ð$Ñ%Ø"Ÿj™j¨Ñ1°AÑ5ˆ�
‰
�7Òr#   c                 ó¾   • [         R                  nU" U R                  U R                  5      U" U R                  U R                  5      U R
                  -  -
  U l        g)z"Update residual R from A, B, X, E.N)rµ   r   r   ro   rn   rÃ   rÙ   )rß   Úmms     r!   Úupdate_residualÚLOBPCG.update_residual
  s>   € ä�]‰]ˆÙ�D—F‘F˜DŸF™FÓ#¡b¨¯©°·±Ó&8¸4¿6¹6Ñ&AÑAˆ�r#   c           	      ó   • U R                   S   nU R                  S   nU R                  S   nU R                  S   nU R                  U R                  U R
                  pvn[        R                  " USS5      [        R                  " USS5      U[        R                  " USUR                  S    5      U-  -   -  -  nX‚:  n	S	n
U	 H  nU(       d    O	U
S
-  n
M     X¡:  a  [        SU SU
 S35      eX R                   S'   X€R                  S'   U
$ )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ï   rs   rì   rí   r%   )r   Nr
   r   r&   z(the number of converged eigenpairs (was ú, got z) cannot decreaseÚrerr)rÜ   rÇ   rÝ   rÃ   ro   rÙ   r   rñ   Úabsr'   r´   rÛ   )rß   Ú
prev_countrs   rì   rí   rÃ   ro   rÙ   rü   Ú	convergedÚcountÚbs               r!   Úupdate_converged_countÚLOBPCG.update_converged_count  s  € ð —Z‘ZÐ 1Ñ2ˆ
Ø�l‰l˜5Ñ!ˆØ—‘˜HÑ%ˆØ—‘˜HÑ%ˆØ—&‘&˜$Ÿ&™& $§&¡&ˆaˆÜ�zŠz˜!˜Q Ó%Ü�JŠJ�q˜!˜TÓ" f¬u¯yªy¸¸=¸Q¿W¹WÀR¹[Ð9IÓ/JÈVÑ/SÑ&SÑTñ
ˆð ‘Jˆ	ØˆÛˆAÞñ Ø�Q‰JŠEñ ð ÓÜ Ø:¸:¸,ÀfÈUÈGÐSdÐeóð ð ).�
‰
Ð$Ñ%Ø!�
‰
�6ÑØˆr#   c                 ó¸   • U R                   R                  SS5      =(       d8    U R                  S   S:H  =(       d    U R                  S   U R                  S   :¬  $ )zŒReturn True to stop iterations.

Note that tracker (if defined) can force-stop iterations by
setting ``worker.bvars['force_stop'] = True``.
Ú
force_stopFrî   r   rï   r<   )rÞ   rº   rÜ   rÆ   ©rß   s    r!   Ústop_iterationÚLOBPCG.stop_iteration.  sT   € ð �J‰J�N‰N˜<¨Ó/÷ BØ�z‰zÐ+Ñ,°Ñ1÷Bà�z‰zÐ+Ñ,°·±¸SÑ0AÑAð	
r#   c                 óž  • U R                  5         [        R                  R                  5       (       d  U R                  b  U R                  5         U R                  5       (       dh  U R                  5         [        R                  R                  5       (       d  U R                  b  U R                  5         U R                  5       (       d  Mg  gg)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¹   r   rœ   r�   ru   r½   r  r  s    r!   rÂ   Ú
LOBPCG.run:  s†   € ð 	�‰Œä�y‰y×%Ñ%×'Ñ'¨D¯L©LÑ,DØ×ÑÔà×%Ñ%×'Ñ'Ø�K‰KŒMä—9‘9×)Ñ)×+Ñ+°·±Ñ0HØ×!Ñ!Ô#ð	 ×%Ñ%×'Õ'r#   c                 ó   • g)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  s    r!   r½   ÚLOBPCG.call_trackerL  s   � r#   c                 ó˜  • [         R                  nU R                  S   nU R                  S   nU R                  S   nU R                  S   nU R                  S   S:X  GaK  U R                  U R                  5      n[        R                  " [        R                  " U R                  U R                  5      U5      n[        R                  " Xu5      u  p‰U" U R                  U" Xi5      5      U R                  SS& X€R                  SS& Sn
U R                  5         U R                  5       nU R                  U R                  SSU24'   [        R                  " U R                  U R                   5      nXJ-   UR"                  S	   -   =U R                  S'   nX°R                  SS2XJ-   U24'   gU R                  SS2X224   nU R                  U5      n[        R                  " [        R                  " U R                  U5      U5      n[        R                  " Xu5      u  pÙU" XÁ" XiSS2SXC-
  24   5      5      U R                  SS2US24'   USXC-
   U R                  US& U" XÁ" XiSS2US
U-  U-
  24   5      5      nUR"                  S	   n
U R                  5         U R                  5       nU R                  U R                  SSU24'   XàR                  SS2XDU
-   24'   [        R                  " U R                  U R                   SS2US24   5      nXJ-   UR"                  S	   -   =U R                  S'   nX°R                  SS2XJ-   U24'   g)zD
Update or initialize iteration variables when `method == "basic"`.
rð   rï   rp   r[   rÕ   r   N.r
   r%   )r   r   rÜ   rÆ   rÈ   Ú_get_rayleigh_ritz_transformro   rµ   Úqformr   ÚsymeigrÃ   rø   r  rÚ   rq   rÙ   r'   )rß   r÷   ÚnsÚncrp   r[   ÚRiÚMrÃ   ÚZÚnpÚWÚS_ÚE_ÚPs                  r!   ró   ÚLOBPCG._update_basicX  s»  € ô �\‰\ˆØ�Z‰Z˜Ñ(ˆØ�Z‰ZÐ)Ñ*ˆØ�L‰L˜ÑˆØ—,‘,˜yÑ)ˆà�:‰:�gÑ !Ô#Ø×2Ñ2°4·6±6Ó:ˆBÜ—’œVŸ\š\¨$¯&©&°$·&±&Ó9¸2Ó>ˆAÜ—=’= Ó,‰DˆAÙ˜4Ÿ6™6¡2 b£9Ó-ˆD�F‰F‘1ˆIØ�F‰F‘1ˆIØˆBØ× Ñ Ô"Ø×,Ñ,Ó.ˆBØ"Ÿf™fˆD�F‰F�3˜˜˜�7‰Oä—’˜dŸg™g t§v¡vÓ.ˆAØ/0©v¸¿¹À¹Ñ/CÐCˆD�J‰J�Ñ'¨"Ø%&�F‰F’1�a‘f˜r�k�>Ò"à—‘š˜2˜5˜Ñ!ˆBØ×2Ñ2°2Ó6ˆBÜ—’œVŸ\š\¨$¯&©&°"Ó5°rÓ:ˆAÜ—M’M !Ó-‰EˆBÙ  B rªQ°°!±&°¨[©>Ó$:Ó;ˆD�F‰F’1�b‘c�6‰NØ˜X˜q™v˜,ˆD�F‰F�2�3ˆKÙ�2�r˜"¢ 1 q¨1¡u¨r¡z >Ð 1Ñ2Ó3Ó4ˆAØ—‘˜‘ˆBà× Ñ Ô"Ø×,Ñ,Ó.ˆBØ"Ÿf™fˆD�F‰F�3˜˜˜�7‰OØ$%�F‰F’1�a˜b™&�j�=Ñ!Ü—’˜dŸg™g t§v¡vªa°±¨f¡~Ó6ˆAà/0©v¸¿¹À¹Ñ/CÐCˆD�J‰J�Ñ'¨"Ø%&�F‰F’1�a‘f˜r�k�>Ò"r#   c                 óh  • [         R                  nU R                  S   nU R                  S   nU R                  S   nU R                  S   nU R                  S   S:X  Ga1  U R                  U R                  5      n[        R                  " [        R                  " U R                  U R                  5      U5      n[        R                  " Xu5      u  p‰U" U R                  U" Xi5      5      U l        U R                  5         Sn
U R                  5       nU R                  U R                  SS2SU24'   U R                  U R                  U R                  5      nXJ-   UR                   S   -   =o R                  S'   X°R                  SS2XJ-   U24'   gU R                  SS2X224   n[        R                  " [        R                  " U R                  U5      U5      u  pÙU" XÉSS2SXC-
  24   5      U R                  SS2US24'   USXC-
   U R"                  US& U" XÁ" U	SS2XC-
  S24   [        R$                  " U	SXC-
  2XC-
  S24   R&                  5      5      5      nUR                   S   n
U R                  5         U R                  5       nU R                  U R                  SS2SU24'   XàR                  SS2XDU
-   24'   U R                  U R                  SS2US24   U R                  SS2SXJ-   24   5      nXJ-   UR                   S   -   =o R                  S'   X°R                  SS2XJ-   U24'   g)	zD
Update or initialize iteration variables when `method == "ortho"`.
rð   rï   rp   r[   rÕ   r   Nr
   )r   r   rÜ   rÆ   rÈ   r  ro   rµ   r  r   r  rø   r  rÚ   Ú
_get_orthorÙ   r'   rÃ   Úbasisr   )rß   r÷   r  r  rp   r[   r  r  Ú_Er  r  r  r  r  r  s                  r!   rò   ÚLOBPCG._update_orthoƒ  s³  € ô �\‰\ˆØ�Z‰Z˜Ñ(ˆØ�Z‰ZÐ)Ñ*ˆØ�L‰L˜ÑˆØ—,‘,˜yÑ)ˆà�:‰:�gÑ !Ô#Ø×2Ñ2°4·6±6Ó:ˆBÜ—’œVŸ\š\¨$¯&©&°$·&±&Ó9¸2Ó>ˆAÜ—M’M !Ó-‰EˆBÙ˜Ÿ™¡ 2£	Ó*ˆDŒFØ× Ñ Ô"ØˆBØ×,Ñ,Ó.ˆBØ ŸF™FˆD�F‰F’1�b�q�b�5‰MØ—‘ §¡¨¯©Ó/ˆAØ/0©v¸¿¹À¹Ñ/CÐCˆB—‘˜OÑ,Ø%&�F‰F’1�a‘f˜r�k�>Ò"ð —‘š˜2˜5˜Ñ!ˆBä—M’M¤&§,¢,¨t¯v©v°rÓ":¸GÓD‰EˆBñ   ¢a¨¨1©6¨ k¡NÓ3ˆD�F‰F’1�b‘c�6‰NØ˜X˜q™v˜,ˆD�F‰F�2�3ˆKÙ�2�r˜!šA˜q™v™x˜K™.¬&¯,ª,°q¸¸1¹6¸À1Á6Á8Ð9KÑ7L×7OÑ7OÓ*PÓQÓRˆAØ—‘˜‘ˆBð × Ñ Ô"Ø×,Ñ,Ó.ˆBð !ŸF™FˆD�F‰F’1�b�q�b�5‰MØ$%�F‰F’1�a˜b™&�j�=Ñ!Ø—‘ §¡¢q¨"©# v¡°·±²q¸(¸A¹F¸(°{Ñ0CÓDˆAØ/0©v¸¿¹À¹Ñ/CÐCˆB—‘˜OÑ,Ø%&�F‰F’1�a‘f˜r�k�>Ò"r#   c                 óP  • U R                   n[        R                  " X!5      nUR                  SSS5      S-  nUR	                  UR
                  S   S5      n[        R                  R                  X4-  U-  SS9n[        R                  R                  XdR                  5       SSS	9$ )
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)`.

r   r	   r
   ç      à¿r&   T)ÚupperF)r#  Úleft)rn   rµ   r  r   rÀ   r'   r   rX   rY   Úsolve_triangularr   )rß   rÚ   rn   ÚSBSÚd_rowÚd_colrÙ   s          r!   r  Ú#LOBPCG._get_rayleigh_ritz_transform°  s—   € ðZ �F‰FˆÜ�lŠl˜1Ó ˆØ—‘˜Q  BÓ'¨4Ñ/ˆØ—‘˜eŸk™k¨!™n¨aÓ0ˆä�L‰L×!Ñ! 3¡;°%Ñ"7¸tÐ!ÐDˆÜ�|‰|×,Ñ,Ø×ÑÓ!¨°Eð -ð 
ð 	
r#   r   ÚdropÚtauc           	      óÚ  • [         R                  " U5      S:X  a  U$ [        R                  " U R                  U5      nUR                  SSS5      n[         R                  " [        U5      S:g  5      n[        U5      S:w  a  [        SU 35      e[        US   5      [        U5      :  a¿  USS2US   4   n[         R                  " U5      S:X  a  U$ [        R                  " U R                  U5      nUR                  SSS5      n[         R                  " [        U5      S:g  5      n[        US   5      [        U5      :w  a&  [        S[        U5       S	[        US   5       35      eUS
-  R                  UR                  S   S5      nXG-  UR                  -  n[        R                  " U5      u  pšU[        U	5      R                  5       -  nU(       aP  [         R                  " X›:„  5      n[        U5      S:w  a  [        SU 35      eXœS      n	U
SS2US   4   n
X|S      nOX¹[         R                  " X›:  5      S   '   [         R                  " XR                  -  X©S
-  -  5      $ )ak  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`.

r   r	   r
   r×   r&   z"expected nz to have length 1, got Nzexpected nz[0] length rû   r"  z$expected keep to have length 1, got )r   Únumelrµ   r  rn   r   Úwhererý   rJ   r´   rÀ   r'   r   r  Úmaxr   )rß   r   r*  r+  ÚUBUÚdÚnzr(  ÚDUBUDrÃ   r  ÚtÚkeeps                r!   Ú	_get_svqbÚLOBPCG._get_svqbç  s  € ô, �;Š;�q‹>˜QÓØˆHÜ�lŠl˜4Ÿ6™6 1Ó%ˆØ�L‰L˜˜B Ó#ˆô �[Š[œ˜Q› 3™Ó'ˆÜˆr‹7�a‹<Ü Ð#EÀbÀTÐ!JÓKÐKÜˆr�!‰u‹:œ˜A›ÓØ’!�R˜‘U�(‘ˆAÜ�{Š{˜1‹~ Ó"Ø�Ü—,’,˜tŸv™v qÓ)ˆCØ—‘˜Q  BÓ'ˆAÜ—’œS ›V s™]Ó+ˆBÜ�2�a‘5‹zœS ›VÓ#Ü$Ø,¬S°«V¨H°F¼3¸rÀ!¹u»:¸,ÐGóð ð
 �D‘×!Ñ! !§'¡'¨!¡*¨aÓ0ˆØ‘ §¡Ñ(ˆÜ�}Š}˜UÓ#‰ˆØ”#�a“&—*‘*“,ÑˆÞÜ—;’;˜q™uÓ%ˆDÜ�4‹y˜A‹~Ü$Ð'KÈDÈ6Ð%RÓSÐSØ�q‘'‘
ˆAØ’!�T˜!‘W�*‘ˆAØ˜q™'‘N‰Eà)*Œu�{Š{˜1™5Ó! 1Ñ%Ñ&ä�|Š|Ø—‘‰LØ�4‘‰Kó
ð 	
r#   c           
      ó<  • [         R                  n[        R                  nU R                  S   nU R                  S   nU R                  S   nU R                  S   nU R                  S   n	U R                  S   n
U R
                  S   n[        U R                  R                  5       5       HN  nUR                  S5      (       d  M  UR                  S	5      (       d  M3  U R                  R                  U5        MP     U R                  R                  S
S5        U R                  R                  SS5        [         R                  " U" U R                  U5      5      nU" U R                  U5      nU" UR                  U5      nS=nn[!        U	5       GHf  nX" X/5      -
  nSnUn[!        U
5       GHS  nU(       a  U R#                  UUU5      nSnUnOU R#                  USU5      n[         R$                  " U5      S:X  a$  UU R                  S
'   UU R                  S'   Us  s  $ U" U R                  U5      nU" UR                  U5      n[         R                  " U5      n[         R                  " U5      nU[         R&                  " UR(                  S   UR*                  UR,                  S9-
  n[         R                  " U5      n[/        U5      [/        UU-  5      S-  -  nSU SU S3nUU R                  U'   UU:  d  GMT    O   U" UR                  U5      n[         R                  " U5      n[         R                  " U5      n[/        U5      [/        UU-  5      S-  -  nSU S3nUU R                  U'   UU:  a    O}XQR(                  S   UR(                  S   -   :  d  GM  U R                  nUc  [1        S5      e[3        SUR(                  S    SUR(                  S    SUR(                  S    S35      e   UU R                  S
'   UU R                  S'   U$ )aA  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²   Úortho_Ú_rerrÚortho_ir   Úortho_jFTr
   )rG   rF   zortho_UBUmI_rerr[z, Ú]zortho_VBU_rerr[zB must not be Nonez$Overdetermined shape of U: #B-cols(=z) >= #U-cols(=z) + #V-cols(=z) must hold)r   r   rµ   rÆ   rÇ   rÈ   r(   rÝ   ÚkeysÚ
startswithÚendswithÚpoprÜ   rñ   rn   r   r*   r6  r-  rH   r'   rG   rF   r   r´   r†   )rß   r   ÚVr÷   Úmm_Br¬   Ú	tau_orthoÚtau_dropÚtau_replaceÚi_maxÚj_maxÚuse_dropÚvkeyÚBV_normÚBUÚVBUr2   Újr*  Útau_svqbr0  ÚU_normÚBU_normrÙ   ÚR_normrü   ÚVBU_normrn   s                               r!   r  ÚLOBPCG._get_ortho,  s‹  € ô2 �\‰\ˆÜ�}‰}ˆØ�L‰L˜ÑˆØ—L‘L Ñ-ˆ	Ø—<‘<Ð 0Ñ1ˆØ—l‘lÐ#6Ñ7ˆØ—‘˜]Ñ+ˆØ—‘˜]Ñ+ˆð —<‘<Ð 0Ñ1ˆô ˜Ÿ™Ÿ™Ó*Ö+ˆDØ�‰˜x×(Ó(¨T¯]©]¸7×-CÓ-CØ—
‘
—‘˜tÖ$ñ ,ð 	�
‰
�‰�y !Ô$Ø�
‰
�‰�y !Ô$ä—*’*™T $§&¡&¨!›_Ó-ˆÙ�$—&‘&˜!‹_ˆÙ�—‘�r‹lˆØˆ	ˆˆAÜ�u—ˆAØ�B�q“J‘ˆAØˆDØˆHÜ˜5—\�ÞØŸ™ q¨$°Ó9�AØ�DØ*‘HàŸ™ q¨%°Ó=�AÜ—;’;˜q“> QÓ&à,-�D—J‘J˜yÑ)Ø,-�D—J‘J˜yÑ)Ø”HÙ˜$Ÿ&™& !“_�Ù˜Ÿ™˜r“l�ÜŸš A›�ÜŸ*š* R›.�Øœ%Ÿ)š) C§I¡I¨b¡M¸#¿*¹*ÈCÏIÉIÑVÑV�ÜŸš A›�ä˜V“}¤u¨W°vÑ-=Ó'>À"Ñ'DÑD�Ø*¨1¨#¨R°¨s°!Ð4�Ø#'�—
‘
˜4Ñ Ø˜)Ö#Ùñ/ "ñ0 �Q—T‘T˜2“,ˆCÜ—z’z #“ˆHÜ—Z’Z “]ˆFÜ˜“?¤U¨7°VÑ+;Ó%<ÀÑ%BÑBˆDØ$ Q C qÐ)ˆDØ#ˆD�J‰J�tÑØ�iÓÙØ—7‘7˜2‘; §¡¨¡Ñ,Ö,ð —F‘F�Ø‘9Ü(Ð)=Ó>Ð>Ü ð!Ø!"§¡¨¡ ¨^¸A¿G¹GÀB¹K¸=ÈÐVW×V]ÑV]Ð^`ÑVaÐUbÐbmðoóð ñU ð\ !"ˆ�
‰
�9ÑØ !ˆ�
‰
�9ÑØˆr#   )r   rn   rÃ   rÙ   rÚ   ro   rÈ   rÞ   rÇ   rÝ   rq   rÆ   rÜ   rt   ru   rÛ   )r‘   r’   r“   r”   Ú__doc__r   r™   r˜   r–   r   r—   rà   rè   r¹   rø   r  r  rÂ   r   rœ   Úunusedr½   ró   rò   r  r6  r  rš   r�   r#   r!   r¼   r¼   ¼  s  † Ù)ð 3à�D‰=ð 3ð �D‰=ð 3ð ð	 3ð
 �T‰Mð 3ð �c˜3�h‘ð 3ð �c˜5�jÑ!ð 3ð �c˜4�i‘ð 3ð ð 3ð ð 3ð 
ô 3òDò&6ò,Bò
ò>

ò$ð$ ‡Y�Y×Ññó ðò)'òV+'òZ5
ðnC
˜6ð C
¨ð C
°Eð C
¸fô C
õJ`r#   r¼   c                 ó&   • U R                  U 5        g r{   )ru   r  s    r!   r»   r»   ”  s   € Ø‡L�L�Õr#   r{   r�   )rU  r   r   rµ   r   Útorch.overridesr   r   Ú__all__r"   r5   r=   rL   rS   rh   rj   ÚautogradÚFunctionrl   r–   r   r—   r˜   r™   r‰   r   r}   r¼   r½   rÄ   r»   r�   r#   r!   Ú<module>r\     sÈ  ðá Fó ß 1ß Eð ˆ*€òò'5òTô>>ô(>ò"hòVUôV˜UŸ^™^×4Ñ4ô Vðv ØØØØØØØØØØ+/Ø-1Ø,0ñmØðmà
ˆT�zðmð ��}ðmð ��}ð	mð
 ˆT�zðmð 	�‰ðmð �‰:ðmð 
�‰ðmð �D‰[ðmð �$‰Jðmð ðmð ˜˜S˜‘> DÑ(ðmð ˜˜U˜
Ñ# dÑ*ðmð ˜˜T˜	‘? TÑ)ðmð ˆ6�6ˆ>Ñõmðd ØØØØØØØØØØ+/Ø-1Ø,0ñr)Øðr)à
ˆT�zðr)ð ��}ðr)ð ��}ð	r)ð
 ˆT�zðr)ð 	�‰ðr)ð �‰:ðr)ð 
�‰ðr)ð �D‰[ðr)ð �$‰Jðr)ð ðr)ð ˜˜S˜‘> DÑ(ðr)ð ˜˜U˜
Ñ# dÑ*ðr)ð ˜˜T˜	‘? TÑ)ðr)ð ˆ6�6ˆ>Ñõr)÷jPñ Pðj "×.Ñ.Ð ór#   