+
    åûjº¬  ã                  óÂ  € R t ^ RIHt ^ RIt^ RIt^ RIt^ RIHt ^ RIt^ RI	H
u Ht ^ RIH
t
 ^ RIHtHt ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHtHt . R&OtRtR R lt ! R R
]
P:                  4      t ! R R]
P:                  4      tR R lt  ! R R]
P:                  4      t!R'R R llt"R(R R llt#R(R R llt$R R lt%R R lt&R R  lt'R! R" lt(R(R#R/R$ R% lllt)R# ))a«  Build Gaussian, Laplacian and scale-space pyramids, and blur and resize by one level.

:func:`pyrdown` and :func:`pyrup`, and the pyramids built from them, take channels-first images ``(B, C, H, W)``,
blur with the 5x5 binomial kernel (the outer product of ``[1, 4, 6, 4, 1] / 16`` with itself) and resize bilinearly:
``pyrdown`` blurs and then resizes to ``floor(side / factor)``, and ``pyrup`` resizes to twice the size and then
blurs. They default to ``align_corners=False`` and pad the blur by ``border_type``, ``'reflect'`` by default, under
which reflection extends across short axes. :class:`ScalePyramid` blurs with Gaussians of its own sigmas
and resizes with ``align_corners=True``.

Which function to use:

- One level down or up: :func:`pyrdown` or :class:`PyrDown`, :func:`pyrup` or :class:`PyrUp`.
- A list of Gaussian levels, each half the size of the previous: :func:`build_pyramid`. Band-pass levels that
  :func:`pyrup` and addition rebuild the image from: :func:`build_laplacian_pyramid`.
- Octaves of progressively blurred levels with their sigmas, for scale-space keypoint detection:
  :class:`ScalePyramid`.
- The integer helpers that :func:`build_laplacian_pyramid` pads with: :func:`is_powerof_two` and
  :func:`find_next_powerof_two`.
- To keep every second pixel of a blurred feature map in a network, use :func:`~kornia.filters.blur_pool2d`; to
  change the size without blurring, :func:`~kornia.geometry.transform.resize`.
)ÚannotationsN)ÚAny)Únn)ÚKORNIA_CHECKÚKORNIA_CHECK_SHAPE)ÚValueCheckError)Úis_compiling)Úfilter2dÚgaussian_blur2d)Ú_gaussian_blur2d_cpuÚ_gaussian_blur2d_cpu_eligibleÚPyrDownÚPyrUpÚScalePyramidaÎ  `build_laplacian_pyramid` pads this input to the next power of two per side, more than `max_level` needs. This is deprecated since kornia 0.9.1: a future minor release pads a side only when it does not divide by `2 ** (max_level - 1)`, to the next multiple of that, which changes the shape of every returned level for this input. `minimal_padding=True` gives that behavior now, and `minimal_padding=False` keeps the current rule without this warning until then; after the change it keeps it for one more minor release, with a deprecation warning. An image rebuilt from the levels and cropped to the input size stays the same up to float rounding, but the values of each level change, even after cropping (kornia#6319).c               ó   € V ^8„  d   QhRR/# )é   Úreturnútorch.Tensor© )Úformats   "Ú]C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\transform\pyramid.pyÚ__annotate__r   P   s   € ÷ ñ  lñ ó    c                 ó\   € \         P                  ! . RO. RO. RO. RO. RO..4      R,          # )z&Return a pre-computed gaussian kernel.g      p@)ç      ð?ç      @ç      @r   r   )r   ç      0@ç      8@r   r   )r   r   g      B@r   r   )ÚtorchÚtensorr   r   r   Ú_get_pyramid_gaussian_kernelr!   P   s:   € ô 	�Šò .Ú0Ú0Ú0Ú-ððó
	
ð õ	ðr   c                  óB   a € ] tR t^btRtRR V 3R llltR R ltRtV ;t# )r   a^  Blur images with the 5x5 pyramid kernel and downsample them by a factor (module form).

Build ``down = PyrDown()``, optionally with ``border_type``, ``align_corners`` and ``factor``, then
``out = down(input)`` blurs ``(B, C, H, W)`` images and resizes them to ``floor(H / factor)`` by
``floor(W / factor)``, as :func:`pyrdown` does. For the step up, use :class:`PyrUp`; for every level at once,
:func:`build_pyramid`.

Convention:
    - See the convention block of :func:`~kornia.geometry.transform.pyrdown`.

Args:
    border_type: the padding mode to be applied before convolving.
      The expected modes are: ``'constant'``, ``'reflect'``,
      ``'replicate'`` or ``'circular'``.
    align_corners: interpolation flag.
    factor: the downsampling factor

Return:
    the downsampled torch.Tensor.

Shape:
    - Input: ``(B, C, H, W)``
    - Output: ``(B, C, H // 2, W // 2)`` at the default ``factor=2.0``

See Also:
    - :func:`pyrdown`: the one-call form.
    - :class:`PyrUp`: the module that goes one level up.

Examples:
    >>> input = torch.rand(1, 2, 4, 4)
    >>> output = PyrDown()(input)  # 1x2x2x2

c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   Úborder_typeÚstrÚalign_cornersÚboolÚfactorÚfloatr   ÚNoner   )r   s   "r   r   ÚPyrDown.__annotate__…   s*   € ÷ $ñ $ Cð $ÀDð $ÐZ_ð $Ðjnñ $r   c                	óH   <€ \         SV `  4        Wn        W n        W0n        R # ©N)ÚsuperÚ__init__r$   r&   r(   )Úselfr$   r&   r(   Ú	__class__s   &&&&€r   r/   ÚPyrDown.__init__…   s   ø€ Ü‰ÑÔØ +ÔØ#0ÔØ#Žr   c               ó    € V ^8„  d   QhRRRR/# ©r   Úinputr   r   r   )r   s   "r   r   r+   ‹   s   € ÷ Qñ Q˜\ð Q¨lñ Qr   c                óX   € \        WP                  V P                  V P                  4      # )aH  Build the next lower-resolution Gaussian pyramid level.

The input is smoothed before resizing so high-frequency content is not
directly subsampled. This is the standard pyramid-down step used by
many multi-scale image algorithms.

Args:
    input: Image tensor with shape ``(B, C, H, W)``, where
        :math:`B` is batch size, :math:`C` is channels, :math:`H` is
        height, and :math:`W` is width.

