U
    ‰dõ  ã                   @   sH   d dl mZ ddlmZ ddlmZ G dd„ deƒZG dd	„ d	eƒZd
S )é   )ÚModuleé   )Ú
functionalé    )ÚTensorc                       sV   e Zd ZU dZdgZeed< eddœ‡ fdd„Zeedœdd	„Z	e
d
œ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)`, where r is an upscale factor.

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

    See 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:`(*, C_{in}, H_{in}, W_{in})`, where * is zero or more batch dimensions
        - Output: :math:`(*, C_{out}, H_{out}, W_{out})`, where

    .. math::
        C_{out} = C_{in} \div \text{upscale\_factor}^2

    .. math::
        H_{out} = H_{in} \times \text{upscale\_factor}

    .. 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_factorN)r   Úreturnc                    s   t t| ƒ ¡  || _d S ©N)Úsuperr   Ú__init__r   )Úselfr   ©Ú	__class__© úA/tmp/pip-unpacked-wheel-ua33x9lu/torch/nn/modules/pixelshuffle.pyr   0   s    zPixelShuffle.__init__©Úinputr	   c                 C   s   t  || j¡S r
   )ÚFZpixel_shuffler   ©r   r   r   r   r   Úforward4   s    zPixelShuffle.forward©r	   c                 C   s   d  | j¡S )Nzupscale_factor={})Úformatr   ©r   r   r   r   Ú
extra_repr7   s    zPixelShuffle.extra_repr©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z__constants__ÚintÚ__annotations__r   r   r   Ústrr   Ú__classcell__r   r   r   r   r      s   
%r   c                       sV   e Zd ZU dZdgZeed< eddœ‡ fdd„Zeedœdd	„Z	e
d
œdd„Z‡  ZS )ÚPixelUnshuffleaò  Reverses the :class:`~torch.nn.PixelShuffle` operation by rearranging elements
    in a tensor of shape :math:`(*, C, H \times r, W \times r)` to a tensor of shape
    :math:`(*, C \times r^2, H, W)`, where r is a downscale factor.

    See 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:
        downscale_factor (int): factor to decrease spatial resolution by

    Shape:
        - Input: :math:`(*, C_{in}, H_{in}, W_{in})`, where * is zero or more batch dimensions
        - Output: :math:`(*, C_{out}, H_{out}, W_{out})`, where

    .. math::
        C_{out} = C_{in} \times \text{downscale\_factor}^2

    .. math::
        H_{out} = H_{in} \div \text{downscale\_factor}

    .. math::
        W_{out} = W_{in} \div \text{downscale\_factor}

    Examples::

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

    .. _Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network:
        https://arxiv.org/abs/1609.05158
    Údownscale_factorN)r%   r	   c                    s   t t| ƒ ¡  || _d S r
   )r   r$   r   r%   )r   r%   r   r   r   r   b   s    zPixelUnshuffle.__init__r   c                 C   s   t  || j¡S r
   )r   Zpixel_unshuffler%   r   r   r   r   r   f   s    zPixelUnshuffle.forwardr   c                 C   s   d  | j¡S )Nzdownscale_factor={})r   r%   r   r   r   r   r   i   s    zPixelUnshuffle.extra_reprr   r   r   r   r   r$   ;   s   
#r$   N)	Úmoduler   Ú r   r   Ztorchr   r   r$   r   r   r   r   Ú<module>   s   4