3
I4W^e  ã               @   s,   d dl mZ ddlmZ G dd„ deƒZdS )é   )ÚModuleé   )Ú
functionalc                   s6   e Zd ZdZdgZ‡ fdd„Zdd„ Zdd„ Z‡  ZS )	ÚPixelShufflea£  Rearranges elements in a tensor of shape :math:`(*, C \times r^2, H, W)`
    to a tensor of shape :math:`(*, C, H \times r, W \times r)`.

    This is useful for implementing efficient sub-pixel convolution
    with a stride of :math:`1/r`.

    Look at the paper:
    `Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network`_
    by Shi et. al (2016) for more details.

    Args:
        upscale_factor (int): factor to increase spatial resolution by

    Shape:
        - Input: :math:`(N, L, H_{in}, W_{in})` where :math:`L=C \times \text{upscale\_factor}^2`
        - Output: :math:`(N, C, H_{out}, W_{out})` where
          :math:`H_{out} = H_{in} \times \text{upscale\_factor}`
          and :math:`W_{out} = W_{in} \times \text{upscale\_factor}`

    Examples::

        >>> pixel_shuffle = nn.PixelShuffle(3)
        >>> input = torch.randn(1, 9, 4, 4)
        >>> output = pixel_shuffle(input)
        >>> print(output.size())
        torch.Size([1, 1, 12, 12])

    .. _Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network:
        https://arxiv.org/abs/1609.05158
    Úupscale_factorc                s   t t| ƒjƒ  || _d S )N)Úsuperr   Ú__init__r   )Úselfr   )Ú	__class__© ú>/tmp/pip-build-e66j97b2/torch/torch/nn/modules/pixelshuffle.pyr   &   s    zPixelShuffle.__init__c             C   s   t j|| jƒS )N)ÚFZpixel_shuffler   )r	   Úinputr   r   r   Úforward*   s    zPixelShuffle.forwardc             C   s   dj | jƒS )Nzupscale_factor={})Úformatr   )r	   r   r   r   Ú
extra_repr-   s    zPixelShuffle.extra_repr)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z__constants__r   r   r   Ú__classcell__r   r   )r
   r   r      s
   r   N)Úmoduler   Ú r   r   r   r   r   r   r   Ú<module>   s   