Returns:
    Downsampled tensor from :func:`pyrdown`. The channel and batch
    dimensions are preserved, while spatial dimensions are reduced
    according to ``self.factor``.
)Úpyrdownr$   r&   r(   ©r0   r5   s   &&r   ÚforwardÚPyrDown.forward‹   s#   € ô" �u×.Ñ.°×0BÑ0BÀDÇKÁKÓPÐPr   )r&   r$   r(   ©ÚreflectFç       @©	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r/   r9   Ú__static_attributes__Ú__classcell__©r1   s   @r   r   r   b   s   ø† ñ ÷D$ò $÷Qó Qr   c                  óB   a € ] tR t^ŸtRtRR V 3R llltR R ltRtV ;t# )r   aÆ  Upsample images to twice their size and blur them with the 5x5 pyramid kernel (module form).

Build ``up = PyrUp()``, optionally with ``border_type`` and ``align_corners``, then ``out = up(input)`` resizes
``(B, C, H, W)`` images to ``(B, C, H * 2, W * 2)`` and blurs them, as :func:`pyrup` does. For the step down, use
:class:`PyrDown`.

Convention:
    - See the convention block of :func:`~kornia.geometry.transform.pyrup`.

Args:
    border_type: the padding mode to be applied before convolving.
      The expected modes are: ``'constant'``, ``'reflect'``,
      ``'replicate'`` or ``'circular'``.
    align_corners: interpolation flag.

Return:
    the upsampled torch.Tensor.

Shape:
    - Input: ``(B, C, H, W)``
    - Output: ``(B, C, H * 2, W * 2)``

See Also:
    - :func:`pyrup`: the one-call form.
    - :class:`PyrDown`: the module that goes one level down.

Examples:
    >>> input = torch.rand(1, 2, 4, 4)
    >>> output = PyrUp()(input)  # 1x2x8x8

c               ó$   € V ^8„  d   QhRRRRRR/# )r   r$   r%   r&   r'   r   r*   r   )r   s   "r   r   ÚPyrUp.__annotate__À   s"   € ÷ 1ñ 1 Cð 1ÀDð 1ÐUYñ 1r   c                	ó<   <€ \         SV `  4        Wn        W n        R # r-   )r.   r/   r$   r&   )r0   r$   r&   r1   s   &&&€r   r/   ÚPyrUp.__init__À   s   ø€ Ü‰ÑÔØ +ÔØ#0Ör   c               ó    € V ^8„  d   QhRRRR/# r4   r   )r   s   "r   r   rI   Å   s   € ÷ Bñ B˜\ð B¨lñ Br   c                óB   € \        WP                  V P                  4      # )a  Build the next higher-resolution Gaussian pyramid level.

The operation upsamples the image and applies pyramid smoothing so the
enlarged result is spatially consistent with Gaussian pyramid
reconstruction.

Args:
    input: Image tensor with shape ``(B, C, H, W)``, where
        :math:`B` is batch size, :math:`C` is channels, :math:`H` is
        height, and :math:`W` is width.

Returns:
    Upsampled tensor from :func:`pyrup`, typically with doubled height
    and width, preserving batch and channel dimensions.
)Úpyrupr$   r&   r8   s   &&r   r9   ÚPyrUp.forwardÅ   s   € ô  �U×,Ñ,¨d×.@Ñ.@ÓAÐAr   )r&   r$   ©r<   Fr>   rF   s   @r   r   r   Ÿ   s   ø† ñ÷@1ò 1÷
Bó Br   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Únamer%   Úvaluer   r   Úintr   )r   s   "r   r   r   Ø   s!   € ÷ ñ ˜ð  Cð ¨Cñ r   c                óJ  € \        VRR4      p\        V\        4      ;'       g+    V\        P                  J ;'       g    \        VRR4      R8H  pRpV'       g    \        P
                  ! V4      pVe   V^8  d   \        RV  RV: 2VR7      hV#   \         d    Rp L0i ; i)aÐ  Return ``value`` as a positive ``int``, or raise :class:`~kornia.core.exceptions.ValueCheckError`.

``_positive_int(name, value)`` converts a positive integer-like value to ``int`` through ``operator.index``.
Python and NumPy integers, 0-d integer arrays and integer tensors are accepted, as is anything else that
``operator.index`` converts to a positive integer; bools of every kind are rejected. ``name`` is the argument named
in the error. The error is raised directly instead of through ``KORNIA_CHECK``: :class:`ScalePyramid` cannot build
an octave from ``n_levels < 1`` or seed the next one from ``extra_levels < 1``, so the guard must also hold under
``python -O``, ``KORNIA_CHECKS=0`` and ``disable_checks()``.
ÚdtypeNÚkindÚbzInvalid z&, it must be a positive integer. Got: ©Úactual_value)ÚgetattrÚ
isinstancer'   r   ÚoperatorÚindexÚ	TypeErrorr   )rR   rS   rV   Úis_boolr^   s   &&   r   Ú_positive_intra   Ø   s¨   € ô �E˜7 DÓ)€Eä˜¤Ó%×cÐc¨´%·*±*Ð)<×cÐcÄÈÈvÐW[Ó@\Ð`cÑ@c€GØ€Eßð	Ü—N’N 5Ó)ˆEð ‚}˜ œ	Ü ¨¨Ð.TÐUZÑT]Ð^ÐmrÔsÐsØ€Løô	 ô 	ØŠEð	ús   ÁB ÂB"Â!B"c                  ó”   a € ] tR t^ðtRtRR V 3R llltR R lt]R R l4       tR R	 lt	R
 R lt
R R ltR R ltR R ltRtV ;t# )r   a…  Build octaves of progressively blurred images, with their sigmas, for scale-space detection.

Build ``sp = ScalePyramid(n_levels, init_sigma, min_size)``, then ``pyr, sigmas, pixel_dists = sp(input)`` takes
``(B, C, H, W)`` images and returns three lists with one entry per octave. ``pyr[o]`` stacks
``L = n_levels + extra_levels`` levels as ``(B, C, L, H_o, W_o)``, each blurred ``2 ** (1 / n_levels)`` times more
than the previous, and ``sigmas[o]`` and ``pixel_dists[o]`` are ``(B, L)``. Each octave after the
first starts from level ``n_levels`` of the previous one, resized to half its size, and
octaves are added while that halved size stays above ``min_size`` on its shorter side. It is the pyramid
:class:`~kornia.feature.ScaleSpaceDetector` searches; for a plain list of halved images, use :func:`build_pyramid`.

Convention:
    - input: ``(B, C, H, W)``
    - ``forward`` returns ``(pyr, sigmas, pixel_dists)``, one entry per octave: ``pyr[o]`` is
      ``(B, C, L, H_o, W_o)`` with ``L = n_levels + extra_levels``, and ``sigmas[o]`` and
      ``pixel_dists[o]`` are ``(B, L)`` nominal values (the targeted blur, not a measurement)
    - ``sigmas`` is octave-relative: the blur in input pixels is ``sigmas[o] * pixel_dists[o]``
    - an ``init_sigma`` below the assumed input blur (``0.5``, or ``1.0`` with
      ``double_image=True``) leaves the first level at that blur, and the octave is built and
      labelled from it, as if ``init_sigma`` were the assumed input blur
    - the internal resizes use ``align_corners=True``; there is no ``align_corners`` parameter. They keep the
      first and last pixel centres, so pixel :math:`(u, v)` of octave ``o`` is input pixel
      :math:`(u (W - 1) / (W_o - 1), v (H - 1) / (H_o - 1))`; ``pixel_dists`` is the nominal spacing
      :math:`2^o` (:math:`2^{o - 1}` with ``double_image=True``), not this map

