+
    åûj!N  ã                   ó¬   € ^ RI HtHtHt ^ RIt^ RIHt ^ RIHtHt . ROt	 ! R R]P                  4      tRR R lltR	 R
 ltRR R lltRR R lltR# )é    )ÚListÚOptionalÚTupleN)Únn)Ú_autocast_disabledÚ_torch_svd_castÚZCAWhiteningc                   ó¨   a a€ ] tR t^t oRt^tRV3R lV 3R llltV3R lV 3R lltV3R lR ltRV3R lR	 llt	V3R
 lR lt
V3R ltRtVtV ;t# )r	   ax  Whiten data with a ZCA transform fitted on a data set.

``zca = ZCAWhitening(dim)`` is fitted with ``zca.fit(x)``, after which ``zca(x)`` returns ``x`` centered and
whitened. ``dim`` is the sample axis and all other axes are flattened into one feature vector, so a
``(5, 3, 2, 2)`` tensor has :math:`N = 5` samples of :math:`D = 12` features.

Convention:
    - The mean :math:`\mathbf{\mu}` and covariance :math:`\mathbf{\Sigma}` come from the flattened data
      :math:`\mathbf{X} \in \mathbb{R}^{N \times D}`. With :math:`U` the eigenvectors and :math:`S` the
      eigenvalues of :math:`\Sigma`, the transform is

      .. math::

          \mathbf{X}_{\text{zca}} = (\mathbf{X} - \mathbf{\mu})(U(S + \epsilon I)^{-1/2}U^T)^T

    - The output has the shape of the input. ``zca(x, include_fit=True)`` fits on ``x`` before transforming it.
    - Float16 and bfloat16 inputs are fitted and transformed in float32, and only the transformed output is rounded
      to the input dtype. The fitted buffers stay float32; casting the module to half precision discards that
      accuracy.
    - The fitted ``mean_vector``, ``transform_matrix`` and ``transform_inv`` are buffers: ``state_dict`` saves them
      and ``.to()`` moves and casts them. Loading a fitted state into an unfitted module fits it, and the loaded
      tensors keep the device and dtype they were saved with, so move the module after loading. A checkpoint saved
      before the fitted state was persisted holds none of it, and loading it keeps the current fit.

Args:
    dim: sample axis.
    eps: value added to the eigenvalues before the inverse square root.
    unbiased: divide the covariance by :math:`N - 1` if ``True``, by :math:`N` otherwise.
    detach_transforms: detach the fitted tensors from the graph, so gradients do not flow through the fit.
    compute_inv: also compute the inverse transform that ``inverse_transform`` needs.

Shape:
    - x: tensor ``(D_0, ..., D_dim, ..., D_N)`` whose axis ``dim`` indexes the samples.
    - x_whiten: same shape as ``x``.

.. note::
   The fit takes an SVD of the covariance, whose backward step yields NaNs if the singular values are not unique,
   see :func:`torch.svd`. A working example is in the `ZCA whitening tutorial
   <https://colab.sandbox.google.com/github/kornia/tutorials/blob/master/source/zca_whitening.ipynb>`__.

See Also:
    - :func:`zca_whiten`: fits and whitens in one call.
    - :func:`zca_mean`: computes the transform and mean this module stores.
    - :func:`linear_transform`: applies a given transform and mean.

Examples:
    >>> x = torch.tensor([[0,1],[1,0],[-1,0],[0,-1]], dtype = torch.float32)
    >>> zca = ZCAWhitening().fit(x)
    >>> x_whiten = zca(x)
    >>> zca = ZCAWhitening()
    >>> x_whiten = zca(x, include_fit = True) # Includes the fitting step
    >>> x_whiten = zca(x) # Can run now without the fitting set
    >>> # Enable backprop through ZCA fitting process
    >>> zca = ZCAWhitening(detach_transforms = False)
    >>> x_whiten = zca(x, include_fit = True) # Includes the fitting step

References:
    [1] `Stanford PCA & ZCA whitening tutorial <http://ufldl.stanford.edu/tutorial/unsupervised/PCAWhitening/>`_

