
    3j+t                    >   % S SK Jr  S SKrS SKJr  S SKrS SKJs  Jr	  S SKJr  S SK
JrJr  S SKJr  S SKJrJrJr  S SKJr  S S	KJr  0 rS
\S'   SS/rS"S jrS"S jr   S#         S$S jjrS%S jrS%S jrS"S jrS&S jr S"S jr!S"S jr"    S'S jr#        S(S jr$        S(S jr%S)S jr&S*S jr'          S+S jr(                  S,S jr)S-S jr*\  S.         S/S jj5       r+      S0S  jr, " S! S\RZ                  5      r.g)1    )annotationsN)Union)nn)rgb_to_ycbcrycbcr_to_rgb)pi)KORNIA_CHECKKORNIA_CHECK_IS_TENSORKORNIA_CHECK_SHAPErescale)perform_keep_shape_imagezhdict[tuple[Union[torch.dtype, None], Union[str, torch.device, None]], tuple[torch.Tensor, torch.Tensor]]_DCT8_CACHEJPEGCodecDifferentiablejpeg_codec_differentiablec                6    U R                  5       nXU-
  S-  -   $ )zDifferentiable rounding.

Args:
    input: Input tensor of any shape to be rounded.

Returns:
    Pseudo rounded tensor of the same shape as input tensor.

   )round)inputinput_rounds     M/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/enhance/jpeg.py#_differentiable_polynomial_roundingr   ,   s"     ++-K+-!333    c                <    U R                  5       nXS-
  U-
  S-  -   $ )zPerform floor via a differentiable operation.

Args:
    input: Input tensor of any shape to be floored.

Returns:
    Pseudo rounded tensor of the same shape as input tensor.

      ?r   )floor)r   input_floors     r    _differentiable_polynomial_floorr   :   s&     ++-K#+3999r   c                    U R                  5       nUb.  U* [        R                  " XDU:     * U-   5      S-
  -  U-   XDU:  '   Ub,  U[        R                  " XDU:     U-
  5      S-
  -  U-   XDU:  '   U$ )a#  Clip via a differentiable and soft approximation of the clipping operation.

Args:
    input: Input tensor of any shape.
    min_val: Minimum value.
    max_val: Maximum value.
    scale: Scale value. Default 0.02.

Returns:
    Clipped output tensor of the same shape as the input tensor.

      ?)clonetorchexp)r   min_valmax_valscaleoutputs        r   _differentiable_clippingr(   H   s    $ !;;=F$)6UYY?O8P7PSZ7Z-[^a-a#bel#l #(EIIfg=M6NQX6X,Y\_,_#`cj#j Mr   c                ^    [         R                  " / SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/U US	9$ )
z1Generate default Quantization table of Y channel.)      
   r*      (   3   =   )   r1            :   <   7   )r2      r*   r-   r.   9   E   8   )r2            r/   W   P   >   )   r=   %   r;   D   m   g   M   )r-   #   r7   @   Q   h   q   \   )1   rI   N   r?   rF   y   x   e   )H   rM   _   b   p   d   rF   c   devicedtyper"   tensorrY   s     r   _get_default_qt_yr^   b   s8    <<,,,,..0/		
  r   c                ^    [         R                  " / SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/ SQ/U US9$ )z2Generate default Quantization table of C channels.)r<   rB   r-   /   rX   rX   rX   rX   )rB      r4   B   rX   rX   rX   rX   )r-   r4   r;   rX   rX   rX   rX   rX   )r`   rb   rX   rX   rX   rX   rX   rX   )rX   rX   rX   rX   rX   rX   rX   rX   rY   r\   rY   s     r   _get_default_qt_crc   t   s8    <<,,,,,,,,		
  r   c                    U R                   u  pnU R                  XS-  SUS-  S5      R                  SSSSS5      R                  USSS5      nU$ )zExtract non-overlapping 8 x 8 patches from the given input image.

Args:
    input (torch.Tensor): Input image of the shape :math:`(B, H, W)`.

