
    3jG                        S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
r
S SKJrJr  S SKJr  S SKJr  S SKJr  S\S	\4   S
\S	\4   4S jrS\S	\4   S
\S	\4   4S jrS\	\
R,                  \\
R,                  \
R,                  4   4   S
\
R.                  4S jrS\	\
R,                  \\
R,                  \
R,                  4   4   S
\
R.                  4S jr S:S\
R,                  S\
R,                  S\S
\
R,                  4S jjr S:S\
R,                  S\
R,                  S\S
\
R,                  4S jjrS\
R,                  S
\
R,                  4S jrS\
R,                  S
\
R,                  4S jrS\
R,                  S\\
R>                     S
S4S jr SS.S\
R,                  S\\!S	4   S\\
R,                     S
\
R,                  4S jjr"S;S\	\\!S	4   \
R.                  4   S\\#S	4   S
S4S jjr$S\
R,                  S\!S\!S
\4S  jr% S<S\	\\!S	4   \
R.                  4   S!\
RL                  RN                  S"\\   S
\
R,                  4S# jjr( S<S\	\\!S	4   \
R.                  4   S!\
RL                  RN                  S"\\   S
\
R,                  4S$ jjr) S<S\	\\!S	4   \
R.                  4   S%\	\*\
R,                  4   S&\	\*\
R,                  4   S"\S
\
R,                  4
S' jjr+ S<S\	\\!S	4   \
R.                  4   S(\	\*\
R,                  4   S)\	\*\
R,                  4   S"\S
\
R,                  4
S* jjr,S+\
R,                  S\	\\!S	4   \\!   4   S,\#S
S4S- jr-S.\\#\4   S
\\#\4   4S/ jr.   S=S.\\#\4   S0\\\#\4      S1\#S2\S
\\#\4   4
S3 jjr/S>S\	\
R,                  \4   S4\#S
\4S5 jjr0S\	\
R,                  \4   S
\4S6 jr1S\
R,                  S
\
R,                  4S7 jr2 " S8 S95      r3g)?    )wraps)AnyCallableDictListOptionalTupleUnionN)BetaUniform)_extract_device_dtype)Boxes)	Keypointsf.returnc           	      x   ^  [        T 5      S[        R                  S[        S[        S[        4U 4S jj5       nU$ )zValidate the 2D input of the wrapped function.

Args:
    f: a function that takes the first argument as torch.Tensor.

Returns:
    the wrapped function after input is validated.

