
    3jD                         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Jr  S SKJr  \" S5      r " S S\5      r " S	 S
\
R&                  \S9r " S S\5      r " S S\\5      rg)    )AnyCallableDictOptionalTupleTypeTypeVarUnionN)nn)DistributionUniform)MultiprocessWrapperTc                   8    \ rS rSrSrS\\   S\S\S\4S jrSr	g	)
_PostInitInjectionMetaClass   zMTo inject the ``__post_init__`` function after the creation of each instance.clsargskwargsreturnc                 Z    [         R                  " U /UQ70 UD6nUR                  5         U$ N)type__call____post_init__)r   r   r   objs       c/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/augmentation/random_generator/base.pyr   $_PostInitInjectionMetaClass.__call__    s+    mmC1$1&1
     N)
__name__
__module____qualname____firstlineno____doc__r   r   r   r   __static_attributes__r    r   r   r   r      s*    Wd1g c S Q r   r   c            	       ~  ^  \ rS rSr% SrSr\S\\R
                  4   \	S'   \R                  \	S'   SU 4S jjrSS jrS\R                  4S\\R
                     S\R                  SS4S	 jjrS
\S\SS 4S jrS\R
                  S\R                  SS4S jrSS\\S4   S\S\\\R.                  4   4S jjrSrU =r$ )RandomGeneratorBase&   z9Base class for generating random augmentation parameters.Ndevicedtyper   c                 "   > [         TU ]  5         g r   )super__init__)self	__class__s    r   r.   RandomGeneratorBase.__init__,   s    r   c                 $    U R                  5         g r   )set_rng_device_and_dtype)r/   s    r   r   !RandomGeneratorBase.__post_init__/   s    %%'r   c                     Uc  [         R                  " S5      nU R                  U:w  d  U R                  U:w  a  U R                  X5        Xl        X l        gg)zChange the random generation device and dtype.

Note:
    The generated random numbers are not reproducible across different devices and dtypes.

Ncpu)torchr*   r+   make_samplersr/   r*   r+   s      r   r3   ,RandomGeneratorBase.set_rng_device_and_dtype2   sK     >\\%(F;;& DJJ%$7v- KJ %8r   r   r   c                     [         R                  R                  R                  " U0 UD6u  p4  nU R	                  X4S9  U $ )zUpdate sampler device and dtype using ``torch.nn.Module.to`` semantics.

Args:
    *args: Positional arguments accepted by ``Module.to``.
    **kwargs: Keyword arguments accepted by ``Module.to``.

Returns:
    This generator instance.
r*   r+   )r7   _C_nn	_parse_tor3   )r/   r   r   r*   r+   _s         r   toRandomGeneratorBase.toE   s>     $hhll44dEfEq!%%V%Ar   c                     [         e)zCreate distribution samplers for the given device and dtype.

Args:
    device: Target device.
    dtype: Target floating-point dtype.

Raises:
    NotImplementedError: Subclass did not implement sampler creation.
NotImplementedErrorr9   s      r   r8   !RandomGeneratorBase.make_samplersS   s
     "!r   batch_shape.same_on_batchc                     [         e)aN  Sample random augmentation parameters.

Args:
    batch_shape: Target batch shape.
    same_on_batch: If ``True``, use one sample and broadcast it across the
        batch dimension.

Returns:
    Dictionary of tensors consumed by augmentation modules.

Raises:
    NotImplementedError: Subclass did not implement parameter sampling.
