+
    åûj*G  ã                   ó–   € ^ RI Ht ^ RIt^ RIHtHtHtHt R R ltR R lt	R R	 lt
RR
 R lltRR R lltRR R lltRR R lltR# )é    )ÚOptionalN)ÚKORNIA_CHECKÚKORNIA_CHECK_IS_TENSORÚKORNIA_CHECK_SAME_DEVICEÚKORNIA_CHECK_SAME_SHAPEc                ód   € V ^8„  d   QhR\         P                  R\         P                  R\        /# )é   ÚshapeÚtarget_shapeÚreturn)ÚtorchÚSizeÚbool)Úformats   "ÚTC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\metrics\disparity.pyÚ__annotate__r      s.   € ÷ cñ c¤§
¡
ð c¼%¿*¹*ð cÌñ có    c           	     ó  € \        V 4      \        V4      8”  d   R# \        ;QJ d:    R \        \        V 4      \        V4      RR7       4       F  '       d   K   R# 	  R# ! R \        \        V 4      \        V4      RR7       4       4      # )z=Check whether ``shape`` can be broadcast to ``target_shape``.Fc              3   ó4   "  € T F  w  rV^V39   x € K  	  R# 5i)é   N© )Ú.0ÚsÚts   &  r   Ú	<genexpr>Ú'_is_broadcastable_to.<locals>.<genexpr>"   s   é € ÐbÑ'a™t˜qˆq�Q˜�FŽ{Ó'aùs   ‚)ÚstrictT)ÚlenÚallÚzipÚreversed)r
   r   s   &&r   Ú_is_broadcastable_tor"      se   € ä
ˆ5ƒz”C˜Ó%Ô%Ùß‹3Ñb¤s¬8°E«?¼HÀ\Ó<RÐ[`Õ'aÓb�3Œ3ÐbŠ3Ðbˆ3Ñb¤s¬8°E«?¼HÀ\Ó<RÐ[`Õ'aÓbÓbÐbr   c          	      óÄ   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        \         P                  ,          /# )r	   ÚinputÚtargetÚ
valid_maskr   )r   ÚTensorr   )r   s   "r   r   r   %   sL   € ÷ Zñ ZÜ�<‰<ðZÜ!&§¡ðZÜ;CÄEÇLÁLÕ;QðZäŒe�l‰lÕñZr   c                ó´  € \        V 4       \        V4       \        W4       V P                  ^ 8”  g7   V P                  P                  R8w  d'   VP                  P                  R8w  d   \        W4       \        V P                  4       ;'       d    VP                  4       RV P                   RVP                   R24       Vf   R# \        V4       \        \        VP                  V P                  4      RVP                   RV P                   24       VP                  V P                  \        P                  R7      P                  V P                  4      # )zXValidate disparity metric inputs and return the valid mask broadcast to the input shape.Úcpuz6Disparity maps must have a floating point dtype. Got: z and z2. Convert them first, for example with `.float()`.Nz@valid_mask shape must be broadcastable to the input shape. Got: )ÚdeviceÚdtype)r   r   Úndimr*   Útyper   r   Úis_floating_pointr+   r"   r
   Útor   r   Úbroadcast_to)r$   r%   r&   s   &&&r   Ú_check_disparity_inputsr1   %   s  € ô ˜5Ô!Ü˜6Ô"Ü˜EÔ*ð ‡z�z�A„~˜%Ÿ,™,×+Ñ+¨uÔ4¸¿¹×9KÑ9KÈuÔ9TÜ  Ô/ô Ø×ÑÓ!×@Ð@ f×&>Ñ&>Ó&@ð	Ø—‘ˆ}˜E &§,¡, Ð/að	côð ÒÙä˜:Ô&ÜÜ˜Z×-Ñ-¨u¯{©{Ó;Ø
