o
    oi
                     @   sL   d dl mZmZmZmZ d dlZd dlmZ d dlmZ G dd deZ	dS )    )AnyDictOptionalTupleN)Tensor)GeometricAugmentationBase2Dc                       s   e Zd ZdZ	ddeeef dededed	d
f
 fddZ	de
deee
f deeef d	e
fddZ	
dde
deee
f deeef dee
 d	e
f
ddZ	
	
dde
deeef dee
 deeeef  d	e
f
ddZ  ZS )PadToaa  Pad the given sample to a specific size. Always occurs (p=1.0).

    .. image:: _static/img/PadTo.png

    Args:
        size: a tuple of ints in the format (height, width) that give the spatial
            dimensions to pad inputs to.
        pad_mode: the type of padding to perform on the image (valid values
            are those accepted by torch.nn.functional.pad)
        pad_value: fill value for 'constant' padding applied to the image
        keepdim: whether to keep the output shape the same as input (True) or broadcast it
                 to the batch form (False).

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

    .. note::
        This function internally uses :func:`torch.nn.functional.pad`.

    Examples:
        >>> import torch
        >>> img = torch.tensor([[[[0., 0., 0.],
        ...                       [0., 0., 0.],
        ...                       [0., 0., 0.]]]])
        >>> pad = PadTo((4, 5), pad_value=1.)
        >>> out = pad(img)
        >>> out
        tensor([[[[0., 0., 0., 1., 1.],
                  [0., 0., 0., 1., 1.],
                  [0., 0., 0., 1., 1.],
                  [1., 1., 1., 1., 1.]]]])
        >>> pad.inverse(out)
        tensor([[[[0., 0., 0.],
                  [0., 0., 0.],
                  [0., 0., 0.]]]])

    constantr   Fsizepad_mode	pad_valuekeepdimreturnNc                    s&   t  jddd|d |||d| _d S )Ng      ?T)psame_on_batchp_batchr   )r
   r   r   )super__init__flags)selfr
   r   r   r   	__class__ Y/home/ubuntu/.local/lib/python3.10/site-packages/kornia/augmentation/_2d/geometric/pad.pyr   B   s   zPadTo.__init__imageparamsr   c                 C   s
   |  |S N)identity_matrix)r   r   r   r   r   r   r   compute_transformationJ   s   
zPadTo.compute_transformationinput	transformc           
      C   sT   |j \}}}}|d d | }|d d | }	tjjj|d|	d|g|d |d dS )Nr
   r      r   r   )modevalue)shapetorchnn
functionalpad)
r   r   r   r   r    _heightwidth
height_pad	width_padr   r   r   apply_transformM   s   zPadTo.apply_transformc                 C   s.   |d u rt d|dd |d d |d f S )Nz#`size` has to be a tuple. Got None..r   r!   )RuntimeError)r   r   r   r    r
   r   r   r   inverse_transformW   s   zPadTo.inverse_transform)r	   r   Fr   )NN)__name__
__module____qualname____doc__r   intstrfloatboolr   r   r   r   r   r   r.   r0   __classcell__r   r   r   r   r      sP    (
*



r   )
typingr   r   r   r   r%   r   &kornia.augmentation._2d.geometric.baser   r   r   r   r   r   <module>   s
   