rD   )r/   rG   rH   s      r   forwardRandomGeneratorBase.forward_   s
     "!r   r<   )r   N)F)r!   r"   r#   r$   r%   r*   r
   strr7   __annotations__r+   r.   r   float32r   r3   r   rA   r8   r   intboolr   TensorrJ   r&   __classcell__)r0   s   @r   r(   r(   &   s    C-1FE$U\\)*1;;(
 *."]]& {{ 
	& s /D 
"ELL 
" 
" 
""5c? "4 "TXY\^c^j^jYjTk " "r   r(   )	metaclassc                      \ rS rSrSrSS\S\\\R                  /\R                  4      SS4S jjr
S\\S	4   S\R                  4S
 jrS\\S	4   S\R                  4S jrS\S\R                  4S jrS\S\4S jrSrg)DistributionWithMapperp   a  Wraps a distribution with a value mapper function.

This is used to restrict the output values of a given distribution by a value mapper function.
The value mapper function can be functions like sigmoid, tanh, etc.

Args:
    dist: the target distribution.
    map_fn: the callable function to adjust the output from distributions.

Example:
    >>> from torch.distributions import Normal
    >>> import torch.nn as nn
    >>> # without mapper
    >>> dist = DistributionWithMapper(Normal(0., 1.,), map_fn=None)
    >>> _ = torch.manual_seed(0)
    >>> dist.rsample((8,))
    tensor([ 1.5410, -0.2934, -2.1788,  0.5684, -1.0845, -1.3986,  0.4033,  0.8380])
    >>> # with sigmoid mapper
    >>> dist = DistributionWithMapper(Normal(0., 1.,), map_fn=nn.Sigmoid())
    >>> _ = torch.manual_seed(0)
    >>> dist.rsample((8,))
    tensor([0.8236, 0.4272, 0.1017, 0.6384, 0.2527, 0.1980, 0.5995, 0.6980])

Ndistmap_fnr   c                     Xl         X l        g r   rW   rX   )r/   rW   rX   s      r   r.   DistributionWithMapper.__init__   s    	r   sample_shape.c                     U R                   R                  [        R                  " U5      5      nU R                  b  U R	                  U5      nU$ )zDraw a reparameterized sample and apply ``map_fn`` when provided.

Args:
    sample_shape: Desired sample shape.

Returns:
    Sample tensor after optional mapping.
)rW   rsampler7   SizerX   r/   r\   outs      r   r^   DistributionWithMapper.rsample   s>     ii

< 89;;"++c"C
r   c                     U R                   R                  [        R                  " U5      5      nU R                  b  U R	                  U5      nU$ )zDraw a sample and apply ``map_fn`` when provided.

Args:
    sample_shape: Desired sample shape.

Returns:
    Sample tensor after optional mapping.
)rW   sampler7   r_   rX   r`   s      r   rd   DistributionWithMapper.sample   s>     iiuzz,78;;"++c"C
r   nc                 x    U R                   R                  U5      nU R                  b  U R                  U5      nU$ )zDraw ``n`` samples and apply ``map_fn`` when provided.

Args:
    n: Number of samples.

Returns:
    Sample tensor after optional mapping.
)rW   sample_nrX   )r/   rf   ra   s      r   rh   DistributionWithMapper.sample_n   s5     ii  #;;"++c"C
r   attrc                 f     [        X5      $ ! [         a    [        U R                  U5      s $ f = fr   )getattrAttributeErrorrW   )r/   rj   s     r   __getattr__"DistributionWithMapper.__getattr__   s2    	,4&& 	,499d++	,s   
  00rZ   r   )r!   r"   r#   r$   r%   r   r   r   r7   rQ   r.   r   rO   r^   rd   rh   rL   r   rn   r&   r    r   r   rU   rU   p   s    2\ 8Hell^UZUaUaEa<b3c os E#s(O  5c? u|| # %,, , , ,r   rU   c                       \ rS rSrSrSrg)UniformDistribution   zgWrapper around torch Uniform distribution which makes it work with the 'spawn' multiprocessing context.r    N)r!   r"   r#   r$   r%   r&   r    r   r   rq   rq      s    qr   rq   )typingr   r   r   r   r   r   r	   r
   r7   r   torch.distributionsr   r   !kornia.augmentation.utils.helpersr   r   r   r   Moduler(   rU   rq   r    r   r   <module>rw      sh   $ N M M   5 ACL$ G""))/J G"TL,\ L,^r-w rr   