c                ó<   <€ V ^8„  d   QhRS[ RS[RS[RS[RS[RR/# )é   ÚdimÚepsÚunbiasedÚdetach_transformsÚcompute_invÚreturnN)ÚintÚfloatÚbool)ÚformatÚ__classdict__s   "€ÚNC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\enhance\zca.pyÚ__annotate__ÚZCAWhitening.__annotate__]   sG   ø€ ÷ 4ñ 4áð4ñ ð4ñ ð	4ñ
  ð4ñ ð4ð 
ñ4ó    c                óÚ   <€ \         SV `  4        Wn        W n        W0n        W@n        WPn        R V n        V P                  RR4       V P                  RR4       V P                  RR4       R# )FÚmean_vectorNÚtransform_matrixÚtransform_inv)	ÚsuperÚ__init__r   r   r   r   r   ÚfittedÚregister_buffer)Úselfr   r   r   r   r   Ú	__class__s   &&&&&&€r   r!   ÚZCAWhitening.__init__]   sc   ø€ ô 	‰ÑÔàŒØŒØ ŒØ!2ÔØ&ÔàˆŒà×Ñ˜]¨DÔ1Ø×ÑÐ/°Ô6Ø×Ñ˜_¨dÖ3r   c                ó¢   <€ V ^8„  d   QhRS[ S[S[P                  3,          RS[RS[ RS[RS[S[,          RS[S[,          RS[S[,          RR	/# )
r   Ú
state_dictÚprefixÚlocal_metadataÚstrictÚmissing_keysÚunexpected_keysÚ
error_msgsr   N)ÚdictÚstrÚtorchÚTensorr   Úlist)r   r   s   "€r   r   r   s   su   ø€ ÷  8ñ  8á™™eŸl™lÐ*Õ+ð 8ñ ð 8ñ ð	 8ñ
 ð 8ñ ™3•ið 8ñ ™c�ð 8ñ ™•Ið 8ð 
ñ 8r   c           	     ó^  <€ VP                  R 4      pR Fl  p	W),           p
V P                  V	,          pW¡9   d2   Vf,   \        P                  ! W,          4      V P                  V	&   KS  KU  Vf   K[  Ve
   V^8  g   Kh  W±V
&   Kn  	  \        SV `  VVVVVVV4       V P                  RJV n        R# )ÚversionN)r   r   r   )ÚgetÚ_buffersr1   Ú
empty_liker    Ú_load_from_state_dictr   r"   )r$   r(   r)   r*   r+   r,   r-   r.   r5   ÚnameÚkeyÚcurrentr%   s   &&&&&&&&    €r   r9   Ú"ZCAWhitening._load_from_state_dicts   s±   ø€ ð !×$Ñ$ YÓ/ˆÛHˆDØ•-ˆCØ—m‘m DÕ)ˆGØÔ Ø’?ä*/×*:Ò*:¸:½?Ó*K�D—M‘M $Ó'ñ #ð Ô$¨'ª/¸WÀq¾[à")˜3“ñ Iô 	‰Ñ%ØØØØØØØô	
ð ×+Ñ+°4Ð7ˆŽr   c                ó8   <€ V ^8„  d   QhRS[ P                  RR/# )r   Úxr   r	   ©r1   r2   )r   r   s   "€r   r   r   •   s   ø€ ÷ ñ ‘U—\‘\ð  nñ r   c                ó¾  € \        WP                  V P                  V P                  V P                  4      w  r#pW0n        W n        Vf   VP                  ^ 4      V n        MW@n        V P                  '       d^   V P
                  P                  4       V n        V P                  P                  4       V n        V P                  P                  4       V n        RV n        V # )a  Fit ZCA whitening matrices to the data.

Args:
    x: Input data.

Returns:
    Returns a fitted ZCAWhitening object instance.

Raises:
    ValueError: If the sample dimension has fewer than two entries with ``unbiased=True``, or none with
        ``unbiased=False``.

T)Úzca_meanr   r   r   r   r   r   Ú	new_emptyr   r   Údetachr"   )r$   r?   ÚTÚmeanÚT_invs   &&   r   ÚfitÚZCAWhitening.fit•   s®   € ô " !§X¡X¨t¯}©}¸d¿h¹hÈ×HXÑHXÓY‰ˆ�àÔØ !ÔØŠ=Ø!"§¡¨Q£ˆDÕà!&Ôà×!×!Ð!Ø#×/Ñ/×6Ñ6Ó8ˆDÔØ$(×$9Ñ$9×$@Ñ$@Ó$BˆDÔ!Ø!%×!3Ñ!3×!:Ñ!:Ó!<ˆDÔàˆŒàˆr   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# )r   r?   Úinclude_fitr   )r1   r2   r   )r   r   s   "€r   r   r   µ   s/   ø€ ÷ Vñ V™Ÿ™ð V±Dð VÁUÇ\Á\ñ Vr   c                óÄ   € V'       d   V P                  V4       V P                  '       g   \        R4      h\        WP                  V P
                  V P                  4      # )zºApply the whitening transform to the data.

Args:
    x: Input data.
    include_fit: Indicates whether to fit the data as part of the forward pass.

Returns:
    The transformed data.

úTNeeds to be fitted first before running. Please call fit or set include_fit to True.)rH   r"   ÚRuntimeErrorÚlinear_transformr   r   r   )r$   r?   rK   s   &&&r   ÚforwardÚZCAWhitening.forwardµ   sF   € ÷ Ø�H‰H�QŒKà�{�{ˆ{ÜÐuÓvÐvä ×#8Ñ#8¸$×:JÑ:JÈDÏHÉHÓUÐUr   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r   r?   r   r@   )r   r   s   "€r   r   r   È   s'   ø€ ÷ Kñ K¡5§<¡<ð K±E·L±Lñ Kr   c                óè  € V P                   '       g   \        R4      hV P                  '       g   \        R4      hV P                  f   \	        R4      hVP
                  \        P                  \        P                  39   d˜   \        P                  P                  4       '       gt   \        VP                  P                  4      ;_uu_ 4        V P                  P                  4       P!                  V P"                  P                  4       4      ) pRRR4       M&V P                  P!                  V P"                  4      ) p\%        WP                  XV P&                  4      #   + '       g   i     L1; i)z°Apply the inverse transform to the whitened data.

Uses the same sample dimension specified by ``dim`` when fitting.

Args:
    x: Whitened data.

Returns:
    Original data.

rM   z;Did not compute inverse ZCA. Please set compute_inv to TrueNz9The transform inverse should be a torch.Tensor. Got None.)r"   rN   r   r   Ú	TypeErrorÚdtyper1   Úfloat16Úbfloat16ÚjitÚis_scriptingr   ÚdeviceÚtyper   r   Úmmr   rO   r   )r$   r?   Úmean_invs   && r   Úinverse_transformÚZCAWhitening.inverse_transformÈ   s  € ð �{�{ˆ{ÜÐuÓvÐvà××ÐÜÐ\Ó]Ð]à×ÑÒ%ÜÐWÓXÐXà�7‰7”u—}‘}¤e§n¡nÐ5Ô5¼e¿i¹i×>TÑ>T×>VÒ>Vä# A§H¡H§M¡M×2Õ2Ø ×,Ñ,×2Ñ2Ó4×7Ñ7¸×8MÑ8M×8SÑ8SÓ8UÓVÐV�÷ 3Ð2ð ×(Ñ(×+Ñ+¨D×,AÑ,AÓBÐBˆHä ×#5Ñ#5°xÀÇÁÓJÐJ÷ 3×2ús   ÃAE!Å!E1	c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )r   Ú_version)r   )r   r   s   "€r   r   r      s   ø‡ ‚ ñ~ Ñò r   )	r   r   r   r   r"   r   r   r   r   )r   ç�íµ ÷Æ°>TTF)F)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ra   r!   r9   rH   rP   r^   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r%   r   s   @@r   r	   r	      sR   ù‡ € ñ;ð| €H÷4õ 4÷, 8ó  8÷Dð ÷@Vò V÷&Kð K÷Y … r   c                óò   € V ^8„  d   QhR\         P                  R\        R\        R\        R\        R\
        \         P                  \         P                  \        \         P                  ,          3,          /# )r   Úinpr   r   r   Úreturn_inverser   ©r1   r2   r   r   r   r   r   )r   s   "r   r   r   ç   se   € ÷ _ñ _Ü	�‰ð_Üð_Ü/3ð_ÜAFð_Ü_cð_ä