inputargskwargsr   c                 4  > [         R                  " U 5      (       d  [        S[        U 5       35      e[	        U R
                  SS9  [        U [         R                  [         R                  [         R                  [         R                  /S9  T" U /UQ70 UD6$ )N&Input type is not a torch.Tensor. Got BCHW)required_shapesaccepted_dtypes)torch	is_tensor	TypeErrortype_validate_shapeshape_validate_input_dtypebfloat16float16float32float64)r   r   r   r   s      [/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/augmentation/utils/helpers.pywrapper _validate_input.<locals>.wrapper(   su    u%%DT%[MRSSY?eennemmUZUbUbdidqdq5rs((((    r   r   Tensorr   r   r)   s   ` r(   _validate_inputr/      sB     1X)u|| )C )3 )3 ) ) Nr+   c           	      x   ^  [        T 5      S[        R                  S[        S[        S[        4U 4S jj5       nU$ )zValidate the 3D input of the wrapped function.

Args:
    f: a function that takes the first argument as torch.Tensor.

Returns:
    the wrapped function after input is validated.

r   r   r   r   c                 `  > [         R                  " U 5      (       d  [        S[        U 5       35      e[	        U R
                  5      nUS:w  a  [        SU S35      e[        U [         R                  [         R                  [         R                  [         R                  /S9  T" U /UQ70 UD6$ )Nr      z"Expect input of 5 dimensions, got z insteadr   )r   r   r   r    lenr"   AssertionErrorr#   r$   r%   r&   r'   )r   r   r   input_shaper   s       r(   r)   "_validate_input3d.<locals>.wrapper@   s    u%%DT%[MRSS%++&! #Ek]RZ![\\eennemmUZUbUbdidqdq5rs((((r+   r,   r.   s   ` r(   _validate_input3dr7   5   sB     1X	)u|| 	)C 	)3 	)3 	) 	) Nr+   r   c                     [        U [        5      (       a  [        U S   5      nUR                  $ [        U 5      nUR                  $ z\Infer input shape.

Input may be either (torch.Tensor,) or (torch.Tensor, transform_matrix)
r   )
isinstancetuple_transform_inputr"   r   
tensor_vars     r(   _infer_batch_shaper?   O   sE    
 %%eAh/
  &e,
r+   c                     [        U [        5      (       a  [        U S   5      nUR                  $ [        U 5      nUR                  $ r9   )r:   r;   _transform_input3dr"   r=   s     r(   _infer_batch_shape3drB   [   sE    
 %'a1
  (.
r+   reference_shapematch_channelc                    [        U5      S:  a  US   OSn[        U5      S:  a  US   OSn[        U R                  5      S:X  a  U R                  S5      n [        U R                  5      S:X  a4  X0R                  S   :X  a  U R                  S5      OU R                  S5      n U(       a(  U(       a!  U R                  S   U:X  d  [        S	5      e U $ U(       a  Uc  [        S
5      eU $ )  Reshape an input torch.Tensor to have the same dimensions as the reference_shape.

Arguments:
    input: torch.Tensor to be transformed
    reference_shape: shape used as reference
    match_channel: if True, C_{src} == C_{ref}. otherwise, no constrain. C =1 by default

   N      r      NThe C dimension of torch.Tensor did not match with the reference torch.Tensor.5The reference torch.Tensor do not have a C dimension!r3   r"   	unsqueeze
ValueErrorr   rC   rD   BCs        r(   _transform_input_by_shaperU   g   s      #?3q8dA"?3q8dA
5;;1"
5;;1 '(;;r?&:"PQ@R{{2!#mnn $
 L 
19PQQLr+   c                    [        U5      S:  a  US   OSn[        U5      S:  a  US   OSn[        U R                  5      S:X  a  U R                  S5      n [        U R                  5      S:X  a#  X0R                  S   :X  a  U R                  S5      n U(       a(  U(       a!  U R                  S   U:X  d  [        S	5      e U $ U(       a  Uc  [        S
5      eU $ )rF   r2   NrG   rH   rI   r   rK   rM   rN   rO   rR   s        r(   _transform_input3d_by_shaperX      s      #?3q8dA"?3q8dA
5;;1"
5;;1kk"o!5 "{{2!#mnn $
 L 
19PQQLr+   c                 t   [         R                  " U 5      (       d  [        S[        U 5       35      e[	        U R
                  5      S;  a  [        SU R
                   35      e[	        U R
                  5      S:X  a  U R                  S5      n [	        U R
                  5      S:X  a  U R                  S5      n U $ )zReshape an input torch.Tensor to be (*, C, H, W). Accept either (H, W), (C, H, W) or (*, C, H, W).

Args:
    input: torch.Tensor

Returns:
    torch.Tensor

r   )rK   rI   rG   zNInput size must have a shape of either (H, W), (C, H, W) or (*, C, H, W). Got rK   r   rI   r   r   r   r    r3   r"   rQ   rP   r   s    r(   r<   r<      s     ??5!!@eNOO
5;;y(ijojujuivwxx
5;;1"
5;;1"Lr+   c                 t   [         R                  " U 5      (       d  [        S[        U 5       35      e[	        U R
                  5      S;  a  [        SU R
                   35      e[	        U R
                  5      S:X  a  U R                  S5      n [	        U R
                  5      S:X  a  U R                  S5      n U $ )zReshape an input torch.Tensor to be (*, C, D, H, W). Accept either (D, H, W), (C, D, H, W) or (*, C, D, H, W).

Args:
    input: torch.Tensor

Returns:
    torch.Tensor

r   )rI   rG   r2   zWInput size must have a shape of either (D, H, W), (C, D, H, W) or (*, C, D, H, W). Got rI   r   rG   rZ   r[   s    r(   rA   rA      s     ??5!!@eNOO
5;;y(efkfqfqers
 	
 5;;1"
5;;1"Lr+   r   c                 Z    U R                   U;  a  [        SU SU R                    35      eg)zCheck if the dtype of the input torch.Tensor is in the range of accepted_dtypes.

Args:
    input: torch.Tensor
    accepted_dtypes: List. e.g. [torch.float32, torch.float64]
zExpected input of . Got N)dtyper   )r   r   s     r(   r#   r#      s3     {{/),_,=VEKK=QRR *r+   )rC   outputr"   c                \   U n[        [        UR                  5      [        U5      -
  5       H{  nSnUb1  UR                  S   US   s=:X  a  S:w  a  O  O[        U5      S:  a  SnUR                  U   S:w  a  [        SU SUR                  U    35      eUR	                  U5      nM}     U$ )a  Collapse the broadcasted batch dimensions an input torch.Tensor to be the specified shape.

Args:
    output: torch.Tensor
    shape: List/tuple of int
    reference_shape: torch.Tensor representation of shape to control which dimensions are collapsed.

Returns:
    torch.Tensor

r   rL   rK   z
Dimension z# of input is expected to be 1, got )ranger3   r"   r4   squeeze)r`   r"   rC   
out_tensordimidxs         r(   _transform_output_shaperg      s     JS))*SZ78&:+;+;A+>/RSBT+YXY+Y^abg^hkl^lCC A% :cU2UV`VfVfgjVkUl!mnn'',
 9 r+   r   c                     SnU H  n[        U 5      [        U5      :X  d  M  Sn  O   U(       d  [        SW SU  S35      eg)zCheck if the dtype of the input torch.Tensor is in the range of accepted_dtypes.

Args:
    shape: torch.Tensor shape
    required_shapes: List. e.g. ["BCHW", "BCDHW"]
FTzExpected input shape in r^   .N)r3   r   )r"   r   passedrequired_shapes       r(   r!   r!      sR     F)u:^,,F * 2>2B&qQRR r+   channel_indexnumberc                 &    U R                   U   U:H  $ )a2  Validate if an input has the right shape.

e.g. to check if an input is channel first.
If channel first, the second channel of an RGB input shall be fixed to 3. To verify using:
    _validate_input_shape(input, 1, 3)

Args:
    input: torch.Tensor
    channel_index: int
    number: int
Returns:
    bool

)r"   )r   rl   rm   s      r(   _validate_input_shapero     s     ;;}%//r+   distsame_on_batchc                 D   [        U [        5      (       a  [        R                  " U 5      n U(       a^  [        R                  " S/U SS Q75      nUR	                  U5      nUR
                  " U S   /S/[        UR                  5      S-
  -  Q76 $ UR	                  U 5      $ )zSample from a uniform reparameterized sampling function that accepts 'same_on_batch'.

If same_on_batch is True, all values generated will be exactly same given a batch_size (shape[0]). By default,
same_on_batch is set to False.
rL   Nr   )r:   r;   r   Sizersamplerepeatr3   r"   )r"   rp   rq   rsample_sizert   s        r(   _adapted_rsamplingrw   !  s     %

5!zz1/uQRy/2,,|,~~eAhH!GMM0BQ0F)GHH<<r+   c                 (   [        U [        5      (       a  [        R                  " U 5      n U(       aP  UR	                  [        R                  " S/U SS Q75      5      R
                  " U S   /S/[        U 5      S-
  -  Q76 $ UR	                  U 5      $ )zSample from a uniform sampling function that accepts 'same_on_batch'.

If same_on_batch is True, all values generated will be exactly same given a batch_size (shape[0]). By default,
same_on_batch is set to False.
rL   Nr   )r:   r;   r   rs   sampleru   r3   )r"   rp   rq   s      r(   _adapted_samplingrz   5  s}     %

5!{{5::qo59o67>>uQxa1#QTUZQ[^_Q_J`aa;;ur+   lowhighc                 $   [        [        U[        R                  5      (       a  UOS[        U[        R                  5      (       a  UOS/5      u  pE[        R                  " XUS9n[        R                  " X$US9n[        XSS9n[        XU5      $ )a{  Sample from a uniform sampling function that accepts 'same_on_batch'.

If same_on_batch is True, all values generated will be exactly same given a batch_size (shape[0]). By default,
same_on_batch is set to False.

By default, sampling happens on the default device and dtype. If low/high is a torch.Tensor,
sampling will happen in the same device/dtype as low/high torch.Tensor.
Ndevicer_   Fvalidate_args)r   r:   r   r-   	as_tensorr   rw   )r"   r{   r|   rq   r   r_   rp   s          r(   _adapted_uniformr   G  s}     *3--4DRWR^R^A_A_eijMF //#E
:C??4e<D 3E2De=99r+   abc                 $   [        [        U[        R                  5      (       a  UOS[        U[        R                  5      (       a  UOS/5      u  pE[        R                  " XUS9n[        R                  " X$US9n[        XSS9n[        XU5      $ )an  Sample from a beta sampling function that accepts 'same_on_batch'.

If same_on_batch is True, all values generated will be exactly same given a batch_size (shape[0]). By default,
same_on_batch is set to False.

By default, sampling happens on the default device and dtype. If a/b is a torch.Tensor,
sampling will happen in the same device/dtype as a/b torch.Tensor.
Nr~   Fr   )r   r:   r   r-   r   r   rw   )r"   r   r   rq   r   r_   rp   s          r(   _adapted_betar   `  sx     *ELL))t*Q:U:UQ[_`MF 	6A6AE*De=99r+   paramnamec                     U R                   [        R                  " U5      :w  a  [        SU SU SU R                    35      eg )NzInvalid shape for z. Expected r^   )r"   r   rs   r4   )r   r"   r   s      r(   _shape_validationr   w  sB    {{ejj''1${5'PUP[P[}]^^ (r+   paramsc                     0 nU R                  5        HX  u  p#[        U[        R                  5      (       a"  UR	                  X#R                  5       05        MF  UR	                  X#05        MZ     U$ )zCPerform deep copy on any dict.

Support torch.Tensor copying here.
)itemsr:   r   r-   updateclone)r   outkvs       r(   deepcopy_dictr   |  sU    
 Ca&&JJ779~&JJv  Jr+   params_overrideif_none_existin_placec                     Uc  U $ U(       a  U O
[        U 5      nUR                  5        H=  u  pVXQ;   a  XdU'   M  US:X  a  M  US:X  a  [        SU SU S35      e[        SU S35      e   U$ )a9  Override params dict w.r.t params_override.

Args:
    params: source parameters.
    params_override: key-values to override the source parameters.
    if_none_exist: behaviour if the key in `params_override` does not exist in `params`.
        'raise' | 'ignore'.
    in_place: if to override in-place or not.

ignoreraisezParam `z` not existed in `z`.`z` is not a valid option.)r   r   RuntimeErrorrQ   )r   r   r   r   r   r   r   s          r(   override_parametersr     s      &-"7C%%'Fh&g%+=o=NbQRRq/GHII ( Jr+   modec                 |   [        U [        R                  5      (       ao  [        U R                  5      S:X  a)  U R                  SS [        R
                  " SS/5      :X  d  [        SU R                   S35      e[        R                  " XS9n [        U [        5      (       d  [        S[        U 5       S35      eU $ )a  Preprocess input boxes.

Args:
    input: 2D boxes, shape of :math:`(N, 4, 2)`, :math:`(B, N, 4, 2)` or a list of :math:`(N, 4, 2)`.
        See below for more details.
    mode: The format in which the boxes are provided.

        * 'xyxy': boxes are assumed to be in the format ``xmin, ymin, xmax, ymax`` where
          ``width = xmax - xmin``
            and ``height = ymax - ymin``. With shape :math:`(N, 4)`, :math:`(B, N, 4)`.
        * 'xyxy_plus': similar to 'xyxy' mode but where box width and length are defined as
            ``width = xmax - xmin + 1`` and ``height = ymax - ymin + 1``.
            With shape :math:`(N, 4)`, :math:`(B, N, 4)`.
        * 'xywh': boxes are assumed to be in the format ``xmin, ymin, width, height`` where
            ``width = xmax - xmin`` and ``height = ymax - ymin``. With shape :math:`(N, 4)`, :math:`(B, N, 4)`.
        * 'vertices': boxes are defined by their vertices points in the following ``clockwise`` order:
            *top-left, top-right, bottom-right, bottom-left*. Vertices coordinates are in (x,y) order. Finally,
            box width and height are defined as ``width = xmax - xmin`` and ``height = ymax - ymin``.
            With shape :math:`(N, 4, 2)` or :math:`(B, N, 4, 2)`.
        * 'vertices_plus': similar to 'vertices' mode but where box width and length are defined as
            ``width = xmax - xmin + 1`` and ``height = ymax - ymin + 1``. ymin + 1``.
            With shape :math:`(N, 4, 2)` or :math:`(B, N, 4, 2)`.

Note:
    **2D boxes format** is defined as a floating data type torch.Tensor of shape ``Nx4x2`` or ``BxNx4x2``
    where each box is a `quadrilateral <https://en.wikipedia.org/wiki/Quadrilateral>`_ defined by
    it's 4 vertices
    coordinates (A, B, C, D). Coordinates must be in ``x, y`` order. The height and width of a box is defined as
    ``width = xmax - xmin + 1`` and ``height = ymax - ymin + 1``. Examples of
    `quadrilaterals <https://en.wikipedia.org/wiki/Quadrilateral>`_ are rectangles, rhombus and trapezoids.

rG   rK   Nz,Only BxNx4x2 torch.Tensor is supported. Got ri   )r   zExpect `Boxes` type. Got )
r:   r   r-   r3   r"   rs   r   r   from_tensorr    )r   r   s     r(   preprocess_boxesr     s    F %&&EKK A%%++ab/UZZA=O*O!Mekk]Z[\]]!!%3eU##6tE{m1EFFLr+   c                 j   [        U [        R                  5      (       af  [        U R                  5      S:X  a(  U R                  SS [        R
                  " S/5      :X  d  [        SU R                   S35      e[        U S5      n [        U [        5      (       a  [        S[        U 5       S35      eU $ )	zPreprocess input keypoints.rI   rL   NrK   z*Only BxNx2 torch.Tensor is supported. Got ri   FzExpect `Keypoints` type. Got )	r:   r   r-   r3   r"   rs   r   r   r    r[   s    r(   preprocess_keypointsr     s     %&&EKK A%%++ab/UZZ_*L!KEKK=XYZ[[%'%##:4;-qIJJLr+   c                     U $ )zPreprocess input class tags. r[   s    r(   preprocess_classesr     s	     Lr+   c                   <   ^  \ rS rSrSrS\S\SS4U 4S jjrSrU =r$ )	MultiprocessWrapperi  zYWhen used as a base class, makes the class work with the 'spawn' multiprocessing context.r   r   r   Nc           	         > [        S U 5       5      nUR                  5        VVs0 s H7  u  p4U[        U[        R                  5      (       a  UR                  5       OU_M9     nnn[        TU ]  " U0 UD6  g s  snnf )Nc              3      #    U  H6  n[        U[        R                  5      (       a  UR                  5       OUv   M8     g 7f)N)r:   r   r-   r   ).0args     r(   	<genexpr>/MultiprocessWrapper.__init__.<locals>.<genexpr>  s-     [VZsJsELL$A$ASYY[sJVZs   >A )r;   r   r:   r   r-   r   super__init__)selfr   r   keyval	__class__s        r(   r   MultiprocessWrapper.__init__  sl    [VZ[[]c]i]i]kl]kQYQT#jell&C&Csyy{L]kl$)&) ms   >A9r   )	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classcell__)r   s   @r(   r   r     s%    c*c *S *T * *r+   r   )T)r   )F)Nr   F)vertices_plus)4	functoolsr   typingr   r   r   r   r   r	   r
   r   torch.distributionsr   r   kornia.core.utilsr   kornia.geometry.boxesr   kornia.geometry.keypointsr   r/   r7   r-   rs   r?   rB   boolrU   rX   r<   rA   r_   r#   intrg   strr!   ro   distributionsDistributionrw   rz   floatr   r   r   r   r   r   r   r   r   r   r+   r(   <module>r      s  $  D D D  - 3 ' /xS) hsCx.@ 0#s(+ c0B 4	eELL%ell8R2S$ST 	Y^YcYc 		ellE%,,:T4U&U V 	[`[e[e 	 OS<<*/,,GK
\\@ OS<<*/,,GK
\\>ELL U\\ 2ell u|| 6S SU[[@Q SVZ S `dLL!&sCxFNu||F\
\\6S5sCx%**!<= SPUVY[^V^P_ Spt S 0 0c 03 0SW 0* %*sCx%**,-



*
* D> \\	. %*sCx%**,-



*
* D> \\	,  	:sCx%**,-:	uell"	#: u||#
$: 	:
 \\::  	:sCx%**,-:UELL !: UELL !: 	:
 \\:._U\\ _%c3hc8R2S _[^ _cg _
$sCx. T#s(^ " 15!	cNd38n-  	
 
#s(^>)E%,,"56 )c )X] )X	ellI&= > 	9 	ell u|| * *r+   