Args:
    n_levels: number of levels per octave over which the blur doubles, a positive integer (a NumPy integer or
      integer tensor is converted to ``int``). Each level is blurred ``2 ** (1 / n_levels)`` times more than
      the one before.
    init_sigma: initial blur level.
    min_size: the minimum size of the octave in pixels, a non-negative number: an octave after the first is built
      only when its shorter side is larger than ``min_size``, so ``0`` halves the image down to one pixel.
    double_image: add 2x upscaled image as 1st level of pyramid. OpenCV SIFT does this.
    extra_levels: number of levels per octave beyond ``n_levels``, a positive integer (a NumPy integer or
      integer tensor is converted to ``int``); the default 3 is what DoG non-maximum suppression needs. Level
      ``n_levels``, blurred to twice the first level's sigma, seeds the next octave, so ``1`` is the least
      that works.

Returns:
    1st output: images, the levels of each octave.
    2nd output: sigmas, the nominal blur of each level in the octave's own pixels.
    3rd output: pixel_dists, the nominal pixel spacing of each level relative to the input.

Raises:
    ValueCheckError: if ``n_levels`` or ``extra_levels`` is not a positive integer, or ``min_size`` is negative
        or NaN. Raised even when the ``KORNIA_CHECK`` helpers are disabled, because ``forward`` could not build
        the pyramid.

Shape:
    - Input: ``(B, C, H, W)``
    - Output 1st: ``[(B, C, L, H, W), (B, C, L, H // 2, W // 2), ...]``, starting from ``(B, C, L, H * 2, W * 2)``
      with ``double_image=True``
    - Output 2nd: ``[(B, L), (B, L), (B, L), ...]``
    - Output 3rd: ``[(B, L), (B, L), (B, L), ...]``

See Also:
    - :func:`build_pyramid`: a list of halved images, one blur per level, without sigmas.
    - :func:`build_laplacian_pyramid`: band-pass levels for reconstruction rather than detection.
    - :class:`~kornia.feature.ScaleSpaceDetector`: detects keypoints in this pyramid.

Examples:
    >>> input = torch.rand(2, 4, 100, 100)
    >>> sp, sigmas, pds = ScalePyramid(3, 15)(input)

c               ó0   € V ^8„  d   QhRRRRRRRRRRR	R
/# )r   Ún_levelsrT   Ú
init_sigmar)   Úmin_sizeÚdouble_imager'   Úextra_levelsr   r*   r   )r   s   "r   r   ÚScalePyramid.__annotate__2  sN   € ÷ Yñ YàðYð ðYð ð	Yð
 ðYð ðYð 
ñYr   c                	ó’  <€ \         SV `  4        \        R V4      p\        RV4      pV^ 8¼  g   \        RV: 2VR7      hWn        WPn        W n        W0n        V^,          ^,
          V n        ^R\        V P                  4      ,          ,          V n
        W@n        \        Y$'       d   RMR4      V n        V P                  WW$4       R# )rd   rh   z9Invalid min_size, it must be a non-negative number. Got: rY   r   ç      à?N)r.   r/   ra   r   rd   rh   re   rf   Úborderr)   Ú
sigma_steprg   ÚmaxÚ_base_sigmaÚ_precompute_gauss_kernels)r0   rd   re   rf   rg   rh   r1   s   &&&&&&€r   r/   ÚScalePyramid.__init__2  s·   ø€ ô 	‰ÑÔÜ  ¨XÓ6ˆÜ$ ^°\ÓBˆð ˜A”Ü!ØKÈHÉ<ÐXÐgoôð ð !ŒØ(ÔØ$ŒØ ŒØ !•m aÕ'ˆŒØ ¤e¨D¯M©MÓ&:Õ :Õ;ˆŒØ(Ôô ˜z¶,©3ÀCÓHˆÔØ×&Ñ& x¸zÖXr   c               ó   € V ^8„  d   QhRR/# )r   r   r%   r   )r   s   "r   r   ri   P  s   € ÷ 

ñ 

˜#ñ 

r   c                	óê   € V P                   P                   R V P                   RV P                   RV P                   RV P
                   RV P                   RV P                   RV P                   R2# )z
(n_levels=z, init_sigma=z, min_size=z, extra_levels=z	, border=z, sigma_step=z, double_image=Ú))	r1   r?   rd   re   rf   rh   rl   rm   rg   )r0   s   &r   Ú__repr__ÚScalePyramid.__repr__P  sˆ   € à�~‰~×&Ñ&Ð'ð (ØŸ™�ð 'ØŸ/™/Ð*ð +ØŸ™�ð 'Ø ×-Ñ-Ð.ð /Ø—k‘k�]ð #ØŸ/™/Ð*ð +Ø ×-Ñ-Ð.¨að1ð		
r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úsigmar)   ÚksizerT   r   r   r   )r   s   "r   r   ri   ]  s&   € ÷ ^ñ ^ uð ^°Sð ^¸\ñ ^r   c                ó’  € \         P                  ! VR\         P                  R7      V^,          ,
          p\         P                  ! RV^,          ,          V ^,          ,          4      pW3P	                  4       ,          P                  4       P                  \         P                  ! ^ \         P                  R7      P                  4      # )z2Normalized 1D Gaussian kernel as a float32 tensor.Úcpu©ÚdevicerV   ©rV   g      à¿)
r   ÚarangeÚfloat64ÚexpÚsumr)   ÚtoÚemptyÚfloat32r}   )rx   ry   ÚxÚkernels   &&  r   Ú_make_gaussian_kernel1dÚ$ScalePyramid._make_gaussian_kernel1d\  sz   € ô �LŠL˜ u´E·M±MÔBÀUÈaÅZÕOˆÜ—’˜4 ! Q¥$�;¨°­Õ1Ó2ˆØŸ™›Õ%×,Ñ,Ó.×1Ñ1´%·+²+¸aÄuÇ}Á}Ô2U×2\Ñ2\Ó]Ð]r   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r   rd   rT   rh   re   r)   rg   r'   r   r*   r   )r   s   "r   r   ri   d  s4   € ÷ %ñ %Øð%Ø+.ð%Ø<Að%ØQUð%à	ñ%r   c                ól  € V'       d   RMRpW58”  di   \        \        P                  ! V^,          V^,          ,
          4      R4      pV P                  V4      pV P	                  RV P                  Wg4      4       MV P	                  RR4       V P                  p\        W,           ^,
          4       F  p	V\        P                  ! V P                  ^,          R,
          4      ,          p
V P                  V
4      pV P	                  RV	 2V P                  W§4      4       W€P                  ,          pK�  	  R# )zLRegister precomputed 1D Gaussian kernels as buffers so they move with .to().r   rk   ç{®Gáz„?Ú_gk_initNÚ_gk_)	rn   ÚmathÚsqrtÚget_kernel_sizeÚregister_bufferrˆ   ro   Úrangerm   )r0   rd   rh   re   rg   Úcur_sigma_initrx   ry   Úcur_sÚlvlÚdeltas   &&&&&      r   rp   Ú&ScalePyramid._precompute_gauss_kernelsd  só   € ÷
 !-™°#ˆØÔ&ÜœŸ	š	 *¨a¥-°.À!Õ2CÕ"CÓDÀdÓKˆEØ×(Ñ(¨Ó/ˆEØ× Ñ  ¨T×-IÑ-IÈ%Ó-WÕXà× Ñ  ¨TÔ2ð
 × Ñ ˆÜ˜Õ0°1Õ4Ö5ˆCØœDŸIšI d§o¡o°qÕ&8¸3Õ&>Ó?Õ?ˆEØ×(Ñ(¨Ó/ˆEØ× Ñ  4¨ u ¨t×/KÑ/KÈEÓ/YÔZØ—_‘_Õ$ŠEó	 6r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r†   r   r‡   r   r   )r   s   "r   r   ri   {  s&   € ÷ Uñ U˜Lð U°,ð UÀ<ñ Ur   c           	     ó  € VP                   ^ ,          pV^,          pVP                   w  rVrxVP                  VP                  VP                  R7      p	\	        V4      '       d[   \
        P                  ! 4       '       d   V	P                  '       g.   \        WP                  ^R4      V	P                  ^R4      R4      # V	P                  ^^^V4      P                  V^^V4      P                  4       p
\        P                  ! \        P                  ! WV^ ^ 3RR7      W¦R7      pV	P                  ^^V^4      P                  V^V^4      P                  4       p\        P                  ! \        P                  ! V^ ^ WD3RR7      WÆR7      # )uP   Separable Gaussian blur with a precomputed 1D kernel â€” no validation overhead.r|   r<   )Úmode)Úgroupséÿÿÿÿ)Úshaperƒ   r}   rV   r   r   Úis_grad_enabledÚrequires_gradr   ÚviewÚexpandÚ
contiguousÚFÚconv2dÚpad)r0   r†   r‡   ry   r¦   Ú_BÚCÚ_HÚ_WÚkÚk_hÚtmpÚk_vs   &&&          r   Ú
_blur_fastÚScalePyramid._blur_fast{  s,  € à—‘˜Q•ˆØ�q�jˆØŸ™‰ˆˆrØ�I‰I˜QŸX™X¨Q¯W©WˆIÓ5ˆÜ(¨×+Ò+´U×5JÒ5J×5LÒ5LÐQR×Q`×Q`ÐQ`Ü'¨¯6©6°!°R«=¸!¿&¹&ÀÀB»-ÈÓSÐSà�f‰f�Q˜˜1˜eÓ$×+Ñ+¨A¨q°!°UÓ;×FÑFÓHˆÜ�hŠh”q—u’u˜Q c¨1¨aÐ 0°yÔAÀ3ÔQˆØ�f‰f�Q˜˜5 !Ó$×+Ñ+¨A¨q°%¸Ó;×FÑFÓHˆÜ�xŠxœŸš˜c A q¨#Ð#3¸)ÔDÀcÔTÐTr   c               ó    € V ^8„  d   QhRRRR/# )r   rx   r)   r   rT   r   )r   s   "r   r   ri   ‰  s   € ÷ ñ  Uð ¨sñ r   c                óf   € \        RV,          R,           4      pV^,          ^ 8X  d
   V^,          pV# )zþChoose an odd Gaussian kernel size for a given blur sigma.

Args:
    sigma: Gaussian standard deviation measured in pixels.

Returns:
    Odd integer kernel size large enough to cover the effective support
    used by this scale-pyramid implementation.
r   g       @)rT   )r0   rx   ry   s   && r   r‘   ÚScalePyramid.get_kernel_size‰  s3   € ô �I Õ%¨Õ+Ó,ˆð �1�9˜Œ>Ø�Q�JˆEØˆr   c               ó    € V ^8„  d   QhRRRR/# )r   r5   r   r   z!tuple[torch.Tensor, float, float]r   )r   s   "r   r   ri   �  s   € ÷ '4ñ '4 \ð '4Ð6Wñ '4r   c                ó|  € RpRpV P                   '       d'   \        P                  ! VRRRR7      pRpVR,          pMTpV P                  V8”  dé   \	        \
        P                  ! V P                  ^,          V^,          ,
          4      R4      pV P                  V4      p\        VP                  ^4      VP                  ^4      4      pV P                  e#   Wg8:  d   V P                  W@P                  4      pM1\        Yg^,          ^8X  d   TMV^,
          4      p\        WFV3WU34      pV P                  pMTpWƒV3# )a©  Create the first image level and its scale metadata.