Œ5�<‰<œŸ™¤x´·±Õ'=Ð=Õ>ñ_r   c           	     óv  € \        V \        P                  4      '       g   \        R\	        V 4       24      h\        V\
        4      '       g   \        R\	        V4       24      h\        V\        4      '       g   \        R\	        V4       24      h\        V\        4      '       g   \        R\	        V4       24      h\        V\        4      '       g   \        R\	        V4       24      hV P                  4       pV\        V4      8¼  g   V\        V4      ) 8  d/   \        R\        V4      )  R\        V4      ^,
           RV 24      hV^ 8  d   \        V4      V,           pV.p^p\        \        V4      4       F+  pW�8w  g   K  VP                  V4       WuV,          ,          pK-  	  V P                  V4      p	WQ,          p
V'       d   V
^8  d   \        R	V
 R
24      hV
^8  d   \        R4      h\        P                  P!                  4       '       d   \#        W—W#V4      w  r¼pMyV P$                  P                  R8X  d   \#        W—W#V4      w  r¼pMM\        P&                  ! V P$                  P                  RR7      ;_uu_ 4        \#        W—W#V4      w  r¼pRRR4       XXX3#   + '       g   i     L; i)aê  Fit the ZCA whitening matrix and mean vector of a data set.

``T, mean, T_inv = zca_mean(inp, dim)`` returns the ZCA matrix ``T`` with shape ``(D, D)``, the mean vector with
shape ``(1, D)`` and, if ``return_inverse=True``, the inverse matrix ``T_inv`` (else ``None``). ``D`` is the product
of the sizes of all axes except ``dim``, the sample axis. Apply the result with :func:`linear_transform`.

