o
    h`                     @   sV   d dl m  mZ d dlmZ ddlmZ ddgZG dd deZ	G dd deZ
dS )	    N)Tensor   )ModulePixelShufflePixelUnshufflec                       Z   e Zd ZU dZdgZeed< deddf fddZdedefdd	Z	de
fd
dZ  ZS )r   aS  Rearrange elements in a tensor according to an upscaling factor.

    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_factorreturnNc                       t    || _d S N)super__init__r   )selfr   	__class__ q/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torch/nn/modules/pixelshuffle.pyr   6      

zPixelShuffle.__init__inputc                 C      t || jS r   )Fpixel_shuffler   r   r   r   r   r   forward:      zPixelShuffle.forwardc                 C      d| j  S )Nzupscale_factor=)r   r   r   r   r   
extra_repr=      zPixelShuffle.extra_repr__name__
__module____qualname____doc____constants__int__annotations__r   r   r   strr   __classcell__r   r   r   r   r   
   s   
 (c                       r   )r   a  Reverse the PixelShuffle operation.

    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_factorr	   Nc                    r
   r   )r   r   r)   )r   r)   r   r   r   r   k   r   zPixelUnshuffle.__init__r   c                 C   r   r   )r   pixel_unshuffler)   r   r   r   r   r   o   r   zPixelUnshuffle.forwardc                 C   r   )Nzdownscale_factor=)r)   r   r   r   r   r   r   r   zPixelUnshuffle.extra_reprr   r   r   r   r   r   A   s   
 &)torch.nn.functionalnn
functionalr   torchr   moduler   __all__r   r   r   r   r   r   <module>   s    7