The method optionally doubles image resolution, then applies initial
Gaussian blur so the first level reaches ``self.init_sigma``. An
``init_sigma`` below the assumed input blur leaves the level unblurred.

Args:
    input: Image tensor with shape ``(B, C, H, W)``.

Returns:
    Tuple ``(cur_level, cur_sigma, pixel_distance)``. ``cur_level`` is
    the first image level, ``cur_sigma`` is its effective blur sigma,
    and ``pixel_distance`` is the level's nominal pixel spacing in input
    pixels (``0.5`` when doubled). It is not the coordinate map: see the
    class Convention for where a level pixel lies in the input.
r   rk   r=   ÚbilinearT)Úscale_factorr›   r&   rŒ   )rg   r¤   Úinterpolatere   rn   r�   r�   r‘   ÚminÚsizer�   r¯   r
   )	r0   r5   Úpixel_distanceÚ	cur_sigmar†   rx   ry   Úmin_dimÚ	cur_levels	   &&       r   Úget_first_levelÚScalePyramid.get_first_level�  s	  € ð" ˆØˆ	à××ÐÜ—’˜e°#¸JÐVZÔ[ˆAØ ˆNØ˜Õ‰IàˆAà�?‰?˜YÔ&ÜœŸ	š	 $§/¡/°1Õ"4°yÀ!µ|Õ"CÓDÀdÓKˆEØ×(Ñ(¨Ó/ˆEÜ˜!Ÿ&™& ›) Q§V¡V¨A£YÓ/ˆGØ�}‰}Ò(¨UÔ-=Ø ŸO™O¨A¯}©}Ó=‘	ä˜E¸­k¸QÔ.>¡7ÀGÈaÅKÓP�Ü+¨A°u¨~À¸~ÓN�	ØŸ™‰IàˆIØ ^Ð3Ð3r   c               ó    € V ^8„  d   QhRRRR/# )r   r†   r   r   zAtuple[list[torch.Tensor], list[torch.Tensor], list[torch.Tensor]]r   )r   s   "r   r   ri   Æ  s   € ÷ F/ñ F/˜ð F/Ð*kñ F/r   c           	     óÊ  € VP                  4       w  p  pV P                  V4      w  rEp\        P                  ! W P                  V P
                  ,           3WQP                  VP                  R7      .p\        P                  ! W P                  V P
                  ,           3WaP                  VP                  R7      .pV..p	 V P                  p
\        ^V P                  V P
                  ,           4       EFI  p\        V RV^,
           24      p\        V	R	,          R	,          P                  ^4      V	R	,          R	,          P                  ^4      4      pVP                  ^ ,          V8:  d"   V P                  V	R	,          R	,          V4      pMlV
\        P                  ! V P                   ^,          R,
          4      ,          pV^,          ^8X  d   TMV^,
          p\#        V	R	,          R	,          VV3Wÿ34      pW P                   ,          p