Convention:
    - See :class:`ZCAWhitening` for the covariance and the transform.
    - The fit runs with autocast disabled (not under TorchScript). Float16 and bfloat16 inputs are fitted in float32
      and return float32 tensors, to avoid cancellation when applying a rank-deficient fit.

Args:
    inp: data tensor with shape ``(D_0, ..., D_dim, ..., D_N)``.
    dim: sample axis.
    unbiased: divide the covariance by :math:`N - 1` if ``True``, by :math:`N` otherwise.
    eps: value added to the eigenvalues before the inverse square root.
    return_inverse: also return the inverse transform.

Returns:
    Tuple ``(T, mean, T_inv)``.

Raises:
    ValueError: If the sample dimension has fewer than two entries with ``unbiased=True``, or none with
        ``unbiased=False``.

See Also:
    - :class:`ZCAWhitening`: stores the fit and applies it.
    - :func:`zca_whiten`: fits and whitens in one call.
    - :func:`linear_transform`: applies the result.

Examples:
    >>> x = torch.tensor([[0,1],[1,0],[-1,0],[0,-1]], dtype = torch.float32)
    >>> transform_matrix, mean_vector,_ = zca_mean(x) # Returns transformation matrix and data mean
    >>> x = torch.rand(3,20,2,2)
    >>> transform_matrix, mean_vector, inv_transform = zca_mean(x, dim = 1, return_inverse = True)
    >>> # transform_matrix.size() equals (12,12) and the mean vector.size equal (1,12)

