+
    –°³j)  ã                   óz   € R t RR.t^ RIt^ RIHtHt ^ RIHtHt RR R llt	RR R	 llt
RR
 R lltRR R lltR# )zBImplement various linear algebra algorithms for low rank matrices.Úsvd_lowrankÚpca_lowrankN)Ú_linalg_utilsÚTensor)Úhandle_torch_functionÚhas_torch_functionc          
      óp   € V ^8„  d   QhR\         R\        R\        R,          R\         R,          R\         /# )é   ÚAÚqÚniterNÚMÚreturn)r   Úint)Úformats   "ÚO/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/_lowrank.pyÚ__annotate__r      sI   € ÷ Gñ GÜðGä
ðGô ��:ðGô �…}ð	Gô
 ñGó    c                óð  € Vf   ^MTpV P                  4       '       g   \        P                  ! V 4      MV P                  p\        P                  p\
        P                  ! V P                  R,          WV P                  R7      pV! W4      pVe   Wu! W64      ,
          p\
        P                  P                  V4      P                  p\        V4       FŸ  p	V! V P                  V4      pVe   Wu! VP                  V4      ,
          p\
        P                  P                  V4      P                  pV! W4      pVe   Wu! W84      ,
          p\
        P                  P                  V4      P                  pK¡  	  V# )a  Return tensor :math:`Q` with :math:`q` orthonormal columns such
that :math:`Q Q^H A` approximates :math:`A`. If :math:`M` is
specified, then :math:`Q` is such that :math:`Q Q^H (A - M)`
approximates :math:`A - M`. without instantiating any tensors
of the size of :math:`A` or :math:`M`.

.. note:: The implementation is based on the Algorithm 4.4 from
          Halko et al., 2009.

.. note:: For an adequate approximation of a k-rank matrix
          :math:`A`, where k is not known in advance but could be
          estimated, the number of :math:`Q` columns, q, can be
          chosen according to the following criteria: in general,
          :math:`k <= q <= min(2*k, m, n)`. For large low-rank
          matrices, take :math:`q = k + 5..10`.  If k is
          relatively small compared to :math:`min(m, n)`, choosing
          :math:`q = k + 0..2` may be sufficient.

.. note:: To obtain repeatable results, reset the seed for the
          pseudorandom number generator

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

    q (int): the dimension of subspace spanned by :math:`Q`
             columns.

    niter (int, optional): the number of subspace iterations to
                           conduct; ``niter`` must be a
                           nonnegative integer. In most cases, the
                           default value 2 is more than enough.

    M (Tensor, optional): the input tensor's mean of size
                          :math:`(*, m, n)`.

References::
    - Nathan Halko, Per-Gunnar Martinsson, and Joel Tropp, Finding
      structure with randomness: probabilistic algorithms for
      constructing approximate matrix decompositions,
      arXiv:0909.4061 [math.NA; math.PR], 2009 (available at
      `arXiv <http://arxiv.org/abs/0909.4061>`_).
©ÚdtypeÚdeviceéÿÿÿÿ)Ú
is_complexÚ_utilsÚget_floating_dtyper   ÚmatmulÚtorchÚrandnÚshaper   ÚlinalgÚqrÚQÚrangeÚmH)
r
   r   r   r   r   r   ÚRÚXr"   Ú_s
   &&&&      r   Úget_approximate_basisr(      s  € ðb ’‰A E€EØ01·±·²ŒF×%Ò% aÔ(ÀAÇGÁG€EÜ�]‰]€Fä�Š�A—G‘G˜B•K ¸¿¹ÔA€Añ
 	ˆq‹€AØ‚}Ø��q“ÕˆÜ�‰�‰˜Ó×Ñ€AÜ�5Ž\ˆÙ�1—4‘4˜‹OˆØŠ=Ø�F˜1Ÿ4™4 “OÕ#ˆAÜ�L‰L�O‰O˜AÓ× Ñ ˆÙ�1‹LˆØŠ=Ø�F˜1“LÕ ˆAÜ�L‰L�O‰O˜AÓ× Ñ Šñ ð €Hr   c                óª   € V ^8„  d   QhR\         R\        R,          R\        R,          R\         R,          R\        \         \         \         3,          /# ©r	   r
   r   Nr   r   r   ©r   r   Útuple)r   s   "r   r   r   U   sR   € ÷ =2ñ =2Üð=2ä
ˆT…zð=2ô ��:ð=2ô �…}ð	=2ô
 Œ6”6œ6Ð!Õ"ñ=2r   c           	     ó@  € \         P                  P                  4       '       go   W3p\        \	        \
        V4      4      P                  \         P                  \        R4      34      '       g%   \        V4      '       d   \        \        W@WVR7      # \        WW#R7      # )a*  Return the singular value decomposition ``(U, S, V)`` of a matrix,