V	R	,          P%                  V4       W§R	,          RV3&   WhR	,          RV3&   EKL  	  V	R	,          V P                  ,          pVP                  ^,          VP                  ^,          pp\        V^,          V^,          4      V P&                  8:  d   EMV^,          V^,          pp\(        P*                  ! VVV3RRR7      pVR,          pV	P%                  V.4       VP%                  \        P                  ! W P                  V P
                  ,           3V P                  VP                  VP                  R7      4       VP%                  \        P                  ! W P                  V P
                  ,           3WaP                  VP                  R7      4       EKô  V	 Uu. uF  p\        P,                  ! V^4      NK  	  ppVWx3# u upi )
a¦  Construct a Gaussian scale pyramid over several octaves.

Each octave stores multiple progressively blurred versions of the same
image resolution. The next octave starts from a downsampled image, so
feature detectors can search both spatial location and scale.

Args:
    x: Input image tensor with shape ``(B, C, H, W)``, where
        :math:`B` is batch size, :math:`C` is channels, :math:`H` is
        height, and :math:`W` is width.

Returns:
    Three lists with one entry per octave. ``pyr`` contains stacked
    image levels, ``sigmas`` contains the octave-relative nominal blur
    sigma for each level (multiply by the matching ``pixel_dists``
    entry for the nominal absolute blur in original-image pixels), and
    ``pixel_dists`` contains the nominal pixel spacing of each level
    relative to the original image. It is not the coordinate map: see
    the class Convention for where an octave pixel lies in the input.
r|   TrŽ   r   :NNNr¶   ©rº   r›   r&   r=   r�   )rº   r¿   r   Úfullrd   rh   r}   rV   ro   r“   r[   r¹   rž   r¯   r�   r�   rm   r
   Úappendrf   r¤   r¸   Ústack)r0   r†   ÚbsÚ_r¾   r¼   r»   ÚsigmasÚpixel_distsÚpyrÚcur_sigma_octÚ	level_idxr‡   r½   Ú	new_levelÚdelta_sigmary   Ú_pyrÚHÚWÚH_newÚW_newÚnextOctaveFirstLevelÚiÚ
output_pyrs   &&                       r   r9   ÚScalePyramid.forwardÆ  s  € ð* —f‘f“h‰ˆˆAˆq�!Ø/3×/CÑ/CÀAÓ/FÑ,ˆ	˜nä—*’*˜b§-¡-°$×2CÑ2CÕ"CÐDÀi×X`ÑX`Ðhi×hoÑhoÔpÐqˆä�JŠJ˜ŸM™M¨D×,=Ñ,=Õ=Ð>À×W_ÑW_Ðgh×gnÑgnÔoð
ˆð ˆ{ˆmˆàð !×,Ñ,ˆMÜ" 1 d§m¡m°d×6GÑ6GÕ&G×H�	Ü  ¨¨i¸!­m¨_Ð'=Ó>�Ü˜c "�g b�k×.Ñ.¨qÓ1°3°rµ7¸2µ;×3CÑ3CÀAÓ3FÓG�Ø—<‘< •? gÔ-Ø $§¡°°Bµ¸µ¸VÓ D‘Ið #0´$·)²)¸D¿O¹OÈQÕ<NÐQTÕ<TÓ2UÕ"U�KØ'.°¥{°aÔ'7™G¸WÀq½[�EÜ /°°Bµ¸µ¸eÀU¸^ÈkÐMgÓ h�IØ§¡Õ0�Ø�B•—‘˜yÔ)Ø+8�r•
˜1˜i˜<Ñ(Ø0>˜B•  9 Ô-ñ Ið& �r•7˜4Ÿ=™=Õ)ˆDØ—:‘:˜a•= $§*¡*¨Q¥-ˆqˆAÜ�1˜•6˜1 �6Ó" d§m¡mÔ3ÙØ �6 1¨¥6�5ˆEÜ#$§=¢=°¸UÀE¸NÐQ[ÐkoÔ#pÐ Ø˜cÕ!ˆNØ�J‰JÐ,Ð-Ô.Ø�M‰MÜ—
’
˜B§¡°×0AÑ0AÕ AÐBÀD×DTÑDTÐ]^×]eÑ]eÐmn×mtÑmtÔuôð ×ÑÜ—
’
˜B§¡°×0AÑ0AÕ AÐBÀN×[cÑ[cÐkl×krÑkrÔs÷ñ 25Ó5±¨A”e—k’k ! QÖ'±ˆ
Ð5Ø˜6Ð.Ð.ùò 6s   Î: O )ro   rl   rg   rh   re   rf   rd   rm   )é   gš™™™™™ù?é   FrÙ   )r?   r@   rA   rB   rC   r/   ru   Ústaticmethodrˆ   rp   r¯   r‘   r¿   r9   rD   rE   rF   s   @r   r   r   ð   sR   ø† ñ?÷BYò Yõ<

ð ô^ó ð^õ%õ.Uõõ('4÷RF/ó F/r   c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R/# )
r   r5   r   r$   r%   r&   r'   r(   r)   r   r   )r   s   "r   r   r     s;   € ÷ Eñ EØðEØ&)ðEØFJðEØ\aðEàñEr   c                ó`  € \        V . RO4       \        4       p\        WV4      pV P                  w   rgp\	        V\
        P                  4      '       dˆ   \
        P                  ! V.\
        P                  R7      p	Wx3 U
u. uFR  p
\
        P                  ! V
P                  ^4      P                  4       V	,          4      P                  4       ^ ,          NKT  	  pp
M¯\	        V\
        P                  4      '       dZ   \
        P                  P                  4       '       d6   Wx3 U
u. uF'  p
\
        P                   ! V
RV,          ,          4      NK)  	  pp
M6\#        \%        V4      V,          4      \#        \%        V4      V,          4      .p\&        P(                  ! W[RVR7      pV# u up
i u up
i )u¯  Blur images with the 5x5 pyramid kernel and downsample them by a factor, one pyramid level down.

``out = pyrdown(input)`` takes images ``(B, C, H, W)``, blurs them with the 5x5 binomial kernel and resizes them
bilinearly to ``(B, C, floor(H / factor), floor(W / factor))``, half the size at the default ``factor=2.0``. It
resamples bilinearly where OpenCV's ``pyrDown`` keeps every second pixel, and rounds an odd side down where OpenCV
rounds it up. For the step up, use :func:`pyrup`; for every level at once, :func:`build_pyramid`; to keep
every second pixel of a blurred map, :func:`~kornia.filters.blur_pool2d`.

.. image:: _static/img/pyrdown.png