ú&Input type is not a torch.Tensor. Got úeps type is not a float. Gotúunbiased type is not bool. Gotú(Argument 'dim' must be of type int. Got z-Argument return_inverse must be of type bool ú4Dimension out of range (expected to be in range of [Ú,ú], but got z7Unbiased covariance requires at least two samples, got Ú.z/Covariance requires at least one sample, got 0.ÚmetaF)Údevice_typeÚenabledN)Ú
isinstancer1   r2   rT   r[   r   r   r   ÚsizeÚlenÚ
IndexErrorÚrangeÚappendÚpermuteÚ
ValueErrorrX   rY   Ú	_zca_meanrZ   Úautocast)rm   r   r   r   rn   Úinp_sizeÚ	new_orderÚnum_featuresÚiÚinp_permuteÚNrE   rF   rG   s   &&&&&         r   rB   rB   ç   sW  € ôR �cœ5Ÿ<™<×(Ò(ÜÐ@ÄÀcÃÀÐLÓMÐMä�cœ5×!Ò!ÜÐ6´t¸C³y°kÐBÓCÐCä�h¤×%Ò%ÜÐ8¼¸h»Ð8HÐIÓJÐJä�cœ3×ÒÜÐBÄ4ÈÃ9À+ÐNÓOÐOä�n¤d×+Ò+ÜÐGÌÈ^ÓH\ÐG]Ð^Ó_Ð_à�x‰x‹z€Hà
Œc�(‹mÔ˜s¤c¨(£m ^Ô3ÜØBÄCÈÃMÀ>ÐBRÐRSÔTWÐX`ÓTaÐdeÕTeÐSfÐfqÐruÐqvÐwó
ð 	
ð ˆQ„wÜ�(‹m˜cÕ!ˆð  ˜5€IØ€LÜ”3�x“=Ö!ˆØŽ8Ø×Ñ˜QÔØ Q�KÕ'ŠLñ "ð
 —+‘+˜iÓ(€Kà�€A÷ �A˜”EÜÐRÐSTÐRUÐUVÐWÓXÐXØˆ1„uÜÐJÓKÐKä‡y�y×Ñ×Òä" ;¸hÈ^Ó\‰ˆ‘Ø	�‰�‰˜FÔ	"ä" ;¸hÈ^Ó\‰ˆ‘ô �^Š^¨¯
©
¯©À×GÖGÜ& {À(ÐQ_Ó`‰NˆA�U÷ Hð ˆd�Eˆ>Ð÷ H×Gús   Ê
J(Ê(J8	c                óò   € V ^8„  d   QhR\         P                  R\        R\        R\        R\        R\
        \         P                  \         P                  \        \         P                  ,          3,          /# )r   rŠ   rˆ   r   r   rn   r   ro   )r   s   "r   r   r   I  s]   € ÷ "ñ "Ü—‘ð"Ü-0ð"Ü<@ð"ÜGLð"Ü^bð"ä
Œ5�<‰<œŸ™¤x´·±Õ'=Ð=Õ>ñ"r   c                ó^  € V P                   ^ ,          pV P                  \        P                  \        P                  39   pV'       d   V P                  4       p \        P                  ! V ^ RR7      pVP                  ^V34      pV P                  WQ34      V,
          p\        V'       d
   V^,
          MT4      p	V'       d   W‰R,          ,          pVP                  4       P                  V4      p
V'       g	   W©,          p
\        V
4      w  r¼pVP                  R^4      p\        P                  ! WÃ,           4      pVP                  WëP                  4       ,          4      pRpV'       dA   VP                  \        P                  ! WÃ,           4      VP                  4       ,          4      pW÷V3# )zIFit ZCA in the working dtype after validating and moving the sample axis.T)r   Úkeepdimg      à?Néÿÿÿÿ)ÚshaperU   r1   rV   rW   r   rF   ÚreshapeÚtr\   r   ÚrsqrtÚsqrt)rŠ   rˆ   r   r   rn   r‹   Ú
half_inputrF   Úinp_center_flatÚdivisorÚcovÚUÚSÚ_Ú
S_inv_rootrE   rG   s   &&&&&            r   r„   r„   I  s>  € ð 	×Ñ˜!Õ€AØ×"Ñ"¤u§}¡}´e·n±nÐ&EÑE€JßØ!×'Ñ'Ó)ˆäŸš K°QÀÔE€Dà�<‰<˜˜LÐ)Ó*€Dà$/×$7Ñ$7¸Ð8IÓ$JÈTÕ$Q€OäŸX�A˜–E¨1Ó-€Gßà)°S­LÕ8ˆØ
×
Ñ
Ó
×
 Ñ
  Ó