JÈ:×K[ÑK[ÐJ\Ð\aÐbg×bmÑbmÐanÐoôð �=‰= §¡´E·J±Jˆ=Ó?×LÑLÈUÏ[É[ÓYÐYr   c                óš   € V ^8„  d   QhR\         P                  R\        \         P                  ,          R\        R\         P                  /# )r	   Úerrorr&   Ú	reductionr   ©r   r'   r   Ústr)r   s   "r   r   r   F   s=   € ÷ ñ ¤5§<¡<ð ¼XÄeÇlÁlÕ=Sð Ô`cð Ôhm×htÑhtñ r   c                óÂ  € V P                   p\        P                  ! V\        P                  4      pVe   \        P                  ! W^ 4      p VR8X  dO   Vf   V P                  4       MVP                  4       pV P                  VR7      V,          P                  V4      p V # VR8X  d$   V P                  VR7      P                  V4      p V # VR8X  d    V # \        R4      h)a¸  Reduce a per-pixel error map over the valid pixels according to ``reduction``.

The sums are accumulated in ``float32`` for half-precision inputs. A ``float16`` sum saturates
at 65504, so an image-sized map would otherwise reduce to ``inf``, and a ``bfloat16`` sum loses
several significant digits over the same number of terms. The result is cast back to the dtype
of ``error`` so that the metrics keep returning the dtype of their input.
Úmean)r+   ÚsumÚnonezInvalid reduction option.)	r+   r   Úpromote_typesÚfloat32ÚwhereÚnumelr9   r/   ÚNotImplementedError)r3   r&   r4   Ú	out_dtypeÚ	acc_dtypeÚcounts   &&&   r   Ú_reduce_disparity_errorrC   F   sÑ   € ð —‘€IÜ×#Ò# I¬u¯}©}Ó=€IàÒô —’˜J¨qÓ1ˆà�FÔØ!+Ò!3�—‘”¸¿¹Ó9IˆØ—‘ �Ó+¨eÕ3×7Ñ7¸	ÓBˆð €Lð 
�eÔ	Ø—	‘	 	�	Ó*×-Ñ-¨iÓ8ˆð €Lð 
�fÔ	Øð €Lô "Ð"=Ó>Ð>r   c          
      óº   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        R\         P                  /# ©r	   r$   r%   r&   r4   r   r5   )r   s   "r   r   r   c   sV   € ÷ A;ñ A;Ü�<‰<ðA;ä�L‰LðA;ô œŸ™Õ&ðA;ô ð	A;ô
 ‡\�\ñA;r   c                ó^   € \        WV4      pW,
          P                  4       p\        WTV4      # )ao  Compute the mean absolute error (MAE) between two disparity maps, over the valid pixels.

``mae = mean_absolute_disparity_error(input, target, valid_mask)`` takes two floating disparity maps in pixels
with shape ``(*)`` and returns the mean of their absolute difference over the valid pixels :math:`\mathcal{V}`
as a 0-d tensor:

.. math::

    \text{MAE}(D, D^{gt}) = \frac{1}{|\mathcal{V}|}\sum_{p \in \mathcal{V}} |D_{p} - D^{gt}_{p}|

Convention:
    - ``'mean'`` and ``'sum'`` pool every valid pixel of every image into one 0-d value, so for images with
      different numbers of valid pixels the result is not the mean of the per-image errors. The other disparity
      metrics pool the same way. If ``valid_mask`` selects no pixels, ``'mean'`` returns ``nan`` and ``'sum'``
      returns 0.
    - ``valid_mask`` is broadcast to the maps from the right: an ``(H, W)`` mask applies to every image of a
      ``(B, H, W)`` batch and a ``(B, 1, 1)`` mask selects whole images, while a ``(B,)`` mask is
      matched against the last axis, not the batch. Nothing is masked automatically: a pixel with an invalid
      ground truth, such as a zero disparity, counts unless ``valid_mask`` excludes it.
    - A ``nan`` at a valid pixel of either map propagates into this error and the RMSE, while
      :func:`~kornia.metrics.mean_bad_pixel_error` and :func:`~kornia.metrics.kitti_d1_error` count it as a
      good pixel.
    - Half-precision sums are accumulated in ``float32`` and the result is cast back to the input dtype, so
      ``'mean'`` stays accurate on image-sized maps, while a ``float16`` ``'sum'`` above 65504 saturates to
      ``inf``: reduce with ``'none'`` and sum in a wider dtype for totals that large.

Args:
    input: predicted disparity map in pixels, with shape ``(*)``.
    target: ground-truth disparity map with the shape of ``input``.
    valid_mask: optional mask broadcastable to ``input``; nonzero (``True``) values mark the pixels to evaluate.
        ``None`` evaluates all pixels.
    reduction: ``'mean'`` (default) averages over the valid pixels, ``'sum'`` adds them and ``'none'`` returns the
        per-pixel error map with masked-out positions set to zero.

Returns:
    the error as a 0-d tensor, or the per-pixel error map for ``reduction='none'``.

See Also:
    - :func:`~kornia.metrics.root_mean_squared_disparity_error`: the root of the mean squared error, which weights
      large errors more.
    - :func:`~kornia.metrics.mean_bad_pixel_error`: the fraction of pixels above an error threshold.
    - :func:`~kornia.metrics.kitti_d1_error`: the KITTI outlier fraction, with a relative criterion.

Examples:
    >>> input = torch.tensor([[0.0, 1.0], [2.0, 3.0]])
    >>> target = torch.tensor([[0.0, 1.0], [2.0, 4.0]])
    >>> mean_absolute_disparity_error(input, target)
    tensor(0.2500)
    >>> valid_mask = torch.tensor([[True, True], [True, False]])
    >>> mean_absolute_disparity_error(input, target, valid_mask)
    tensor(0.)

Reference:
    D. Scharstein and R. Szeliski. A taxonomy and evaluation of dense two-frame stereo
    correspondence algorithms. IJCV 2002. https://vision.middlebury.edu/stereo/taxonomy-IJCV.pdf

)r1   ÚabsrC   )r$   r%   r&   r4   Úmaskr3   s   &&&&  r   Úmean_absolute_disparity_errorrI   c   s.   € ô~ # 5°*Ó=€DØ�^× Ñ Ó"€EÜ" 5°	Ó:Ð:r   c          
      óº   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        R\         P                  /# rE   r5   )r   s   "r   r   r   §   s]   € ÷ DVñ DVÜ�<‰<ðDVä�L‰LðDVô œŸ™Õ&ðDVô ð	DVô
 ‡\�\ñDVr   c                óX  € \        WV4      p\        P                  ! V P                  VP                  4      p\        P                  ! V\        P                  4      pV P                  V4      VP                  V4      ,
          pVe   \        P                  ! WG^ 4      p\        V^,          WC4      pV^ 8H  p	\        P                  ! V	\        P                  ! V4      V4      p