Convention:
    - input: ``(B, C, H, W)``
    - output spatial size is ``floor(side / factor)`` per dimension
      (:math:`5 \times 5 \to 2 \times 2` at the default ``factor=2.0`` â€”
      note OpenCV's ``pyrDown`` rounds up instead)
    - Dynamo ONNX uses float32 reciprocal-scale arithmetic for dynamic sides, which can differ from eager by one
      pixel for some fractional factors (for example, side 33 and factor 1.1)
    - border_type: ``'reflect'`` by default (blur before downsample), including short positive axes; the resized
      output must still have at least one pixel along each axis
    - align_corners: ``False`` by default

Args:
    input: the torch.Tensor to be downsampled.
    border_type: the padding mode to be applied before convolving.
      The expected modes are: ``'constant'``, ``'reflect'``,
      ``'replicate'`` or ``'circular'``.
    align_corners: interpolation flag.
    factor: the downsampling factor

Return:
    the downsampled torch.Tensor.

See Also:
    - :class:`PyrDown`: the module form.
    - :func:`pyrup`: one level up, to twice the size.
    - :func:`build_pyramid`: the list of levels from repeated ``pyrdown`` calls.
    - :func:`~kornia.filters.blur_pool2d`: a zero-padded binomial blur sampled at a stride, from pixel 0;
      ``blur_pool2d(x, 5, 2)`` blurs with this kernel and returns ``ceil(H / 2)`` rows.

Examples:
    >>> input = torch.arange(16, dtype=torch.float32).reshape(1, 1, 4, 4)
    >>> pyrdown(input, align_corners=True)
    tensor([[[[ 3.7500,  5.2500],
              [ 9.7500, 11.2500]]]])

r~   r   r¶   rÃ   ©ÚBr¨   rÑ   rÒ   )r   r!   r	   rž   r\   r   ÚTensorr    r€   ÚfloorÚreshapeÚdoubleÚlongÚSymIntÚonnxÚis_in_onnx_exportÚsym_intrT   r)   r¤   r¸   )r5   r$   r&   r(   r‡   Úx_blurrÈ   ÚheightÚwidthÚdivisorÚsiderº   Úouts   &&&&         r   r7   r7     sE  € ôb �uÒ2Ô3ä7Ó9€Fä# E°;Ó?€Fð  Ÿ+™+Ñ€A€q�%Ü�&œ%Ÿ,™,×'Ò'ô —,’, ˜x¬u¯}©}Ô=ˆØW]ÑVeÓfÑVeÈd”—’˜DŸL™L¨›O×2Ñ2Ó4°wÕ>Ó?×DÑDÓFÀq×IÐIÑVeˆÐfˆÜ	�FœEŸL™L×	)Ò	)¬e¯j©j×.JÑ.J×.LÒ.Lð CIÁÓQÁ¸”—’˜d c¨F¥lÕ3Ö4ÁˆÐQˆä”E˜&“M FÕ*Ó+¬S´°u³ÀÕ1FÓ-GÐHˆÜŸš f¸jÐXeÔf€CØ€Jùò gùò Rs   ÂAF&Ä%-F+c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r5   r   r$   r%   r&   r'   r   r   )r   s   "r   r   r   W  s)   € ÷ 4ñ 4�ð 4¨Cð 4ÈDð 4Ð]iñ 4r   c                óÀ   € \        V . RO4       \        4       pV P                  w   rEp\        P                  ! W^,          V^,          3RVR7      p\        WsV4      pV# )ad  Upsample images to twice their size and blur them with the 5x5 pyramid kernel, one pyramid level up.

``out = pyrup(input)`` takes images ``(B, C, H, W)``, resizes them bilinearly to ``(B, C, H * 2, W * 2)`` and then
blurs them with the 5x5 binomial kernel; it has no ``factor``. With ``pyrdown`` it builds the levels of
:func:`build_laplacian_pyramid`. For the step down, use :func:`pyrdown`; to change the size without blurring,
:func:`~kornia.geometry.transform.resize`.

.. image:: _static/img/pyrup.png

Convention:
    - input: ``(B, C, H, W)``
    - output spatial size is exactly doubled per dimension (no ``factor``
      parameter, unlike :func:`pyrdown`; :math:`3 \times 3 \to 6 \times 6`)
    - border_type: ``'reflect'`` by default (blur after upsample)
    - align_corners: ``False`` by default

Args:
    input: the torch.Tensor to be upsampled.
    border_type: the padding mode to be applied before convolving.
      The expected modes are: ``'constant'``, ``'reflect'``, ``'replicate'`` or ``'circular'``.
    align_corners: interpolation flag.

Return:
    the upsampled torch.Tensor.

See Also:
    - :class:`PyrUp`: the module form.
    - :func:`pyrdown`: one level down, by any factor.
    - :func:`build_laplacian_pyramid`: subtracts ``pyrup`` of each Gaussian level from the next finer one.

Examples:
    >>> input = torch.arange(4, dtype=torch.float32).reshape(1, 1, 2, 2)
    >>> pyrup(input, align_corners=True)
    tensor([[[[0.7500, 0.8750, 1.1250, 1.2500],
              [1.0000, 1.1250, 1.3750, 1.5000],
              [1.5000, 1.6250, 1.8750, 2.0000],
              [1.7500, 1.8750, 2.1250, 2.2500]]]])

r¶   rÃ   rÞ   )r   r!   rž   r¤   r¸   r	   )	r5   r$   r&   r‡   rÈ   rê   rë   Úx_upré   s	   &&&      r   rN   rN   W  s]   € ôP �uÒ2Ô3ä7Ó9€FàŸ+™+Ñ€A€q�%äŸšØ˜a•Z ¨¥Ð+°*ÈMô€Dô
 $ D°+Ó>€FØ€Mr   c          
     ó,   € V ^8„  d   QhRRRRRRRRR	R
/# )r   r5   r   Ú	max_levelrT   r$   r%   r&   r'   r   úlist[torch.Tensor]r   )r   s   "r   r   r   Ž  s4   € ÷ 8ñ 8Øð8Ø$'ð8Ø69ð8ØVZð8àñ8r   c                óX  a€ \        V . RO4       \        \        S\        4      ;'       d#    \        S\        4      '       * ;'       d    S^ 8„  V3R l4       . pVP                  V 4       \        S^,
          4       F)  pVR,          p\        WbV4      pVP                  V4       K+  	  V# )aÞ  Build a Gaussian pyramid: the image and its successively halved levels, as a list.

