+
    öäûjæ9  ã                   ó¾   € ^ RI HtHtHtHtHtHt ^ RIt^ RIH	t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHtHt  ! R
 R]4      tR R lt ! R R]4      tR# )é    )ÚAnyÚDictÚListÚOptionalÚTupleÚUnionN)Úrandom_generator)ÚGeometricAugmentationBase2D)ÚResample)Úeye_like)Ú_to_device_nonblocking)Úaffine)Ú_compute_rotation_matrixÚ_compute_tensor_centerc                   ó¶   a a€ ] tR t^t oRt]P                  P                  RRRR3V3R lV 3R llltV3R lR lt	RV3R	 lR
 llt
RV3R lR lltRtVtV ;t# )ÚRandomRotationa  Rotate images by a random angle in degrees, applied per sample with probability ``p`` (default 0.5).

``output = RandomRotation(degrees, ...)(input)`` rotates selected images of shape ``(B, C, H, W)``
about their centers. Use :class:`RandomRotation90` when only quarter turns are wanted.

.. image:: _static/img/RandomRotation.png

.. note::
    Unlike torchvision's ``RandomRotation``, which rotates every image, this class rotates each sample with
    probability ``p``, 0.5 by default; with ``same_on_batch=True`` one draw decides for the whole batch. Pass
    ``p=1.0`` to rotate every sample.

Args:
    degrees: range of degrees to select from. If degrees is a number the
      range of degrees to select from will be (-degrees, +degrees).
    resample: Default: the interpolation mode.
    same_on_batch: apply the same transformation across the batch.
    align_corners: interpolation flag.
    p: probability of applying the transformation to each sample.
    keepdim: whether to keep the output shape the same as input (True) or broadcast it
             to the batch form (False).

Shape:
    - Input: ``(C, H, W)`` or ``(B, C, H, W)``, Optional: ``(B, 3, 3)``
    - Output: ``(B, C, H, W)``

Convention:
    - See :class:`~kornia.augmentation.GeometricAugmentationBase2D` for coordinates, defaults and inverse.
    - a positive sampled angle rotates the displayed image counter-clockwise, as
      :func:`~kornia.geometry.transform.rotate` does and unlike :class:`RandomAffine`
      (:doc:`/get-started/conventions`, `#4408 <https://github.com/kornia/kornia/issues/4408>`_).

.. note::
    This function internally uses :func:`kornia.geometry.transform.affine`.

See Also:
    - :class:`RandomRotation90`: samples only multiples of 90 degrees.
    - :class:`RandomRotation3D`: rotates volumes by a sampled 3D axis-angle vector.

Examples:
    >>> rng = torch.manual_seed(0)
    >>> input = torch.tensor([[1., 0., 0., 2.],
    ...                       [0., 0., 0., 0.],
    ...                       [0., 1., 2., 0.],
    ...                       [0., 0., 1., 2.]])
    >>> aug = RandomRotation(degrees=45.0, p=1.)
    >>> out = aug(input)
    >>> out
    tensor([[[[0.9824, 0.0088, 0.0000, 1.9649],
              [0.0000, 0.0029, 0.0000, 0.0176],
              [0.0029, 1.0000, 1.9883, 0.0000],
              [0.0000, 0.0088, 1.0117, 1.9649]]]])
    >>> aug.transform_matrix
    tensor([[[ 1.0000, -0.0059,  0.0088],
             [ 0.0059,  1.0000, -0.0088],
             [ 0.0000,  0.0000,  1.0000]]])
    >>> inv = aug.inverse(out)

To apply the exact augmenation again, you may take the advantage of the previous parameter state:
    >>> input = torch.randn(1, 3, 32, 32)
    >>> aug = RandomRotation(degrees=45.0, p=1.)
    >>> (aug(input) == aug(input, params=aug._params)).all()
    tensor(True)