\        P                  ! V	\        P                  ! V4      V
P                  4       4      P                  V4      # )aÖ  Compute the root mean squared error (RMSE) between two disparity maps, over the valid pixels.

``rmse = root_mean_squared_disparity_error(input, target, valid_mask)`` takes two floating disparity maps in
pixels with shape ``(*)`` and returns the root of the mean squared difference over the valid pixels
:math:`\mathcal{V}` as a 0-d tensor:

.. math::

    \text{RMSE}(D, D^{gt}) =
    \sqrt{\frac{1}{|\mathcal{V}|}\sum_{p \in \mathcal{V}} (D_{p} - D^{gt}_{p})^{2}}

Convention:
    - See the Convention block of :func:`~kornia.metrics.mean_absolute_disparity_error` for the pooling, the
      mask and the empty-mask result.
    - ``'sum'`` gives :math:`\sqrt{\sum e^2}`, not a sum of errors. The squared error is computed in ``float32``
      for half-precision inputs and only the final value is cast back, so an error above 256 px does not
      saturate ``float16``.

Args:
    input: predicted disparity map in pixels, with shape ``(*)``.
    target: ground-truth disparity map with the shape of ``input``.
    valid_mask: optional mask broadcastable to ``input``; nonzero (``True``) values mark the pixels to evaluate.
        ``None`` evaluates all pixels.
    reduction: ``'mean'`` (default) averages the squared error over the valid pixels before the root, ``'sum'``
        adds it, and ``'none'`` returns the per-pixel absolute error with masked-out positions set to zero.

Returns:
    the error as a 0-d tensor, or the per-pixel absolute error map for ``reduction='none'``.

See Also:
    - :func:`~kornia.metrics.mean_absolute_disparity_error`: the mean of the absolute errors, which weights large
      errors less.

Examples:
    >>> input = torch.zeros(2, 2)
    >>> target = torch.tensor([[0.0, 0.0], [0.0, 1.0]])
    >>> root_mean_squared_disparity_error(input, target)
    tensor(0.5000)

