
    3j                         S SK JrJrJrJrJrJrJrJr  S SK	r	S SK	J
r
  S SKJr  S SKJr  S SKJrJr  S SKJr  S SKJr  S S	KJr  \\\4   r\\\\\   4   r\\   r " S
 S\\5      rg)    )AnyDictIteratorListOptionalTupleUnioncastN)nn)OperationBase)PolicySequential)ImageSequentialBaseTransformMatrixMinIn)InputSequentialOps)	ParamItemeye_likec                   T  ^  \ rS rSrSrSS\\   S\SS4U 4S jjjrS\	SS4S	 jr
SU 4S
 jjrS\\   S\\	   4S jrS\S\	4S jrS\R                  S\R                  4S jr   SS\R                  S\\\      S\S\\\\4      S\\R                     4
S jjrSS\\\      S\4S jjrS\R0                  S\\   4S jr SS\R                  S\\   S\\\\4      S\R                  4S jjr SS\R                  S\\\      S\\\\4      S\R                  4S jjrSrU =r$ )PolicyAugmentBase#   z Policy-based image augmentation.policytransformation_matrix_modereturnNc                 |   > U R                  U5      n[        TU ]  " U6   U R                  U5        [        4U l        g N)compose_policysuper__init__!_parse_transformation_matrix_moder   $_valid_ops_for_transform_computation)selfr   r   policies	__class__s       W/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/augmentation/auto/base.pyr   PolicyAugmentBase.__init__&   s:    &&v.(#../IJFVEX1    modulec                 N    U R                   R                  UR                  5        g r   )_transform_matricesappendtransform_matrix)r!   r'   s     r$   %_update_transform_matrix_for_valid_op7PolicyAugmentBase._update_transform_matrix_for_valid_op,   s      ''(?(?@r&   c                 @   > U R                  5         [        TU ]	  5       $ )z4Reset cached params and transformation-matrix state.)_reset_transform_matrix_stater   clear_state)r!   r#   s    r$   r0   PolicyAugmentBase.clear_state/   s    **,w"$$r&   c                 N    U Vs/ s H  o R                  U5      PM     sn$ s  snf )z-Compose policy by the provided policy config.)compose_subpolicy_sequential)r!   r   	subpolicys      r$   r    PolicyAugmentBase.compose_policy4   s#    NTUf11)<fUUUs   "r4   c                     [         e)zBuild a :class:`PolicySequential` from a single sub-policy spec.

Args:
    subpolicy: Sub-policy definition used by the concrete augmentation.

Returns:
    The sequential module representing that sub-policy.
)NotImplementedError)r!   r4   s     r$   r3   .PolicyAugmentBase.compose_subpolicy_sequential8   s
     "!r&   inputc                     [        SU5      $ )zReturn identity matrix.   r   )r!   r9   s     r$   identity_matrix!PolicyAugmentBase.identity_matrixC   s    5!!r&   params	recompute