Returns:
    output (torch.Tensor): Image patchify of the shape :math:`(B, N, 8, 8)`.

   r      r         shapeviewpermutereshape)r   BHWr'   s        r   _patchify_8x8rr      s\     kkGA! ::aaAFA>FFq!QPQSTU]]^_acefhijFMr   c                    U R                   SS u  p4U R                  X1S-  US-  SS5      R                  SSSSS5      R                  X1U5      nU$ )a  Reverse non-overlapping 8 x 8 patching.

Args:
    input (torch.Tensor): Input image of the shape :math:`(B, N, 8, 8)`.
    H: height of resulting torch.Tensor.
    W: width of resulting torch.Tensor.

Returns:
    output (torch.Tensor): Image patchify of the shape :math:`(B, H, W)`.

Nrg   re   r   rf   r   rh   rj   )r   rp   rq   ro   _Nr'   s         r   _unpatchify_8x8ru      sZ     KKOEA ::aaaA>FFq!QPQSTU]]^_defFMr   c                    U R                   nU R                  n[        X5      u  p4US   [        R                  " U S-
  U5      -  nU$ )zPerform an 8 x 8 discrete cosine transform.

Args:
    input (torch.Tensor): Patched input torch.tensor of the shape :math:`(B, N, 8, 8)`.

Returns:
    output (torch.Tensor): DCT output torch.tensor of the shape :math:`(B, N, 8, 8)`.

NN      `@)r[   rZ   _get_dct8_basis_scaler"   	tensordot)r   r[   rZ   
dct_tensor	dct_scaler'   s         r   _dct_8x8r}      sG     ',kkE-2\\F1%@J$Z05??55=R\3]]FMr   c                   U R                   nU R                  n[        R                  " SXS9nUR	                  S5      nUR	                  S5      n[        R
                  " SU-  S-   U-  [        -  S-  5      n[        R                  " SXS9nSUS'   [        R                  " Xw5      nX-  n X-  n	U	R                  S	S
5      U-  R                  S	S
5      n
U
S-  S-   n
U
$ )zPerform an 8 x 8 inverse discrete cosine transform.

Args:
    input (torch.Tensor): Patched input torch.tensor of the shape :math:`(B, N, 8, 8)`.

Returns:
    output (torch.Tensor): IDCT output torch.tensor of the shape :math:`(B, N, 8, 8)`.

re   r[   rZ   r   rf          @r          0@;f?ri         ?rx   )
r[   rZ   r"   arange	unsqueezecosr   onesouter	transpose)r   r[   rZ   idxspatial_idxfreq_idxbasisalphar|   tmpr'   s              r   	_idct_8x8r      s     KKE\\F
,,q
5C--"K}}QHIIs[(3.(:R?$FGEJJq5EE!HE)IE
-CmmB#e+66r2>Fd]U"FMr   c           	     `    [        [        R                  " U S:  SU -  SSU -  -
  5      5      nU$ )a  Convert a given JPEG quality to the scaling factor.

Args:
    compression_strength (torch.Tensor): Compression strength ranging from 0 to 100. Any shape is supported.

Returns:
    scale (torch.Tensor): Scaling factor to be applied to quantization matrix. Same shape as input.

2   g     @g      i@r   )r   r"   where)compression_strengthr&   s     r   _jpeg_quality_to_scaler      s@     ; 2%))C...	
E Lr   c                    USS2S4   [        U5      SS2SSS4   -  n[        [        US-   S-  SS5      5      nX-  n[        U5      nU$ )a  Perform quantization.

Args:
    input (torch.Tensor): Input torch.tensor of the shape :math:`(B, N, 8, 8)`.
    jpeg_quality (torch.Tensor): Compression strength to be applied, shape is :math:`(B)`.
    quantization_table (torch.Tensor): Quantization table of the shape :math:`(1, 8, 8)` or :math:`(B, 8, 8)`.

Returns:
    output (torch.Tensor): Quantized output torch.tensor of the shape :math:`(B, N, 8, 8)`.

N      I@      Y@rf      )r   r   r(   r   r   jpeg_qualityquantization_tablequantization_table_scaledr'   s        r   	_quantizer      sn    $ 	1d7#&<\&J1dTXZ^K^&__  : ";d"Be!KQPST !5F08FMr   c                    USS2S4   [        U5      SS2SSS4   -  nU [        [        US-   S-  SS5      5      -  nU$ )a  Perform dequantization.

Args:
    input (torch.Tensor): Input torch.tensor of the shape :math:`(B, N, 8, 8)`.
    jpeg_quality (torch.Tensor): Compression strength to be applied, shape is :math:`(B)`.
    quantization_table (torch.Tensor): Quantization table of the shape :math:`(1, 8, 8)` or :math:`(B, 8, 8)`.

Returns:
    output (torch.Tensor): Quantized output torch.tensor of the shape :math:`(B, N, 8, 8)`.

Nr   r   rf   r   )r   r   r(   r   s        r   _dequantizer     sc    $ 	1d7#&<\&J1dTXZ^K^&__  !#C ";d"Be!KQPST$ F Mr   c                    U SS2S4   nU SS2S4   nU SS2S4   n[        USS2S4   SSSSS	9n[        USS2S4   SSSSS	9nXSS2S4   USS2S4   4$ )
a  Implement chroma subsampling.

Args:
    input_ycbcr (torch.Tensor): YCbCr input torch.tensor of the shape :math:`(B, 3, H, W)`.

Returns:
    output_y (torch.Tensor): Y component (not-subsampled), shape is :math:`(B, H, W)`.
    output_cb (torch.Tensor): Cb component (subsampled), shape is :math:`(B, H // 2, W // 2)`.
    output_cr (torch.Tensor): Cr component (subsampled), shape is :math:`(B, H // 2, W // 2)`.

Nr   rf   rg   r   bilinearFTfactorinterpolationalign_corners	antialiasr   )input_ycbcroutput_y	output_cb	output_crs       r   _chroma_subsamplingr   +  s     )A.H)!Q$/I)!Q$/I!T' I !T' I q!t_i1o55r   c                <    [        U SS2S4   SSSSS9nUSS2S4   $ )zPerform chroma upsampling.