Reference:
    D. Scharstein and R. Szeliski. A taxonomy and evaluation of dense two-frame stereo
    correspondence algorithms. IJCV 2002. https://vision.middlebury.edu/stereo/taxonomy-IJCV.pdf

)r1   r   r;   r+   r<   r/   r=   rC   Ú	ones_likeÚ
zeros_likeÚsqrt)r$   r%   r&   r4   rH   r@   rA   ÚdiffÚsquaredÚis_zeroÚsafes   &&&&       r   Ú!root_mean_squared_disparity_errorrS   §   sÜ   € ôd # 5°*Ó=€Dô ×#Ò# E§K¡K°·±Ó>€IÜ×#Ò# I¬u¯}©}Ó=€IØ�8‰8�IÓ §¡¨9Ó!5Õ5€DØÒô �{Š{˜4 qÓ)ˆÜ% d¨A¥g¨tÓ?€Gð
 ˜‰l€GÜ�;Š;�w¤§¢°Ó 8¸'ÓB€DÜ�;Š;�w¤× 0Ò 0°Ó 9¸4¿9¹9»;ÓG×JÑJÈ9ÓUÐUr   c                óÆ   € V ^8„  d   QhR\         P                  R\         P                  R\        R\        \         P                  ,          R\        R\         P                  /# )r	   r$   r%   Ú	thresholdr&   r4   r   ©r   r'   Úfloatr   r6   )r   s   "r   r   r   î   sY   € ÷ 79ñ 79Ü�<‰<ð79ä�L‰Lð79ô ð79ô œŸ™Õ&ð	79ô
 ð79ô ‡\�\ñ79r   c                óÔ   € \        WV4      pW,
          P                  4       V8„  P                  \        P                  ! V P
                  VP
                  4      4      p\        WeV4      # )a½  Compute the fraction of bad pixels between two disparity maps, over the valid pixels.

``bad = mean_bad_pixel_error(input, target, threshold, valid_mask)`` takes two floating disparity maps in pixels
with shape ``(*)`` and returns the fraction of valid pixels :math:`\mathcal{V}` whose absolute error is strictly
greater than ``threshold`` :math:`\tau`, a 0-d tensor in :math:`[0, 1]`:

.. math::

    \text{Bad}_{\tau}(D, D^{gt}) =
    \frac{1}{|\mathcal{V}|}\sum_{p \in \mathcal{V}} [|D_{p} - D^{gt}_{p}| > \tau]

This is the bad-pixel percentage of the Middlebury stereo benchmark as a fraction. It is **not** the number
KITTI reports: use :func:`~kornia.metrics.kitti_d1_error`.

Convention:
    - See the Convention block of :func:`~kornia.metrics.mean_absolute_disparity_error` for the pooling, the
      mask, the empty-mask result and half-precision sums. ``'sum'`` gives the number of bad pixels.
    - The output is built from comparisons, so it does not require grad and cannot be used as a loss.

Args:
    input: predicted disparity map in pixels, with shape ``(*)``.
    target: ground-truth disparity map with the shape of ``input``.
    threshold: the absolute error above which a pixel is bad.
    valid_mask: optional mask broadcastable to ``input``; nonzero (``True``) values mark the pixels to evaluate.
        ``None`` evaluates all pixels.
    reduction: ``'mean'`` (default) gives the fraction of bad pixels among the valid pixels, ``'sum'`` their
        number, and ``'none'`` the per-pixel bad-pixel map with masked-out positions set to zero.

Returns:
    the fraction as a 0-d tensor, or the per-pixel bad-pixel map for ``reduction='none'``.

See Also:
    - :func:`~kornia.metrics.kitti_d1_error`: adds a relative criterion.
    - :func:`~kornia.metrics.mean_absolute_disparity_error`: the mean error in pixels, with no threshold.

Examples:
    >>> input = torch.zeros(2, 2)
    >>> target = torch.tensor([[0.0, 1.0], [2.0, 4.0]])
    >>> mean_bad_pixel_error(input, target, threshold=1.5)
    tensor(0.5000)

Reference:
    D. Scharstein and R. Szeliski. A taxonomy and evaluation of dense two-frame stereo
    correspondence algorithms. IJCV 2002. https://vision.middlebury.edu/stereo/taxonomy-IJCV.pdf