extra_argsc           	          Uc  [        S5      eU R                  U5      nSn[        XRb  UO/ 5       HX  u  u  pxn	[        [        U5      nUR                  U[        [        [        [              U	R                  5      X4S9n
Uc  U
OX-  nMZ     U$ )aj  Compute the transformation matrix according to the provided parameters.

Args:
    input: the input torch.Tensor.
    params: params for the sequence.
    recompute: if to recompute the transformation matrix according to the params.
        default: False.
    extra_args: Optional dictionary of extra arguments with specific options for different input types.

Nzrequires params to be provided.)r>   r?   r@   )
r7   get_forward_sequencezipr
   r   get_transformation_matrixr   r   r   data)r!   r9   r>   r?   r@   named_modulesres_mat_r'   parammats              r$   rD   +PolicyAugmentBase.get_transformation_matrixG   s    " >%&GHH9=9R9RSY9Z +/"%m?QVWY"ZKQ*F3F22d8DO#<ejjIU^ 3 C %_c#-G #[ r&   c                     U R                  U5      nU H,  u  p4[        [        U5      nUR                  5       (       a  M,    g   g)zCheck whether all selected sub-policies are intensity-only.

Args:
    params: Optional parameters that define which sub-policies to inspect.

Returns:
    ``True`` if no geometric transform is selected, ``False`` otherwise.
FT)rB   r
   r   is_intensity_only)r!   r>   rF   rH   r'   s        r$   rM   #PolicyAugmentBase.is_intensity_onlyf   sE     :>9R9RSY9Z&IA*F3F++-- ' r&   batch_shapec                     U R                  5       n/ nU HB  u  pE[        [        U5      nUR                  U5      n[	        XF5      nUR                  U5        MD     U$ )zGenerate per-module parameters for one policy forward pass.

Args:
    batch_shape: Input shape used to sample operation parameters.

Returns:
    Parameters for each selected child module, in execution order.
)rB   r
   r   forward_parametersr   r*   )r!   rO   rF   r>   namer'   	mod_paramrI   s           r$   rQ   $PolicyAugmentBase.forward_parametersv   s\     :>9R9R9T"$)LD-0F11+>Id.EMM% 	 *
 r&   c                 x    U H3  nU R                  UR                  5      n[        R                  " XXCS9nM5     U$ )zApply a prepared parameter list to the input tensor.

Args:
    input: Input tensor.
    params: Parameters produced by :meth:`forward_parameters`.
    extra_args: Optional overrides forwarded to child transforms.

Returns:
    Transformed tensor.
r'   rI   r@   )get_submodulerR   r   	transform)r!   r9   r>   r@   rI   r'   s         r$   transform_inputs"PolicyAugmentBase.transform_inputs   s;     E''

3F&00UjE  r&   c                    U R                  5         Uc%  UnU R                  USS9u  pVU R                  U5      nU HD  nU R                  UR                  5      n[
        R                  " XXsS9nU R                  U5        MF     X l        U$ )a#  Apply the policy to ``input`` and cache the parameters used.

Args:
    input: Input tensor.
    params: Optional precomputed parameters. If omitted, parameters are
        sampled on-the-fly.
    extra_args: Optional overrides forwarded to child transforms.

Returns:
    Augmented tensor.
)      )	dim_rangerV   )	r0   autofill_dimrQ   rW   rR   r   rX   "_update_transform_matrix_by_module_params)	r!   r9   r>   r@   inprH   	out_shaperI   r'   s	            r$   forwardPolicyAugmentBase.forward   s     	>C,,SF,CLA,,Y7FE''

3F&00UjE33F; 
 r&   )ra   r    )silence)r   N)NFNr   )NN)__name__
__module____qualname____firstlineno____doc__r   SUBPOLICY_CONFIGstrr   r   r,   r0   r   r3   torchTensorr<   r   r   boolr   r   rD   rM   SizerQ   rY   rd   __static_attributes____classcell__)r#   s   @r$   r   r   #   s   *Yt$45 YSV Ygk Y YA<L AQU A%
VT*:%; VEU@V V	"6F 	"K[ 	""U\\ "ell " -1/3|| i) 	
 T#s(^, 
%,,	>i(A T  ejj T)_ * dh\\+/	?HPQUVY[^V^Q_H`	& uy\\+3DO+DYabfgjlogobpYq	 r&   r   )typingr   r   r   r   r   r   r	   r
   rn   r   (kornia.augmentation.auto.operations.baser   *kornia.augmentation.auto.operations.policyr   "kornia.augmentation.container.baser   r   !kornia.augmentation.container.opsr   $kornia.augmentation.container.paramsr   kornia.core.opsr   floatintNUMBERrm   	OP_CONFIGrl   r    r&   r$   <module>r      si   $ K J J   B G X @ : $	ucz	#vx//0		? T+-A Tr&   