batches of matrices, or a sparse matrix :math:`A` such that
:math:`A \approx U \operatorname{diag}(S) V^{\text{H}}`. In case :math:`M` is given, then
SVD is computed for the matrix :math:`A - M`.

.. note:: The implementation is based on the Algorithm 5.1 from
          Halko et al., 2009.

.. note:: For an adequate approximation of a k-rank matrix
          :math:`A`, where k is not known in advance but could be
          estimated, the number of :math:`Q` columns, q, can be
          chosen according to the following criteria: in general,
          :math:`k <= q <= min(2*k, m, n)`. For large low-rank
          matrices, take :math:`q = k + 5..10`.  If k is
          relatively small compared to :math:`min(m, n)`, choosing
          :math:`q = k + 0..2` may be sufficient.

.. note:: This is a randomized method. To obtain repeatable results,
          set the seed for the pseudorandom number generator

.. note:: In general, use the full-rank SVD implementation
          :func:`torch.linalg.svd` for dense matrices due to its 10x
          higher performance characteristics. The low-rank SVD
          will be useful for huge sparse matrices that
          :func:`torch.linalg.svd` cannot handle.

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

    q (int, optional): a slightly overestimated rank of A.

    niter (int, optional): the number of subspace iterations to
                           conduct; niter must be a nonnegative
                           integer, and defaults to 2

    M (Tensor, optional): the input tensor's mean of size
                          :math:`(*, m, n)`, which will be broadcasted
                          to the size of A in this function.

References::
    - Nathan Halko, Per-Gunnar Martinsson, and Joel Tropp, Finding
      structure with randomness: probabilistic algorithms for
      constructing approximate matrix decompositions,
      arXiv:0909.4061 [math.NA; math.PR], 2009 (available at
      `arXiv <https://arxiv.org/abs/0909.4061>`_).

N)r   r   r   )r   ÚjitÚis_scriptingÚsetÚmapÚtypeÚissubsetr   r   r   r   Ú_svd_lowrank)r
   r   r   r   Ú
tensor_opss   &&&& r   r   r   U   s~   € ôj �9‰9×!Ñ!×#Ò#Ø�Vˆ
Ü”3”t˜ZÓ(Ó)×2Ñ2Ü�\‰\œ4 ›:Ð&÷
ò 
ä  ×,Ò,Ü(Ü˜Z¨aÀôð ô ˜ eÔ1Ð1r   c                óª   € V ^8„  d   QhR\         R\        R,          R\        R,          R\         R,          R\        \         \         \         3,          /# r*   r+   )r   s   "r   r   r   •   sR   € ÷ ñ Üðä
ˆT…zðô ��:ðô �…}ð	ô
 Œ6”6œ6Ð!Õ"ñr   c                 óò  € Vf   ^MTpV P                   RR  w  rE\        P                  pVe    VP                  V P	                  4       4      pWE8  d   V P
                  p Ve   VP
                  p\        WW#R7      pV! VP
                  V 4      pVe   W†! VP
                  V4      ,
          p\        P                  P                  VRR7      w  ršpVP
                  pVP                  V	4      p	WE8  d   YÉrÉWšV3# )N©r   r   F)Úfull_matriceséþÿÿÿ)
r   r   r   Úbroadcast_toÚsizer$   r(   r   r    Úsvd)r
   r   r   r   ÚmÚnr   r"   ÚBÚUÚSÚVhÚVs   &&&&         r   r4   r4   •   sÚ   € ð ŠY‰˜A€AØ�7‰7�2�3ˆ<�D€AÜ�]‰]€FØ‚}Ø�N‰N˜1Ÿ6™6›8Ó$ˆð 	„uØ�D‰DˆØŠ=Ø—‘ˆAä˜a¨%Ô5€AÙˆq�t‰t�Q‹€AØ‚}Ø��q—t‘t˜Q“ÕˆÜ�|‰|×Ñ °ÐÓ7�H€Aˆ"Ø
�‰€AØ	�‰�‹€Aà„uØˆ1à�ˆ7€Nr   c                óŽ   € V ^8„  d   QhR\         R\        R,          R\        R\        R\        \         \         \         3,          /# )r	   r
   r   NÚcenterr   r   )r   r   Úboolr,   )r   s   "r   r   r   ·   sQ   € ÷ n;ñ n;Üðn;ä
ˆT…zðn;ô ðn;ô ð	n;ô
 Œ6”6œ6Ð!Õ"ñn;r   c           	     ó  € \         P                  P                  4       '       gD   \        V 4      \         P                  Jd'   \        V 34      '       d   \        \        V 3WW#R7      # V P                  RR w  rEVf   \        ^WE4      pM1V^ 8¼  d   V\        WE4      8:  g   \        RV R\        WE4       24      hV^ 8¼  g   \        RV R24      h\        P                  ! V 4      pV'       g   \        WVRR7      # \        P                  ! V 4      '       EdA   \        V P                  4      ^8w  d   \        R4      h\         P                   P#                  V RR	7      V,          pVP%                  4       ^ ,          p\         P&                  ! ^\        V4      VP(                  VP*                  R