©r1   rG   r/   r   r;   r+   rC   )r$   r%   rU   r&   r4   rH   Úbads   &&&&&  r   Úmean_bad_pixel_errorr[   î   sV   € ôj # 5°*Ó=€DØ�N×ÑÓ! IÑ-×
1Ñ
1´%×2EÒ2EÀeÇkÁkÐSY×S_ÑS_Ó2`Ó
a€CÜ" 3¨iÓ8Ð8r   c                óÒ   € V ^8„  d   QhR\         P                  R\         P                  R\        R\        R\        \         P                  ,          R\        R\         P                  /# )r	   r$   r%   Úabs_thresholdÚrel_thresholdr&   r4   r   rV   )r   s   "r   r   r   (  sl   € ÷ B=ñ B=Ü�<‰<ðB=ä�L‰LðB=ô ðB=ô ð	B=ô
 œŸ™Õ&ðB=ô ðB=ô ‡\�\ñB=r   c                ó  € \        WV4      pW,
          P                  4       pWr8„  WqP                  4       ,          V8„  ,          P                  \        P                  ! V P
                  VP
                  4      4      p\        W†V4      # )a§  Compute the KITTI D1 outlier fraction between two disparity maps, over the valid pixels.

``d1 = kitti_d1_error(input, target, abs_threshold, rel_threshold, valid_mask)`` takes two floating disparity
maps in pixels with shape ``(*)`` and returns the fraction of valid pixels :math:`\mathcal{V}` that are
outliers, a 0-d tensor in :math:`[0, 1]`. A pixel is an outlier when its absolute error exceeds ``abs_threshold``
**and** its error relative to the ground truth exceeds ``rel_threshold``:

.. math::

    \text{D1}(D, D^{gt}) = \frac{1}{|\mathcal{V}|}\sum_{p \in \mathcal{V}}
    \left[|D_{p} - D^{gt}_{p}| > \tau_{abs} \;\wedge\;
    \frac{|D_{p} - D^{gt}_{p}|}{|D^{gt}_{p}|} > \tau_{rel}\right]

Convention:
    - See the Convention block of :func:`~kornia.metrics.mean_absolute_disparity_error` for the pooling, the
      mask, the empty-mask result and half-precision sums. ``'sum'`` gives the number of outliers.
      :ref:`Losses and metrics <losses-metrics-conventions>` relates it to the KITTI devkit.
    - The relative error divides by ``target``, so the two maps are not interchangeable: swapping them can
      change the result.
    - A zero ground-truth disparity gives a non-finite relative error, so that pixel is classified by
      ``abs_threshold`` alone and the output stays finite. KITTI marks these pixels invalid: pass ``valid_mask``.
    - A ``nan`` in either map counts as an **inlier**, because every comparison against ``nan`` is false and both
      criteria must hold. Mask non-finite pixels out with ``valid_mask``.
    - The output is built from comparisons, so it does not require grad and cannot be used as a loss.

Args:
    input: predicted disparity map in pixels, with shape ``(*)``.
    target: ground-truth disparity map with the shape of ``input``.
    abs_threshold: the absolute error above which a pixel may be an outlier.
    rel_threshold: the relative error above which a pixel may be an outlier.
    valid_mask: optional mask broadcastable to ``input``; nonzero (``True``) values mark the pixels to evaluate.
        ``None`` evaluates all pixels.
    reduction: ``'mean'`` (default) gives the fraction of outliers among the valid pixels, ``'sum'`` their number,
        and ``'none'`` the per-pixel outlier map with masked-out positions set to zero.

Returns:
    the fraction as a 0-d tensor, or the per-pixel outlier map for ``reduction='none'``.

See Also:
    - :func:`~kornia.metrics.mean_bad_pixel_error`: the absolute criterion alone, as Middlebury reports.
    - :func:`~kornia.metrics.mean_absolute_disparity_error`: the mean absolute error, whose rules this one shares.

Examples:
    >>> input = torch.tensor([1.0, 5.0, 104.0, 20.0])
    >>> target = torch.tensor([1.0, 1.0, 100.0, 10.0])
    >>> kitti_d1_error(input, target)
    tensor(0.5000)

Reference:
    M. Menze and A. Geiger. Object Scene Flow for Autonomous Vehicles. CVPR 2015.
    https://www.cvlibs.net/datasets/kitti/eval_scene_flow.php?benchmark=stereo

rY   )	r$   r%   r]   r^   r&   r4   rH   r3   Úoutliers	   &&&&&&   r   Úkitti_d1_errorra   (  sn   € ôz # 5°*Ó=€DØ�^× Ñ Ó"€EØÑ%¨%·*±*³,Õ*>ÀÑ*NÕO×SÑSÜ×Ò˜EŸK™K¨¯©Ó6ó€Gô # 7°)Ó<Ð<r   )Nr8   )ç      @Nr8   )rb   gš™™™™™©?Nr8   )Útypingr   r   Úkornia.core.checkr   r   r   r   r"   r1   rC   rI   rS   r[   ra   r   r   r   Ú<module>re      sJ   ðõ$ ã ÷ó õcõZõB÷:A;÷HDV÷N79÷tB=ñ B=r   