Args:
    input_c (torch.Tensor): Cb or Cr component to be upsampled of the shape :math:`(B, H, W)`.

Returns:
    output_c (torch.Tensor): Upsampled C(b or r) component of the shape :math:`(B, H * 2, W * 2)`.

Nr   r   Fr   r   r   )input_coutput_cs     r   _chroma_upsamplingr   M  s6     %4 H AqD>r   c                .   [        U 5      nSU-  n[        U5      u  pVn[        U5      [        U5      [        U5      pvn[        U5      n[        [        R
                  " Xg4SS95      n	[        UUU5      n
[        U	UU5      R                  SSS9u  pXU4$ )ae  Perform JPEG encoding.

Args:
    image_rgb (torch.Tensor): RGB input images of the shape :math:`(B, 3, H, W)`.
    jpeg_quality (torch.Tensor): Compression strength of the shape :math:`(B)`.
    quantization_table_y (torch.Tensor): Quantization table for Y channel.
    quantization_table_c (torch.Tensor): Quantization table for C channels.

Returns:
    y_encoded (torch.Tensor): Encoded Y component of the shape :math:`(B, N, 8, 8)`.
    cb_encoded (torch.Tensor): Encoded Cb component of the shape :math:`(B, N, 8, 8)`.
    cr_encoded (torch.Tensor): Encoded Cr component of the shape :math:`(B, N, 8, 8)`.

     o@rf   dimrg   )r   r   rr   r}   r"   catr   chunk)	image_rgbr   quantization_table_yquantization_table_cimage_ycbcrinput_yinput_cbinput_crdct_y	dct_cb_cr	y_encoded
cb_encoded
cr_encodeds                r   _jpeg_encoder   b  s    * !-Y 7K+%K"5k"BGx 	ghh  G
 WEH#7Q?@I'I
 ' eA1eo	 J
 *,,r   c                   [        U UU5      n [        [        R                  " X4SS9UU5      n[        U 5      n	[        U5      R	                  SSS9u  p[        XU5      n[        XS-  US-  5      n[        XS-  US-  5      n[        U5      n[        U5      n[        R                  " XU4SS9S-  n[        U5      nU$ )a  Perform JPEG decoding.

Args:
    input_y (torch.Tensor): Compressed Y component of the shape :math:`(B, N, 8, 8)`.
    input_cb (torch.Tensor): Compressed Cb component of the shape :math:`(B, N, 8, 8)`.
    input_cr (torch.Tensor): Compressed Cr component of the shape :math:`(B, N, 8, 8)`.
    jpeg_quality (torch.Tensor): Compression strength of the shape :math:`(B)`.
    H (int): Original image height.
    W (int): Original image width.
    quantization_table_y (torch.Tensor): Quantization table for Y channel.
    quantization_table_c (torch.Tensor): Quantization table for C channels.

Returns:
    rgb_decoded (torch.Tensor): Decompressed RGB image of the shape :math:`(B, 3, H, W)`.

rf   r   rg   r   )	r   r"   r   r   r   ru   r   stackr   )r   r   r   r   rp   rq   r   r   input_cb_cridct_yidct_cbidct_crimage_yimage_cbimage_crr   rgb_decodeds                    r   _jpeg_decoder     s    6 G
 		8&A.K %W-F -33A13=G+Fq9G,W1fa1fEH,W1fa1fEH!(+H!(+H %W,Iq QTY YK ,[ 9Kr   c                    U R                   SS u  p[        R                  " US-  5      S-  U-
  n[        R                  " US-  5      S-  U-
  n[        R                  " U SUSU4S5      nXSU4$ )a#  Pad a given image to be dividable by 16.

Args:
    image: Image of the shape :math:`(*, 3, H, W)`.

Returns:
    image_padded: Padded image of the shape :math:`(*, 3, H_{new}, W_{new})`.
    h_pad: Padded pixels along the horizontal axis.
    w_pad: Padded pixels along the vertical axis.

r   Nr*   r   	replicate)rk   mathceilFpad)imagerp   rq   h_padw_padimage_paddeds         r   _perform_paddingr     st     ;;rsDA1r6"R'!+E1r6"R'!+E!"uq%E.BK!PL%%r   c                "   [        U 5        [        U5        U R                  nU R                  nUc  [        XT5      OUnUc  [	        XT5      OUn[        U5        [        U5        [        U / SQ5        [        US/5        UR                  S:X  a  UR                  SS9nUR                  S:X  a  UR                  SS9n[        U/ SQ5        [        U/ SQ5        [        UR                  5       R                  5       S:  =(       a!    UR                  5       R                  5       S	:*  S
UR                  5       R                  5        SUR                  5       R                  5        S35        [        U 5      u  pnU R                  SS u  pUR                  S   S:w  aJ  [        UR                  S   U R                  S   :H  SU R                  S    SUR                  S    S35        UR                  S   S:w  aJ  [        UR                  S   U R                  S   :H  SU R                  S    SUR                  S    S35        UR                  S   S:w  aJ  [        UR                  S   U R                  S   :H  SU R                  S    SUR                  S    S35        UR                  XT5      nUR                  XT5      nUR                  XT5      n[        U UUUS9u  pn[!        U
UUUUU	UUS9n[#        USSS9nUSSX-
  2SX-
  24   nU$ )a8  Differentiable JPEG encoding-decoding module.

Based on :cite:`reich2024` :cite:`shin2017`, we perform differentiable JPEG encoding-decoding as follows:

.. image:: _static/img/jpeg_codec_differentiable.png

.. math::

    \text{JPEG}_{\text{diff}}(I, q, QT_{y}, QT_{c}) = \hat{I}

Where:
   - :math:`I` is the original image to be coded.
   - :math:`q` is the JPEG quality controlling the compression strength.
   - :math:`QT_{y}` is the luma quantization table.
   - :math:`QT_{c}` is the chroma quantization table.
   - :math:`\hat{I}` is the resulting JPEG encoded-decoded image.

.. note:::
    The input (and output) pixel range is :math:`[0, 1]`. In case you want to handle normalized images you are
    required to first perform denormalization followed by normalizing the output images again.

    Note, that this implementation models the encoding-decoding mapping of JPEG in a differentiable setting,
    however, does not allow the excess of the JPEG-coded byte file itself.
    For more details please refer to :cite:`reich2024`.

    This implementation is not meant for data loading. For loading JPEG images please refer to `kornia.io`.
    There we provide an optimized Rust implementation for fast JPEG loading.

Args:
    image_rgb: the RGB image to be coded.
    jpeg_quality: JPEG quality in the range :math:`[0, 100]` controlling the compression strength.
    quantization_table_y: quantization table for Y channel. Default: `None`, which will load the standard
      quantization table.
    quantization_table_c: quantization table for C channels. Default: `None`, which will load the standard
      quantization table.

Shape:
    - image_rgb: :math:`(*, 3, H, W)`.
    - jpeg_quality: :math:`(1)` or :math:`(B)` (if used batch dim. needs to match w/ image_rgb).
    - quantization_table_y: :math:`(8, 8)` or :math:`(B, 8, 8)` (if used batch dim. needs to match w/ image_rgb).
    - quantization_table_c: :math:`(8, 8)` or :math:`(B, 8, 8)` (if used batch dim. needs to match w/ image_rgb).

Return:
    JPEG coded image of the shape :math:`(B, 3, H, W)`

Example:
    To perform JPEG coding with the standard quantization tables just provide a JPEG quality

    >>> img = torch.rand(3, 3, 64, 64, requires_grad=True, dtype=torch.float)
    >>> jpeg_quality = torch.tensor((99.0, 25.0, 1.0), requires_grad=True)
    >>> img_jpeg = jpeg_codec_differentiable(img, jpeg_quality)
    >>> img_jpeg.sum().backward()

    You also have the option to provide custom quantization tables

    >>> img = torch.rand(3, 3, 64, 64, requires_grad=True, dtype=torch.float)
    >>> jpeg_quality = torch.tensor((99.0, 25.0, 1.0), requires_grad=True)
    >>> quantization_table_y = torch.randint(1, 256, size=(3, 8, 8), dtype=torch.float)
    >>> quantization_table_c = torch.randint(1, 256, size=(3, 8, 8), dtype=torch.float)
    >>> img_jpeg = jpeg_codec_differentiable(img, jpeg_quality, quantization_table_y, quantization_table_c)
    >>> img_jpeg.sum().backward()

    In case you want to control the quantization purly base on the quantization tables use a JPEG quality of 99.5.
    Setting the JPEG quality to 99.5 leads to a QT scaling of 1, see Eq. 2 of :cite:`reich2024` for details.

    >>> img = torch.rand(3, 3, 64, 64, requires_grad=True, dtype=torch.float)
    >>> jpeg_quality = torch.ones(3) * 99.5
    >>> quantization_table_y = torch.randint(1, 256, size=(3, 8, 8), dtype=torch.float)
    >>> quantization_table_c = torch.randint(1, 256, size=(3, 8, 8), dtype=torch.float)
    >>> img_jpeg = jpeg_codec_differentiable(img, jpeg_quality, quantization_table_y, quantization_table_c)
    >>> img_jpeg.sum().backward()

N)*3rp   rq   ro   rg   r   r   )ro   8r   g        r   z?JPEG quality is out of range. Expected range is [0, 100], got [z, z"]. Consider clipping jpeg_quality.r   rf   z#Batch dimensions do not match. Got z images and z quantization tables (Y).z quantization tables (C).z JPEG qualities.)r   r   r   r   )r   r   r   r   rp   rq   r   r   r   )r   r$   r%   .)r
   r[   rZ   r^   rc   r   ndimr   r	   aminitemamaxr   rk   tor   r   r(   )r   r   r   r   r[   rZ   r   r   rp   rq   r   r   r   image_rgb_jpegs                 r   r   r     sQ   b 9%<(&/ooE-6-=-=F?S?[,V;au?S?[,V;au/0/0y"67|cU+  A%3==!=D  A%3==!=D+_=+_=					!	!	#s	*U1B1B1D1I1I1Ku1T!!#((*+2l.?.?.A.F.F.H-IIk	m /y9Ie??23DA!!!$) &&q)Y__Q-????1%&l3G3M3Ma3P2QQjl	

 !!!$) &&q)Y__Q-????1%&l3G3M3Ma3P2QQjl	

 !!q!Y__Q%77??1%&l<3E3Ea3H2IIY[	
  ??61L/226A/226A(4!11	)%I: $0!

11	$N .NCY^_N#C19k	k$ABNr   c                z   X4nU[         ;  a  [        R                  " SXS9nSU-  S-   S S 2S 4   US S S 24   -  [        S-  -  n[        R                  " U5      nUS S 2S S S 2S 4   US S S 2S S S 24   -  n[        R
                  " SXS9nSUS'   [        R                  " Xw5      S-  nXh4[         U'   [         U   $ )	Nre   r   r   r    r   r   r   r   )r   r"   r   r   r   r   r   )	r[   rZ   keyifreqbasis_1dr{   r   r|   s	            r   ry   ry   }  s     /C
+LL%7a#q$w'!D!G*4T	B99T?aq$./(4D!;K2LL


1E9!aKK-4	&2Csr   c                  X   ^  \ rS rSrSr  S     SU 4S jjjr      SS jrSrU =r$ )	r   i  a  Differentiable JPEG encoding-decoding module.

Based on :cite:`reich2024` :cite:`shin2017`, we perform differentiable JPEG encoding-decoding as follows:

.. math::

    \text{JPEG}_{\text{diff}}(I, q, QT_{y}, QT_{c}) = \hat{I}

Where:
   - :math:`I` is the original image to be coded.
   - :math:`q` is the JPEG quality controlling the compression strength.
   - :math:`QT_{y}` is the luma quantization table.
   - :math:`QT_{c}` is the chroma quantization table.
   - :math:`\hat{I}` is the resulting JPEG encoded-decoded image.

.. image:: _static/img/jpeg_codec_differentiable.png

.. note::
    The input (and output) pixel range is :math:`[0, 1]`. In case you want to handle normalized images you are
    required to first perform denormalization followed by normalizing the output images again.

    Note, that this implementation models the encoding-decoding mapping of JPEG in a differentiable setting,
    however, does not allow the excess of the JPEG-coded byte file itself.
    For more details please refer to :cite:`reich2024`.

    This implementation is not meant for data loading. For loading JPEG images please refer to `kornia.io`.
    There we provide an optimized Rust implementation for fast JPEG loading.

Args:
    quantization_table_y: quantization table for Y channel. Default: `None`, which will load the standard
      quantization table.
    quantization_table_c: quantization table for C channels. Default: `None`, which will load the standard
      quantization table.

Shape:
    - quantization_table_y: :math:`(8, 8)` or :math:`(B, 8, 8)` (if used batch dim. needs to match w/ image_rgb).
    - quantization_table_c: :math:`(8, 8)` or :math:`(B, 8, 8)` (if used batch dim. needs to match w/ image_rgb).
    - image_rgb: :math:`(*, 3, H, W)`.
    - jpeg_quality: :math:`(1)` or :math:`(B)` (if used batch dim. needs to match w/ image_rgb).

Example:
    You can use the differentiable JPEG module with standard quantization tables by

    >>> diff_jpeg_module = JPEGCodecDifferentiable()
    >>> img = torch.rand(2, 3, 32, 32, requires_grad=True, dtype=torch.float)
    >>> jpeg_quality = torch.tensor((99.0, 1.0), requires_grad=True)
    >>> img_jpeg = diff_jpeg_module(img, jpeg_quality)
    >>> img_jpeg.sum().backward()

    You can also specify custom quantization tables to be used by

    >>> quantization_table_y = torch.randint(1, 256, size=(2, 8, 8), dtype=torch.float)
    >>> quantization_table_c = torch.randint(1, 256, size=(2, 8, 8), dtype=torch.float)
    >>> diff_jpeg_module = JPEGCodecDifferentiable(quantization_table_y, quantization_table_c)
    >>> img = torch.rand(2, 3, 32, 32, requires_grad=True, dtype=torch.float)
    >>> jpeg_quality = torch.tensor((99.0, 1.0), requires_grad=True)
    >>> img_jpeg = diff_jpeg_module(img, jpeg_quality)
    >>> img_jpeg.sum().backward()

    In case you want to learn the quantization tables just pass parameters `nn.Parameter`

    >>> quantization_table_y = torch.nn.Parameter(torch.randint(1, 256, size=(2, 8, 8), dtype=torch.float))
    >>> quantization_table_c = torch.nn.Parameter(torch.randint(1, 256, size=(2, 8, 8), dtype=torch.float))
    >>> diff_jpeg_module = JPEGCodecDifferentiable(quantization_table_y, quantization_table_c)
    >>> img = torch.rand(2, 3, 32, 32, requires_grad=True, dtype=torch.float)
    >>> jpeg_quality = torch.tensor((99.0, 1.0), requires_grad=True)
    >>> img_jpeg = diff_jpeg_module(img, jpeg_quality)
    >>> img_jpeg.sum().backward()

c                v  > [         TU ]  5         Uc  [        S S 5      OUnUc  [        S S 5      OUn[	        U[
        R                  5      (       a  U R                  SU5        OU R                  SU5        [	        U[
        R                  5      (       a  U R                  SU5        g U R                  SU5        g )Nr   r   )	super__init__r^   rc   
isinstancer   	Parameterregister_parameterregister_buffer)selfr   r   	__class__s      r   r    JPEGCodecDifferentiable.__init__  s    
 	@T@\0t<bv@T@\0t<bv*BLL99##$:<PQ  !79MN*BLL99##$:<PQ  !79MNr   c                    UR                   nUR                  nU R                  R                  X45      nU R                  R                  X45      n[        UUUUS9nU$ )N)r   r   r   )rZ   r[   r   r   r   r   )r   r   r   rZ   r[   r   r   r   s           r   forwardJPEGCodecDifferentiable.forward  sf    
 !!  $88;;FJ#88;;FJ'@%!5!5	(
 r    rw   )r   "torch.Tensor | nn.Parameter | Noner   r   returnNone)r   torch.Tensorr   r   r   r   )	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classcell__)r   s   @r   r   r     sf    ER DHCGO@O AO 
	O O$ # 
	 r   )r   r   r   r   )NNg{Gz?)
r   r   r$   Union[float, None]r%   r  r&   floatr   r   )rZ   Union[str, torch.device, None]r[   Union[torch.dtype, None]r   r   )r   r   rp   intrq   r  r   r   )r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   /tuple[torch.Tensor, torch.Tensor, torch.Tensor])r   r   r   r   )
r   r   r   r   r   r   r   r   r   r	  )r   r   r   r   r   r   r   r   rp   r  rq   r  r   r   r   r   r   r   )r   r   r   ztuple[torch.Tensor, int, int]rw   )
r   r   r   r   r   torch.Tensor | Noner   r
  r   r   )r[   r  rZ   r  r   z!tuple[torch.Tensor, torch.Tensor])/
__future__r   r   typingr   r"   torch.nn.functionalr   
functionalr   kornia.colorr   r   kornia.constantsr   kornia.core.checkr	   r
   r   !kornia.geometry.transform.affwarpr   kornia.image.utilsr   r   __annotations____all__r   r   r(   r^   rc   rr   ru   r}   r   r   r   r   r   r   r   r   r   r   ry   Moduler   r   r   r   <module>r     sC  $ #       3  
 6 7     %&A
B4:  #'"&	   	
 4$$"&&<&. % 	< % 	66D*,-,-,- ',- '	,-
 5,-^333 3 	3
 3 3 '3 '3 3l&,  1504	\\\ .\ .	\
 \ \~#-K& lbii lr   