FTç      à?c                ó´   <€ V ^8„  d   QhRS[ S[P                  S[S[S[S[3,          S[S[,          3,          RS[ S[S[S[3,          RS[	RS[	RS[RS[	RR/# )	é   ÚdegreesÚresampleÚsame_on_batchÚalign_cornersÚpÚkeepdimÚreturnN)
r   ÚtorchÚTensorÚfloatr   r   ÚstrÚintr   Úbool)ÚformatÚ__classdict__s   "€ÚfC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_2d\geometric\rotation.pyÚ__annotate__ÚRandomRotation.__annotate__d   s…   ø€ ÷ Zñ Zá‘u—|‘|¡U©E±%¹°,Õ,?ÁÁeÅÐLÕMðZñ ™™S¡(Ð*Õ+ðZñ ð	Zñ
 ðZñ ðZñ ðZð 
ñZó    c                ó¦   <€ \         SV `  WSVR 7       \        P                  ! VRRR34      V n        R\
        P                  ! V4      RV/V n        R# )©r   r   r   r   g        r   r   N)g     €vÀg     €v@)ÚsuperÚ__init__ÚrgÚPlainUniformGeneratorÚ_param_generatorr   ÚgetÚflags)Úselfr   r   r   r   r   r   Ú	__class__s   &&&&&&&€r%   r,   ÚRandomRotation.__init__d   sM   ø€ ô 	‰Ñ˜1À7ÐÔKÜ "× 8Ò 8¸'À9ÈcÐSbÐ9cÓ dˆÔà ¤(§,¢,¨xÓ"8¸/È=ÐYˆŽ
r(   c                óš   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[ P                  /# ©r   ÚinputÚparamsr1   r   )r   r   r   r    r   )r#   r$   s   "€r%   r&   r'   r   óN   ø€ ÷ ñ Ù—\‘\ðÙ+/±±U·\±\Ð0AÕ+BðÙKOÑPSÑUXÐPXÍ>ðá	�‰ñr(   c                ó  € \        VR ,          VP                  VP                  4      p\        V4      p\	        WEP                  VP                  ^ ,          R4      4      p\        ^VRR7      pVR,          VR&   VR,          VR&   V# )r   F©Úshared_memoryéÿÿÿÿ©ºNNNr   ©r?   é   )r   ÚdeviceÚdtyper   r   ÚexpandÚshaper   ©r2   r7   r8   r1   ÚanglesÚcenterÚrotation_matÚ	trans_mats   &&&&    r%   Úcompute_transformationÚ%RandomRotation.compute_transformationr   s�   € ô  6°f¸YÕ6GÈÏÉÐW\×WbÑWbÓcˆä5°eÓ<ˆÜ%=¸fÇmÁmÐTZ×T`ÑT`ÐabÕTcÐegÓFhÓ%iˆô #+¨1¨eÀ5Ô"Iˆ	Ø& tÕ,ˆ	�$‰Ø& tÕ,ˆ	�$‰àÐr(   c          
      óÄ   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[S[ P                  ,          RS[ P                  /# ©r   r7   r8   r1   Ú	transformr   )r   r   r   r    r   r   )r#   r$   s   "€r%   r&   r'   ‚   ók   ø€ ÷ 
vñ 
vá�|‰|ð
vñ ‘S™%Ÿ,™,Ð&Õ'ð
vñ ‘C™�H�~ð	
vñ
 ™EŸL™LÕ)ð
vñ 
�‰ñ
vr(   c                óè   € \        V\        P                  4      '       g   \        R \	        V4       R24      h\        WR,          VR,          P                  P                  4       RVR,          4      # ©ú0Expected the `transform` be a torch.Tensor. Got Ú.r   Úzerosr   ).:Nr   N:Né   N©Ú
isinstancer   r   Ú	TypeErrorÚtyper   ÚnameÚlower©r2   r7   r8   r1   rO   s   &&&&&r%   Úapply_transformÚRandomRotation.apply_transform‚   óc   € ô ˜)¤U§\¡\×2Ò2ÜÐNÌtÐT]ËÐN_Ð_`ÐaÓbÐbä�e {Õ3°U¸:Õ5F×5KÑ5K×5QÑ5QÓ5SÐU\Ð^cÐdsÕ^tÓuÐur(   c                óÀ   <€ V ^8„  d   QhRS[ P                  RS[S[S[3,          RS[S[ P                  ,          RS[S[S[S[3,          ,          RS[ P                  /# ©r   r7   r1   rO   Úsizer   )r   r   r   r    r   r   r   r!   )r#   r$   s   "€r%   r&   r'   Ž   óc   ø€ ÷ 
ñ 
á�|‰|ð
ñ ‘C™�H�~ð
ñ ™EŸL™LÕ)ð	
ñ
 ‘u™S¡#˜X•Õ'ð
ñ 
�‰ñ
r(   c           
     ó  € \        V\        P                  4      '       g   \        R \	        V4       R24      hV P                  VV P                  \        P                  ! W1P                  VP                  R7      VR7      # ©rS   rT   )rB   rC   )r8   rO   r1   ©
rX   r   r   rY   rZ   r^   Ú_paramsÚ	as_tensorrB   rC   ©r2   r7   r1   rO   rc   s   &&&&&r%   Úinverse_transformÚ RandomRotation.inverse_transformŽ   ól   € ô ˜)¤U§\¡\×2Ò2ÜÐNÌtÐT]ËÐN_Ð_`ÐaÓbÐbØ×#Ñ#ØØ—<‘<Ü—o’o i¿¹ÈEÏKÉKÔXØð	 $ó 
ð 	
r(   )r/   r1   ©N©NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚBILINEARr[   r,   rK   r^   rk   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©r3   r$   s   @@r%   r   r      sZ   ù‡ € ñ@ðN /7×.?Ñ.?×.DÑ.DØ#Ø"ØØ÷Zõ Z÷ð ÷ 
vò 
v÷
÷ 
ò 
r(   r   c                ó<   € V ^8„  d   QhR\         R\         R\        /# )r   ÚlowÚhighr   )r   r"   )r#   s   "r%   r&   r&   Ÿ   s!   € ÷ &ñ &¤ð &¬eð &¼ñ &r(   c                ó\   € \        V 4      \        V4      rW8„  ;'       g    V ^,          ^ 8g  # )a  Whether a ``times`` draw from ``[low, high]`` can round to an odd number of quarter turns.

The bounds are rounded the way ``compute_transformation`` rounds a draw. Two different whole numbers always include
an odd one, and a single whole number is either odd or even.
)Úround)r{   r|   s   &&r%   Ú_range_allows_odd_turnsr   Ÿ   s+   € ô �c“
œE $›KˆØ‰:×%Ð%˜˜q� A™Ð%r(   c                   óþ   a a€ ] tR t^©t oRt]P                  P                  RRRR3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V 3R
 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RV3R lR lltRtVtV ;t# )ÚRandomRotation90aâ  Rotate images by a random multiple of 90 degrees, applied per sample with probability ``p`` (default 0.5).

``output = RandomRotation90(times, ...)(input)`` rotates selected images of shape ``(B, C, H, W)``
by quarter turns. Use :class:`RandomRotation` to sample arbitrary angles.

Args:
    times: the range of n times 90 degree rotation needs to be applied. A range of whole numbers is closed:
      every whole number from the lower to the upper bound is drawn with the same probability.
    resample: Default: the interpolation mode.
    same_on_batch: apply the same transformation across the batch.
    align_corners: interpolation flag.
    p: probability of applying the transformation to each sample.
    keepdim: whether to keep the output shape the same as input (True) or broadcast it
             to the batch form (False).

Shape:
    - Input: ``(C, H, W)`` or ``(B, C, H, W)``, Optional: ``(B, 3, 3)``
    - Output: ``(B, C, H, W)``

Convention:
    - See :class:`~kornia.augmentation.GeometricAugmentationBase2D` for coordinates, defaults and inverse.
    - a positive rounded ``times`` rotates the displayed image counter-clockwise by ``times * 90`` degrees.
    - a range of whole numbers for ``times`` is closed and uniform: ``times=(-1, 1)`` gives a clockwise quarter
      turn, no turn and a counter-clockwise quarter turn with the same probability. A range with a fractional
      bound is still drawn continuously and rounded.
    - an odd number of quarter turns swaps the height and the width, but the output keeps the ``(H, W)`` of the
      input, so part of a non-square image would be cut off. A non-square input therefore raises ``ValueError``
      when the ``times`` range allows an odd number of quarter turns, even if a given call would draw an even one.
      Square images, and ranges of even numbers only such as ``times=(2, 2)``, are unaffected. Use
      :class:`~kornia.augmentation.RandomRotation` with a fixed angle of 90 degrees to rotate and crop, or
      :func:`torch.rot90` to turn a whole batch exactly.

.. note::
    This function internally uses :func:`kornia.geometry.transform.affine`. This version is relatively
    slow as it operates based on affine transformations.

See Also:
    - :class:`RandomRotation`: samples an arbitrary angle in degrees.

Examples:
    >>> rng = torch.manual_seed(1)
    >>> input = torch.tensor([[1., 0., 0., 2.],
    ...                       [0., 0., 0., 0.],
    ...                       [0., 1., 2., 0.],
    ...                       [0., 0., 1., 2.]])
    >>> aug = RandomRotation90(times=(1, 1), p=1.)
    >>> out = aug(input)
    >>> out.round()  # rounded: the warp leaves float32 noise around 1e-7
    tensor([[[[2., 0., 0., 2.],
              [0., 0., 2., 1.],
              [0., 0., 1., 0.],
              [1., 0., 0., 0.]]]])
    >>> aug.transform_matrix.round(decimals=4) + 0.  # + 0. turns -0. into 0.
    tensor([[[ 0.,  1.,  0.],
             [-1.,  0.,  3.],
             [ 0.,  0.,  1.]]])
    >>> inv = aug.inverse(out)

To apply the exact augmenation again, you may take the advantage of the previous parameter state:
    >>> input = torch.randn(1, 3, 32, 32)
    >>> aug = RandomRotation90(times=(-1, 1), p=1.)
    >>> (aug(input) == aug(input, params=aug._params)).all()
    tensor(True)

FTr   c                ór   <€ V ^8„  d   QhRS[ S[S[3,          RS[S[S[S[3,          RS[RS[RS[RS[RR/# )	r   Útimesr   r   r   r   r   r   N)Útupler!   r   r    r   r"   r   )r#   r$   s   "€r%   r&   ÚRandomRotation90.__annotate__ì   sn   ø€ ÷ Zñ Zá‘S™#�X�ðZñ ™™S¡(Ð*Õ+ðZñ ð	Zñ
 ðZñ ðZñ ðZð 
ñZr(   c                ó
  <€ \         S	V `  WSVR 7       \        P                  ! V4      V n        V P                  P
                  P                  4       w  rx\        Wx4      V n        R\        P                  ! V4      RV/V n        R# )r*   r   r   N)r+   r,   r-   ÚRotation90Generatorr/   rƒ   Útolistr   Ú_allows_odd_turnsr   r0   r1   )
r2   rƒ   r   r   r   r   r   r{   r|   r3   s
   &&&&&&&  €r%   r,   ÚRandomRotation90.__init__ì   sl   ø€ ô 	‰Ñ˜1À7ÐÔKÜ "× 6Ò 6°uÓ =ˆÔØ×)Ñ)×/Ñ/×6Ñ6Ó8‰	ˆÜ!8¸Ó!CˆÔà ¤(§,¢,¨xÓ"8¸/È=ÐYˆŽ
r(   c                ó:   <€ V ^8„  d   QhRS[ S[S[3,          RR/# )r   Ústater   N©r   r    r   )r#   r$   s   "€r%   r&   r…   ü   s'   ø€ ÷ Hñ H¡$¡s©C x¥.ð H°Tñ Hr(   c                ó  <€ \         SV `  V4       R V P                  9  g'   V P                  P                  P
                  '       d9   V P                  P                  P                  4       w  r#\        W#4      V n        R# R# )r‰   N)	r+   Ú__setstate__Ú__dict__r/   rƒ   Úrequires_gradrˆ   r   r‰   )r2   rŒ   r{   r|   r3   s   &&  €r%   r�   ÚRandomRotation90.__setstate__ü   sd   ø€ Ü‰Ñ˜UÔ#Ø d§m¡mÔ3°t×7LÑ7L×7RÑ7R×7`×7`Ð7`ð ×-Ñ-×3Ñ3×:Ñ:Ó<‰IˆCÜ%<¸SÓ%GˆDÖ"ñ 8ar(   c          
      óL   <€ V ^8„  d   QhRS[ S[S[3,          RS[RS[RS[RR/# )r   Ú
state_dictÚprefixÚargsÚkwargsr   Nr�   )r#   r$   s   "€r%   r&   r…     sB   ø€ ÷ Hñ H±±S¹#°Xµð HÉð HÑTWð HÑcfð HÐkoñ Hr(   c                ó  <€ \         SV `  ! W.VO5/ VB  VP                  V R 24      p\        V\        P
                  4      '       d8   VP                  R8X  d%   VP                  4       w  rg\        Wg4      V n	        R# R# R# )z_param_generator.timesN)r   )
r+   Ú_load_from_state_dictr0   rX   r   r   rE   rˆ   r   r‰   )	r2   r”   r•   r–   r—   rƒ   r{   r|   r3   s	   &&&*,   €r%   r™   Ú&RandomRotation90._load_from_state_dict  so   ø€ Ü‰Ò% jÐJ¸4ÒJÀ6ÒJØ—‘ & Ð)?Ð@ÓAˆÜ�eœUŸ\™\×*Ò*¨u¯{©{¸dÔ/BØŸ™›‰IˆCÜ%<¸SÓ%GˆDÖ"ñ 0CÑ*r(   c                ó8   <€ V ^8„  d   QhRS[ P                  RR/# )r   r7   r   N)r   r   )r#   r$   s   "€r%   r&   r…     s   ø€ ÷ 	ñ 	¡U§\¡\ð 	°dñ 	r(   c                ó    <€ \         SV `  V4       VP                  RR w  r#V P                  '       d   W#8w  d   \	        RV RV R24      hR# R# )r   Nz]`RandomRotation90` keeps the (H, W) shape, so an odd number of quarter turns of a non-square ÚxzÄ image would cut off part of it, and `times` allows one. Use a square image, `RandomRotation` with a fixed angle of 90 degrees to rotate and crop, or `torch.rot90` to turn the whole batch exactly.éþÿÿÿ)r+   Úvalidate_tensorrE   r‰   Ú
ValueError)r2   r7   ÚheightÚwidthr3   s   &&  €r%   rŸ   Ú RandomRotation90.validate_tensor  s_   ø€ Ü‰Ñ Ô&ØŸ™ B CÐ(‰ˆØ×!×!Ð! f¤oÜØoØ�(˜!˜E˜7ð #+ð+óð ñ '6Ñ!r(   c                óš   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[ P                  /# r6   )r   r   Údictr    r   )r#   r$   s   "€r%   r&   r…     r9   r(   c                ó:  € R \        VR,          P                  4       VP                  VP                  4      ,          p\	        V4      p\        WEP                  VP                  ^ ,          R4      4      p\        ^VRR7      pVR,          VR&   VR,          VR&   V# )g     €V@rƒ   Fr;   r=   r>   r@   )	r   r~   rB   rC   r   r   rD   rE   r   rF   s   &&&&    r%   rK   Ú'RandomRotation90.compute_transformation  s’   € ð  $Ô&<¸VÀG½_×=RÑ=RÓ=TÐV[×VbÑVbÐdi×doÑdoÓ&pÕpˆä5°eÓ<ˆÜ%=¸fÇmÁmÐTZ×T`ÑT`ÐabÕTcÐegÓFhÓ%iˆô #+¨1¨eÀ5Ô"Iˆ	Ø& tÕ,ˆ	�$‰Ø& tÕ,ˆ	�$‰àÐr(   c          
      óÄ   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[S[ P                  ,          RS[ P                  /# rN   )r   r   r¥   r    r   r   )r#   r$   s   "€r%   r&   r…   '  rP   r(   c                óè   € \        V\        P                  4      '       g   \        R \	        V4       R24      h\        WR,          VR,          P                  P                  4       RVR,          4      # rR   rW   r]   s   &&&&&r%   r^   Ú RandomRotation90.apply_transform'  r`   r(   c                óÀ   <€ V ^8„  d   QhRS[ P                  RS[S[S[3,          RS[S[ P                  ,          RS[S[S[S[3,          ,          RS[ P                  /# rb   )r   r   r¥   r    r   r   r„   r!   )r#   r$   s   "€r%   r&   r…   3  rd   r(   c           
     ó  € \        V\        P                  4      '       g   \        R \	        V4       R24      hV P                  VV P                  \        P                  ! W1P                  VP                  R7      VR7      # rf   rg   rj   s   &&&&&r%   rk   Ú"RandomRotation90.inverse_transform3  rm   r(   )r‰   r/   r1   rn   ro   )rp   rq   rr   rs   rt   r   ru   r[   r,   r�   r™   rŸ   rK   r^   rk   rv   rw   rx   ry   s   @@r%   r�   r�   ©   s|   ù‡ € ñ@ðJ /7×.?Ñ.?×.DÑ.DØ#Ø"ØØ÷Zõ Z÷ Hó H÷Hó H÷	ó 	÷ð ÷ 
vò 
v÷
÷ 
ò 
r(   r�   )Útypingr   r   r   r   r   r   r   Úkornia.augmentationr	   r-   Ú&kornia.augmentation._2d.geometric.baser
   Úkornia.constantsr   Úkornia.core.opsr   Úkornia.core.utilsr   Úkornia.geometry.transformr   Ú!kornia.geometry.transform.affwarpr   r   r   r   r�   © r(   r%   Ú<module>r·      sI   ð÷$ ;× :ã å 6Ý NÝ %Ý $Ý 4Ý ,ß ^ô}
Ð0ô }
õ@&ôX
Ð2ö X
r(   