``levels = build_pyramid(input, max_level)`` takes images ``(B, C, H, W)`` and returns a list of ``max_level``
tensors: the input itself, then each previous level through :func:`pyrdown`, ``(B, C, H // 2, W // 2)`` and so on.
Every level must have at least one pixel per side, so ``H`` and ``W`` must be at least
``2 ** (max_level - 1)``. The blur extends its reflected border across the final 2 by 2 level. For band-pass
levels, use :func:`build_laplacian_pyramid`; for octaves of several blurs each, with their sigmas,
:class:`ScalePyramid`.

.. image:: _static/img/build_pyramid.png

Convention:
    - input: ``(B, C, H, W)``
    - ``max_level`` is the total number of levels returned (including the
      unchanged original as level 0), not a 0-based index of the last level
    - each subsequent level is produced by :func:`pyrdown` (``floor(side / 2)``
      per dimension)

Args:
    input : the torch.Tensor to be used to construct the pyramid.
    max_level: a positive integer giving the number of pyramid levels to return, including the
      unchanged original image as level 0.
    border_type: the padding mode to be applied before convolving.
      The expected modes are: ``'constant'``, ``'reflect'``,
      ``'replicate'`` or ``'circular'``.
    align_corners: interpolation flag.

Shape:
    - Input: ``(B, C, H, W)``
    - Output ``[(B, C, H, W), (B, C, H // 2, W // 2), ...]``

See Also:
    - :func:`build_laplacian_pyramid`: the differences of these levels, ending with the coarsest one.
    - :class:`ScalePyramid`: octaves of several blurred levels each, with their sigmas, for keypoint detection.
    - :func:`pyrdown`: one level of this pyramid.

c                 ó   <€ R S  2# ©z7Invalid max_level, it must be a positive integer. Got: r   ©ró   s   €r   Ú<lambda>Úbuild_pyramid.<locals>.<lambda>¹  ó   ø€ ÐIÈ)ÈÑUr   rÞ   r�   )r   r   r\   rT   r'   rÅ   r“   r7   )r5   ró   r$   r&   ÚpyramidrÈ   Úimg_currÚimg_downs   &f&&    r   Úbuild_pyramidrÿ   Ž  s•   ø€ ôP �uÒ2Ô3ÜÜ�9œcÓ"×XÐX¬:°iÄÓ+FÔ'F×XÐXÈ9ÐWXÉ=ÜUôð #%€GØ‡N�N�5Ôô �9˜q•=Ö!ˆØ!(¨¥ˆÜ!(¨ÀÓ!NˆØ�‰�xÖ ñ "ð
 €Nr   c               ó    € V ^8„  d   QhRRRR/# )r   r†   rT   r   r'   r   )r   s   "r   r   r   É  s   € ÷ +ñ +�cð +˜dñ +r   c                óP   € \        V 4      ;'       d    W ^,
          ,          '       * # )aC  Check whether an integer is a positive power of two.

``is_powerof_two(x)`` returns ``True`` for 1, 2, 4, 8, ... and ``False`` for every other integer, ``0`` and
negative numbers included. :func:`build_laplacian_pyramid` uses it to decide whether to pad an image.

Args:
    x: the integer to check.

Returns:
    ``True`` if ``x`` is a positive power of two, ``False`` otherwise (including for ``0``).

See Also:
    - :func:`find_next_powerof_two`: the smallest power of two not below ``x``.

Example:
    >>> is_powerof_two(64)
    True
    >>> is_powerof_two(100)
    False

)r'   ©r†   s   &r   Úis_powerof_twor  É  s   € ô, �‹7×*Ð*˜Q a¥%�[Ô)Ð*r   c               ó    € V ^8„  d   QhRRRR/# )r   r†   rT   r   r   )r   s   "r   r   r   â  s   € ÷ %ñ %˜Sð % Sñ %r   c                ó>   € ^V ^,
          P                  4       ,          # )a<  Find the smallest power of two that is greater than or equal to a positive integer.

``find_next_powerof_two(x)`` returns ``x`` itself when it is a power of two, and the next one above otherwise.
It is defined for positive integers only. :func:`build_laplacian_pyramid` pads each side of an image to it.

Args:
    x: a positive integer.

Returns:
    the smallest power of two not below ``x``.

See Also:
    - :func:`is_powerof_two`: whether ``x`` is already a power of two.

Example:
    >>> find_next_powerof_two(100)
    128
    >>> find_next_powerof_two(64)
    64

)Ú
bit_lengthr  s   &r   Úfind_next_powerof_twor  â  s   € ð, ��Q•×"Ñ"Ó$Õ$Ð$r   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r5   r   r¦   rT   Údimr<   r'   r   r   )r   s   "r   r   r   û  s/   € ÷ 	)ñ 	)�Lð 	) sð 	)°ð 	)¸tð 	)Èñ 	)r   c                óJ  € V P                   V,          pV'       d1   V P                  W$^,
          V,
          V4      P                  V4      pMA\        V P                   4      pWV&   V P                  W$^,
          ^4      P	                  V4      p\
        P                  ! W.V4      # )zfAppend ``pad`` rows (``dim=2``) or columns (``dim=3``): reflected about the last one, or copies of it.)rž   ÚnarrowÚflipÚlistr¢   r   Úcat)r5   r¦   r	  r<   rí   Útailrž   s   &&&&   r   Ú_pad_endr  û  s}   € à�;‰;�sÕ€DßØ�|‰|˜C¨¥¨C¥°Ó5×:Ñ:¸3Ó?‰ä�U—[‘[Ó!ˆØˆc‰
Ø�|‰|˜C¨¥¨1Ó-×4Ñ4°UÓ;ˆÜ�9Š9�e�] CÓ(Ð(r   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r5   r   ró   rT   r   r   )r   s   "r   r   r     s!   € ÷ ñ ˜,ð °3ð ¸<ñ r   c                ój  € V P                  4       ^,          pV P                  4       ^,          p^V^,
          ,          pW$,           ^,
          V,          V,          V,
          pW4,           ^,
          V,          V,          V,
          pV^ 8w  d   \        W^WR8  4      p V^ 8w  d   \        W^Wc8  4      p V # )zjPad the bottom and right of ``input`` to the next multiple of ``2 ** (max_level - 1)``, the rule of #6319.)rº   r  )r5   ró   rê   rë   ÚstrideÚ
pad_heightÚ	pad_widths   &&     r   Ú_pad_to_strider    s›   € à�Z‰Z‹\˜!�_€FØ�J‰J‹L˜�O€EØ�9˜q•=Õ!€Fð •/ AÕ%¨&Õ0°6Õ9¸FÕB€JØ• !Õ#¨Õ.°Õ7¸%Õ?€IØ�Q„Ü˜¨A¨zÑ/BÓCˆØ�A„~Ü˜¨1¨iÑ.?Ó@ˆØ€Lr   Úminimal_paddingc               ó0   € V ^8„  d   QhRRRRRRRRR	R
RR/# )r   r5   r   ró   rT   r$   r%   r&   r'   r  zbool | Noner   rô   r   )r   s   "r   r   r     sL   € ÷ {ñ {Øð{àð{ð ð{ð ð	{ð !ð{ð ñ{r   c               óJ  a€ \        V . RO4       \        \        S\        4      ;'       d#    \        S\        4      '       * ;'       d    S^ 8„  V3R l4       RpV'       d   \        V S4      p EMV P                  4       ^,          pV P                  4       ^,          p^S^,
          ,          p\        V4      ;'       g    \        V4      '       * p	S^8”  d)   T	;'       g    Wh,          ^ 8g  ;'       g    Wx,          ^ 8g  p	V	'       dz   ^ \        V4      V,
          ^ \        V4      V,
          3p
\        P                  ! W
R4      p VRJ ;'       d1    \        4       '       * ;'       d    V
^ V) V,          ^ V) V,          38g  p\        V SW#4      p. p\        S^,
          4       F<  p\        W½^,           ,          W#4      pW½,          V,
          pVP                  V4       K>  	  VP                  VR,          4       V'       d"   \         P"                  ! \$        \&        ^R7       V# )u  Build a Laplacian pyramid: band-pass differences of Gaussian levels, ending with the coarsest level.

