
    JTh`                     b    S SK Js  Jr  S SKJr  SSKJr  SS/r " S S\5      r	 " S S\5      r
g)	    N)Tensor   )ModulePixelShufflePixelUnshufflec                   j   ^  \ rS rSr% SrS/r\\S'   S\SS4U 4S jjrS\	S\	4S jr
S\4S	 jrS
rU =r$ )r   
   a  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U ]  5         Xl        g N)super__init__r
   )selfr
   	__class__s     U/var/www/auris/envauris/lib/python3.13/site-packages/torch/nn/modules/pixelshuffle.pyr   PixelShuffle.__init__6   s    ,    inputc                 B    [         R                  " XR                  5      $ r   )Fpixel_shuffler
   r   r   s     r   forwardPixelShuffle.forward:   s    u&9&9::r   c                      SU R                    3$ )Nzupscale_factor=r
   r   s    r   
extra_reprPixelShuffle.extra_repr=   s     !4!4 566r   r   __name__
__module____qualname____firstlineno____doc____constants__int__annotations__r   r   r   strr   __static_attributes____classcell__r   s   @r   r   r   
   sP    &P &&M-s -t -;V ; ;7C 7 7r   c                   j   ^  \ rS rSr% SrS/r\\S'   S\SS4U 4S jjrS\	S\	4S jr
S\4S	 jrS
rU =r$ )r   A   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                 .   > [         TU ]  5         Xl        g r   )r   r   r0   )r   r0   r   s     r   r   PixelUnshuffle.__init__k   s     0r   r   c                 B    [         R                  " XR                  5      $ r   )r   pixel_unshuffler0   r   s     r   r   PixelUnshuffle.forwardo   s      (=(=>>r   c                      SU R                    3$ )Nzdownscale_factor=r0   r   s    r   r   PixelUnshuffle.extra_reprr   s    "4#8#8"9::r   r7   r!   r-   s   @r   r   r   A   sP    $L ((M1 1 1?V ? ?;C ; ;r   )torch.nn.functionalnn
functionalr   torchr   moduler   __all__r   r    r   r   <module>r@      s7        +
,476 47n2;V 2;r   