7      p	W‰^ &   \         P,                  ! W—P/                  4       V^3W`P*                  R
7      p
\         P0                  ! V P                  RR ^V3,           W`P*                  R
7      p\         P                   P3                  W«4      P4                  p\        WW<R7      # V P7                  RRR7      p\        W,
          WRR7      # )a;  Performs linear Principal Component Analysis (PCA) on a low-rank
matrix, batches of such matrices, or sparse matrix.

This function returns a namedtuple ``(U, S, V)`` which is the
nearly optimal approximation of a singular value decomposition of
a centered matrix :math:`A` such that :math:`A \approx U \operatorname{diag}(S) V^{\text{H}}`

.. note:: The relation of ``(U, S, V)`` to PCA is as follows:

            - :math:`A` is a data matrix with ``m`` samples and
              ``n`` features

            - the :math:`V` columns represent the principal directions

            - :math:`S ** 2 / (m - 1)` contains the eigenvalues of
              :math:`A^T A / (m - 1)` which is the covariance of
              ``A`` when ``center=True`` is provided.

            - ``matmul(A, V[:, :k])`` projects data to the first k
              principal components

.. note:: Different from the standard SVD, the size of returned
          matrices depend on the specified rank and q
          values as follows:

            - :math:`U` is m x q matrix

            - :math:`S` is q-vector

            - :math:`V` is n x q matrix

.. note:: To obtain repeatable results, reset the seed for the
          pseudorandom number generator

Args:

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

    q (int, optional): a slightly overestimated rank of
                       :math:`A`. By default, ``q = min(6, m,
                       n)``.

    center (bool, optional): if True, center the input tensor,
                             otherwise, assume that the input is
                             centered.

    niter (int, optional): the number of subspace iterations to
                           conduct; niter must be a nonnegative
                           integer, and defaults to 2.

References::

    - Nathan Halko, Per-Gunnar Martinsson, and Joel Tropp, Finding
      structure with randomness: probabilistic algorithms for
      constructing approximate matrix decompositions,
      arXiv:0909.4061 [math.NA; math.PR], 2009 (available at
      `arXiv <http://arxiv.org/abs/0909.4061>`_).

)r   rF   r   Nzq(=z>) must be non-negative integer and not greater than min(m, n)=zniter(=z) must be non-negative integerr8   z8pca_lowrank input is expected to be 2-dimensional tensor)Údimr   T)rI   Úkeepdimr:   )r:   )r   r.   r/   r2   r   r   r   r   r   ÚminÚ
ValueErrorr   r   r4   Ú	is_sparseÚlenÚsparseÚsumÚindicesÚzerosr   r   Úsparse_coo_tensorÚvaluesÚonesÚmmÚmTÚmean)r
   r   rF   r   r>   r?   r   ÚcÚcolumn_indicesrQ   ÚC_tÚ	ones_m1_tr   ÚCs   &&&&          r   r   r   ·   s  € ôD �9‰9×!Ñ!×#Ò#Ü�‹7œ%Ÿ,™,Ó&Ô+=¸q¸d×+CÒ+CÜ(Ü˜a˜T 1°&ôð ð �W‰W�R�Sˆ\�F€Qà‚yÜ��1‹L‰Ø�1Œf˜œc !›iœÜØ�!�ÐRÔSVÐWXÓS\ÐR]Ð^ó
ð 	
ð �QŒJÜ˜7 5 'Ð)GÐHÓIÐIä×%Ò% aÓ(€EçÜ˜A¨°Ô6Ð6ä×Ò˜×ÓÜˆq�w‰w‹<˜1ÔÜÐWÓXÐXÜ�L‰L×Ñ˜Q EÐÓ*¨QÕ.ˆàŸ™› Q�ˆÜ—+’+ØÜ�ÓØ ×&Ñ&Ø!×(Ñ(ô	
ˆð $�‰
Ü×%Ò%Ø—X‘X“Z ! Q ¨u¿X¹Xô
ˆô —J’J˜qŸw™w s¨˜|¨q°!¨fÕ4¸EÏ(É(ÔSˆ	Ü�L‰L�O‰O˜CÓ+×.Ñ.ˆÜ˜A¨Ô3Ð3à�F‰F�u dˆFÓ+ˆÜ˜A�E 1°TÔ:Ð:r   )r	   N)é   r	   N)NTr	   )Ú__doc__Ú__all__r   r   r   r   Útorch.overridesr   r   r(   r   r4   r   © r   r   Ú<module>rc      s<   ðÙ Hà˜-Ð
(€ó ß 1ß E÷G÷T=2÷@÷Dn;ñ n;r   