``levels = build_laplacian_pyramid(input, max_level)`` takes images ``(B, C, H, W)`` and returns a list of
``max_level`` tensors: level ``i`` is Gaussian level ``i`` of :func:`build_pyramid` minus :func:`pyrup` of Gaussian
level ``i + 1``, and the last is the coarsest Gaussian level. Starting from ``x = levels[-1]``,
``x = pyrup(x, border_type, align_corners) + levels[i]`` for ``i`` from ``max_level - 2`` down to 0, with the
``border_type`` and ``align_corners`` the pyramid was built with, rebuilds the input up to float rounding. The
input is first reflect-padded at the right and bottom to the next power of two per side when neither side is a
power of two or a side does not halve evenly ``max_level - 1`` times (see Convention); every level is then shaped
from the padded size, and the rebuilt image is the padded one. That rule is deprecated since kornia 0.9.1: with the
default ``minimal_padding=None``, an eager call that ``minimal_padding=True`` would shape differently emits a
``FutureWarning``. ``minimal_padding=True`` gives the rule of a future minor release, which pads only to the next
multiple of ``2 ** (max_level - 1)``, and ``minimal_padding=False`` keeps the current rule without the warning. For
the Gaussian levels themselves, use :func:`build_pyramid`.

See :cite:`burt1987laplacian` for more details.

Convention:
    - input: ``(B, C, H, W)``
    - ``max_level`` is the total number of levels returned, not a 0-based
      index of the last level
    - levels ``0`` through ``max_level - 2`` are band-pass residuals: level
      ``i`` = :func:`build_pyramid` Gaussian level ``i`` minus a
      :func:`pyrup`-expanded Gaussian level ``i + 1``; only the last
      element (index ``max_level - 1``) is the unsubtracted final Gaussian
      level â€” level 0 is **not** the unchanged original image whenever
      ``max_level > 1``
    - the input is reflect-padded up to the next power of two (per dimension)
      when neither side is already a power of two, or when ``max_level > 1``
      and a side is not divisible by ``2 ** (max_level - 1)``. When
      padding is applied, every returned level â€” including level 0 â€” is
      shaped from the padded size
    - with ``minimal_padding=True``, the input is padded only when a side is not
      divisible by ``2 ** (max_level - 1)``, and only that side, to the next multiple.
      So 480x640 at 3 levels stays 480x640, where the rule above gives 512x1024.
      A side too small for the padding to reflect repeats its last row or column instead,
      whatever ``border_type``
    - border_type: ``'reflect'`` by default
    - align_corners: ``False`` by default

Args:
    input : the torch.Tensor to be used to construct the pyramid with shape ``(B, C, H, W)``.
    max_level: a positive integer giving the number of pyramid levels to return (see Convention
      above for what each level contains).
    border_type: the padding mode to be applied before convolving.
      The expected modes are: ``'constant'``, ``'reflect'``,
      ``'replicate'`` or ``'circular'``.
    align_corners: interpolation flag.
    minimal_padding: ``True`` pads only as ``max_level`` needs (see Convention above), the future default.
      ``False`` keeps the power-of-two rule without a warning. ``None``, the current default, uses the
      power-of-two rule and warns on a call that ``True`` would shape differently. Once ``True`` is the
      default, ``False`` keeps the power-of-two rule for one more minor release, with a deprecation warning,
      and then the keyword is removed.

Return:
    Output: ``[(B, C, H', W'), (B, C, H' / 2, W' / 2), ...]``, where
    ``(H', W')`` equals the input ``(H, W)`` unless padding was
    applied (see Convention above), in which case it is the padded size.

See Also:
    - :func:`build_pyramid`: the Gaussian levels these are differences of.
    - :func:`pyrup`: the upsampling step between levels, also the one that rebuilds the image.
    - :class:`ScalePyramid`: octaves of blurred levels for keypoint detection, with their sigmas.

Example:
    >>> levels = build_laplacian_pyramid(torch.rand(1, 1, 480, 640), 3, minimal_padding=True)
    >>> [tuple(level.shape[-2:]) for level in levels]
    [(480, 640), (240, 320), (120, 160)]

c                 ó   <€ R S  2# r÷   r   rø   s   €r   rù   Ú)build_laplacian_pyramid.<locals>.<lambda>l  rû   r   Fr<   N)Ú
stacklevelrÞ   r�   )r   r   r\   rT   r'   r  rº   r  r  r¤   r¦   r   rÿ   r“   rN   rÅ   ÚwarningsÚwarnÚ'_LAPLACIAN_POWER_OF_TWO_PADDING_MESSAGEÚFutureWarning)r5   ró   r$   r&   r  Úshape_will_changeÚhÚwr  Úrequire_paddingÚpaddingÚgaussian_pyramidÚlaplacian_pyramidrÖ   Ú
img_expandÚ	laplacians   &f&&$           r   Úbuild_laplacian_pyramidr*    sÛ  ø€ ô\ �uÒ2Ô3ÜÜ�9œcÓ"×XÐX¬:°iÄÓ+FÔ'F×XÐXÈ9ÐWXÉ=ÜUôð
 ÐßÜ˜u iÓ0Šà�J‰J‹L˜�OˆØ�J‰J‹L˜�OˆØ�y 1•}Õ%ˆÜ-¨aÓ0×EÐE´NÀ1Ó4EÔFˆØ�qŒ=ð .×SÐS°µ¸q±×SÐSÀAÅJÐRSÁOˆOçð Ô/°Ó2°QÕ6¸Ô;PÐQRÓ;SÐVWÕ;WÐXˆGÜ—E’E˜%¨)Ó4ˆEð
   4Ð'×nÐn´³Ô,>×nÐnÀ7ÈqÐSTÐRTÐW]ÕR]Ð_`ÐcdÐbdÐgmÕbmÐNnÑCnð ô
 ,9¸À	È;Ó+fÐà,.Ðô �9˜q•=Ö!ˆÜ#(Ð)9¸a½%Õ)@À+Ó#]ˆ
Ø"2Õ"5¸
Õ"Bˆ	Ø× Ñ  Ö+ñ "ð ×ÑÐ-¨bÕ1Ô2çÜ�ŠÔ=¼}ÐYZÕ[ØÐr   )	r   r   r   r*  rÿ   r  r  r7   rN   r;   rP   )*rC   Ú
__future__r   r�   r]   r  Útypingr   r   Útorch.nn.functionalr   Ú
functionalr¤   Úkornia.core.checkr   r   Úkornia.core.exceptionsr   Úkornia.core.utilsr   Úkornia.filtersr	   r
   Úkornia.filters.gaussianr   r   Ú__all__r  r!   ÚModuler   r   ra   r   r7   rN   rÿ   r  r  r  r  r*  r   r   r   Ú<module>r6     sÈ   ðñ$õ, #ã Û Û Ý ã ß Ð Ý ç >Ý 2Ý *ß 4ß Wò
€ð?ð (õô$:Qˆb�i‰iô :Qôz6BˆB�I‰Iô 6Bõrô0\/�2—9‘9ô \/÷~E÷P4÷n8õv+õ2%õ2	)õñ({ð $(÷{ò {r   