1€CçØ�mˆä˜cÓ"�G€Aˆ!à	�	‰	�"�aÓ€AÜ$Ÿ{š{¨1­7Ó3€JØ—f‘f˜Z¯#©#«%Õ/Ó0€Aà$(€EßØ—‘”u—z’z !¥'Ó*¨Q¯S©S«UÕ2Ó3ˆà�Eˆ>Ðr   c          
      ó|   € V ^8„  d   QhR\         P                  R\        R\        R\        R\         P                  /# )r   rm   r   r   r   r   )r1   r2   r   r   r   )r   s   "r   r   r   n  s:   € ÷ 07ñ 07”E—L‘Lð 07¤sð 07¼$ð 07ÌEð 07Ô]b×]iÑ]iñ 07r   c                ó¶  € \        V \        P                  4      '       g   \        R\	        V 4       24      h\        V\
        4      '       g   \        R\	        V4       24      h\        V\        4      '       g   \        R\	        V4       24      h\        V\        4      '       g   \        R\	        V4       24      h\        WW#R4      w  rEp\        WWQ4      # )a›  Whiten data with a ZCA transform fitted on the same data.

``out = zca_whiten(inp, dim)`` fits ZCA on ``inp`` and returns ``inp`` centered and whitened, with its shape. To
reuse the fit on other data, use :class:`ZCAWhitening`.

Convention:
    - See :class:`ZCAWhitening` for the sample axis and the covariance normalization.

Args:
    inp: data tensor with shape ``(D_0, ..., D_dim, ..., D_N)``.
    dim: sample axis.
    unbiased: divide the covariance by :math:`N - 1` if ``True``, by :math:`N` otherwise.
    eps: value added to the eigenvalues before the inverse square root.

Returns:
    Whitened tensor with the shape of ``inp``.

Raises:
    ValueError: If the sample dimension has fewer than two entries with ``unbiased=True``, or none with
        ``unbiased=False``.

See Also:
    - :class:`ZCAWhitening`: fits once and whitens other data, and inverts the transform.
    - :func:`zca_mean`: returns the transform and mean without applying them.

Examples:
    >>> x = torch.tensor([[0,1],[1,0],[-1,0]], dtype = torch.float32)
    >>> zca_whiten(x).round(decimals=3)
    tensor([[ 0.0000,  1.1550],
            [ 1.0000, -0.5770],
            [-1.0000, -0.5770]])

rq   rr   rs   rt   F)
r|   r1   r2   rT   r[   r   r   r   rB   rO   )rm   r   r   r   Ú	transformrF   r›   s   &&&&   r   Ú
zca_whitenr    n  sº   € ôD �cœ5Ÿ<™<×(Ò(ÜÐ@ÄÀcÃÀÐLÓMÐMä�cœ5×!Ò!ÜÐ6´t¸C³y°kÐBÓCÐCä�h¤×%Ò%ÜÐ8¼¸h»Ð8HÐIÓJÐJä�cœ3×ÒÜÐBÄ4ÈÃ9À+ÐNÓOÐOä! #¨H¸5ÓAÑ€I�Qä˜C¨DÓ6Ð6r   c          
      ó¤   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\         P                  /# )r   rm   r   r   r   r   )r1   r2   r   )r   s   "r   r   r   ¡  sK   € ÷ S.ñ S.Ü	�‰ðS.Ü).¯©ðS.ÜDIÇLÁLðS.ÜWZðS.ä
‡\�\ñS.r   c                óî  € V P                  4       pV\        V4      8¼  g   V\        V4      ) 8  d/   \        R\        V4      )  R\        V4      ^,
           RV 24      hV^ 8  d   \        V4      V,           pV.p^p\        \        V4      4       F+  pWs8w  g   K  VP	                  V4       WdV,          ,          pK-  	  V Uu. uF  p^ NK  	  p	p\        \        V4      4       F  pWyWW,          &   K  	  V P                  V4      p
V
P                  RV34      pV P                  pV\        P                  \        P                  39   dË   VP                  4       VP                  4       ,
          p\        P                  P                  4       '       d!   VP                  VP                  4       4      pMO\        V P                   P"                  4      ;_uu_ 4        VP                  VP                  4       4      pRRR4       XP%                  V4      pMW²,
          pVP                  V4      pVP                  V
P                  4       4      pVP                  V	4      # u upi   + '       g   i     Lp; i)ao  Center data and multiply it by a transform matrix.

``out = linear_transform(inp, transform_matrix, mean_vector, dim)`` flattens all axes of ``inp`` except the sample
axis ``dim`` into one feature vector per sample, computes ``(X - mean_vector) @ transform_matrix`` and restores the
shape of ``inp``.

Convention:
    Half inputs are centered and multiplied in float32 with autocast disabled (outside TorchScript), then rounded to
    the input dtype. Keep the fitted transform and mean in float32 to preserve their accuracy.

Args:
    inp: data tensor with shape ``(D_0, ..., D_dim, ..., D_N)``.
    transform_matrix: matrix with shape ``(D, D)``, ``D`` being the product of the sizes of all axes except ``dim``.
    mean_vector: mean with shape ``(1, D)``.
    dim: sample axis.

Returns:
    Transformed tensor with the shape of ``inp``.

See Also:
    - :func:`zca_mean`: computes the whitening matrix and mean to pass here.
    - :class:`ZCAWhitening`: stores them and applies this transform.

Example:
    >>> # Example where dim = 3
    >>> inp = torch.ones((10,3,4,5))
    >>> transform_mat = torch.ones((10*3*4,10*3*4))
    >>> mean = 2*torch.ones((1,10*3*4))
    >>> out = linear_transform(inp, transform_mat, mean, 3)
    >>> print(out.shape, out.unique())  # a (10,3,4,5) tensor of -120s
    torch.Size([10, 3, 4, 5]) tensor([-120.])

    >>> # Example where dim = 0
    >>> inp = torch.ones((10,2))
    >>> transform_mat = torch.ones((2,2))
    >>> mean = torch.zeros((1,2))
    >>> out = linear_transform(inp, transform_mat, mean)
    >>> print(out.shape, out.unique()) # a (10,2) tensor of 2s
    torch.Size([10, 2]) tensor([2.])

ru   rv   rw   Nr�   )r}   r~   r   r€   r�   r‚   r‘   rU   r1   rV   rW   r   rX   rY   r\   r   rZ   r[   Úto)rm   r   r   r   r†   r‡   rˆ   r‰   r›   Ú	inv_orderrŠ   Úinp_flatÚoutput_dtypeÚ
inp_centerÚinp_transformeds   &&&&           r   rO   rO   ¡  s  € ðX �x‰x‹z€Hà
Œc�(‹mÔ˜s¤c¨(£m ^Ô3ÜØBÄCÈÃMÀ>ÐBRÐRSÔTWÐX`ÓTaÐdeÕTeÐSfÐfqÐruÐqvÐwó
ð 	
ð ˆQ„wÜ�(‹m˜cÕ!ˆð  ˜5€IØ€LÜ”3�x“=Ö!ˆØŽ8Ø×Ñ˜QÔØ Q�KÕ'ŠLñ "ñ (1Ó1¡y !›A¡y€IÐ1Ü”3�y“>Ö"ˆØ"#�)•,Óñ #ð —+‘+˜iÓ(€KØ×"Ñ" B¨Ð#5Ó6€Hà—9‘9€LØœŸ™¤u§~¡~Ð6Ô6Ø—^‘^Ó%¨×(9Ñ(9Ó(;Õ;ˆ
Ü�9‰9×!Ñ!×#Ò#Ø(Ÿm™mÐ,<×,BÑ,BÓ,DÓE‰Oä# C§J¡J§O¡O×4Õ4Ø",§-¡-Ð0@×0FÑ0FÓ0HÓ"I�÷ 5à)×,Ñ,¨\Ó:‰àÕ+ˆ
Ø$Ÿ-™-Ð(8Ó9ˆà%×-Ñ-¨k×.>Ñ.>Ó.@ÓA€Oà×"Ñ" 9Ó-Ð-ùò- 2÷ 5×4ús   ÃIÇ I$É$I4	)r	   rO   rB   r    )r   Trb   F)r   Trb   )r   )Útypingr   r   r   r1   r   Úkornia.core.utilsr   r   Ú__all__ÚModuler	   rB   r„   r    rO   © r   r   Ú<module>r®      sO   ð÷$ )Ñ (ã Ý ç Aâ
H€ôHK�2—9‘9ô HK÷V_õD"÷J07÷fS.ñ S.r   