+
    åûj1G  ã                  óÆ   € ^ RI Ht ^ RIt^ RIt^ RIt^ RIHu Ht ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt Rt ! R R	]P                   4      t ! R
 R]4      t ! R R]4      tR# )é    )ÚannotationsN)Únn)ÚKORNIA_CHECK_SAME_DEVICE)Ú_is_numpy_bool)Úis_compilingg      Ð?c                  ój   a € ] tR t^#tRtRR V 3R llltRR R lltR R ltR R	 ltR
 R lt	Rt
V ;t# )Ú_HausdorffERLossBasea†  Base class for the Hausdorff losses based on morphological erosion, one binary map per class channel.

The loss follows ``Loss_ER`` of :cite:`karimi2019reducing` (Eq. 12). The error of a pixel is its squared error
above the value where thresholding the probability at 0.5 starts to misclassify it, and it is weighted by
``sum_i i ** alpha`` over the ``k`` successive erosions of the misclassified set that keep the pixel. The erosion
takes the minimum over the nonzero entries of :meth:`get_kernel`.

Args:
    alpha: the exponent of the weight ``(i + 1) ** alpha`` of erosion ``i = 0, ..., k - 1``.
    k: the number of iterations of erosion.
    reduction: Specifies the reduction to apply to the output: 'none' | 'mean' | 'sum'.
        'none': no reduction will be applied, 'mean': the mean of the output is taken,
        'sum': the output will be summed.

Returns:
    Estimated Hausdorff Loss.

c               ó(   € V ^8„  d   QhRRRRRRRR/# )	é   ÚalphaÚfloatÚkÚintÚ	reductionÚstrÚreturnÚNone© )Úformats   "ÚSC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\losses\hausdorff.pyÚ__annotate__Ú!_HausdorffERLossBase.__annotate__7   s)   € ÷ 
ñ 
˜eð 
¨cð 
À3ð 
ÐTXñ 
ó    c                	óÆ  <a € \         SS `  4        \        P                  ! V\        P
                  8  4      P                  4       '       g   \        R V R24      h\        V\        4      '       gQ   \        V\        P                  4      '       d    VP                  \        P                  8X  g   \        V4      '       d   \        R4      h \        P                  ! V4      pT^ 8  d   \        RT R24      hTR9  d   \%        RT R24      hTS n        TS n        TS n        S P-                  4       pS P/                  RT4       TP1                  TP2                  R	,          4      p\4        ;QJ d    . R
 TP2                   4       F  NK  	  5M! R
 TP2                   4       4      S n        \4        ;QJ d@    . T 3R l\        P8                  ! T4      P;                  4        4       F  NK  	  5S n        R# ! T 3R l\        P8                  ! T4      P;                  4        4       4      S n        R#   \         d%    \        R\!        T4      P"                   R24      Rhi ; i)z#alpha must not be NaN or +inf. Got Ú.zk must be an integer. Got bool.zk must be an integer. Got Nzk must be non-negative. Got úreduction `ú` has not been implemented yet.Úkernelºr   NNc              3  ó@   "  € T F  q^,
          ^,          x € K  	  R# 5i)é   Nr   )Ú.0Úsizes   & r   Ú	<genexpr>Ú0_HausdorffERLossBase.__init__.<locals>.<genexpr>R   s   é € ÐG¹° Q�h¨1Ÿ_š_»ùs   ‚c              3  óÌ   <"  € T FY  p\         ;QJ d(    . R  \        VSP                  4       4       F  NK  	  5M!! R  \        VSP                  4       4       4      x € K[  	  R# 5i)c              3  óJ   "  € T F  w  r\        V4      V,
          x € K  	  R # 5i©N)r   )r"   ÚiÚrs   &  r   r$   Ú:_HausdorffERLossBase.__init__.<locals>.<genexpr>.<genexpr>T   s   é € ÐBÑ)A¡ ”#�a“&˜1—*’*Ó)Aùs   ‚!#N)ÚtupleÚzipÚ_radius)r"   ÚindexÚselfs   & €r   r$   r%   S   sG   øé € ð 
ÙPoÀu�EŒEÑB¬¨U°D·L±LÔ)AÓB�E‰EÑB¬¨U°D·L±LÔ)AÓB×BÐBÓPoùs   ƒA$“AA$)ÚmeanÚsumÚnone)ÚsuperÚ__init__ÚtorchÚ	as_tensorÚmathÚinfÚallÚ
ValueErrorÚ
isinstanceÚboolÚTensorÚdtyper   Ú	TypeErrorÚoperatorr/   ÚtypeÚ__name__ÚNotImplementedErrorr   r   r   Ú
get_kernelÚregister_bufferÚreshapeÚshaper,   r.   ÚnonzeroÚtolistÚ_offsets)r0   r   r   r   r   ÚweightsÚ	__class__s   f&&&  €r   r5   Ú_HausdorffERLossBase.__init__7   sÜ  ù€ Ü‰ÑÔô �Š˜u¤t§x¡xÑ/Ó0×4Ñ4×6Ò6ÜÐBÀ5À'ÈÐKÓLÐLä�aœ×Ò¤:¨a´·±×#>Ò#>À1Ç7Á7ÌeÏjÉjÔCXÔ]kÐlm×]nÒ]nÜÐ=Ó>Ð>ð	Xä—’˜qÓ!ˆAð ˆqŒ5ÜÐ;¸A¸3¸aÐ@ÓAÐAØÐ3Ô3Ü%¨°I°;Ð>]Ð&^Ó_Ð_ØˆŒ
ØˆŒØ"ˆŒØ—‘Ó"ˆà×Ñ˜X vÔ.ð —.‘. §¡¨bÕ!1Ó2ˆß”uÑG¸¿ºÓG—u‘uÑG¸¿ºÓGÓGˆŒßœô 
ÜPU×P]ÒP]Ð^eÓPf×PmÑPmÔPoó
ŸˆŽ˜ô 
ÜPU×P]ÒP]Ð^eÓPf×PmÑPmÔPoó
ó 
ˆŽøô! ô 	XÜÐ8¼¸a»×9IÑ9IÐ8JÈ!ÐLÓMÐSWÐWð	Xús   ÃH1 È1/I c               ó    € V ^8„  d   QhRRRR/# ©r   r?   ztorch.dtype | Noner   útorch.Tensorr   )r   s   "r   r   r   W   s   € ÷ 	"ñ 	"Ð 2ð 	"¸lñ 	"r   c                ó   € \         h)ap  Get the structuring element of the erosion as a ``(1, 1, *window)`` kernel with odd sizes.

Only the nonzero entries matter: the erosion takes the minimum over them, centred on each pixel, and ignores
their values. ``__init__`` calls ``get_kernel()`` once, so an override may take no arguments.

Args:
    dtype: dtype of the kernel; ``None`` gives the default dtype.
)rD   )r0   r?   s   &&r   rE   Ú_HausdorffERLossBase.get_kernelW   s
   € ô "Ð!r   c               ó    € V ^8„  d   QhRRRR/# )r   ÚxrQ   r   r   )r   s   "r   r   r   b   s   € ÷ ,ñ ,˜ð ,¨ñ ,r   c                ó.  € VP                   R,          p\        V P                  4       UUu. uF  q3V3 F  qDNK  	  K  	  ppp\        P                  ! W\
        P                  R7      pV P                   UUUU	u. uFX  pTR.\        V P                  Wr4       UUU	u. uF%  w  r8p	\        W8,           W8,           V	,           4      NK'  	  up	ppO5,          NKZ  	  p
pppp	\        P                  ! V
4      P                  ^ 4      # u uppi u up	ppi u up	pppi )aJ  Erode ``x`` once: the minimum over the structuring element, centred on each pixel.

Positions outside the image count as ``+inf``, so the image border is not an edge of the eroded set.

Args:
    x: floating-point map with a shape of ``(B, 1, H, W)`` or ``(B, 1, D, H, W)``.

Returns:
    The eroded map, with the shape of ``x``.
r   )Úvalue.)rH   Úreversedr.   ÚFÚpadr8   r9   rK   r-   Úslicer6   ÚstackÚamin)r0   rU   Úspatialr*   ÚprZ   ÚpaddedÚoffsetÚoÚnÚwindowss   &&         r   Ú_erodeÚ_HausdorffERLossBase._erodeb   sá   € ð —'‘'˜"•+ˆÜ" 4§<¡<Ô0ÔAÑ0�Q¸a»&°QŠq¹&‰qÑ0ˆÑAÜ—’�q¤T§X¡XÔ.ˆð Ÿ-š-ö
á'�ð �CÐfÄ#ÀdÇlÁlÐTZÔBdÕeÑBd±w°q¸Qœ5 ¥¨­°­	Ö2ÑBdÓeÑf×gÐgÙ'ð 	ó 
ô �{Š{˜7Ó#×(Ñ(¨Ó+Ð+ùó Bùô fùõ
s   ¬DÁ:"D
Â+DÃD
ÄD
c               ó$   € V ^8„  d   QhRRRRRR/# ©r   ÚpredrQ   Útargetr   r   )r   s   "r   r   r   w   s!   € ÷ ñ  Lð ¸,ð È<ñ r   c                óœ  € W,
          ^,          \         ,
          ^\         ,
          ,          pVP                  ^ 4      pV^ 8„  P                  VP                  4      p\        P
                  ! V4      p\        V P                  4       F;  pV P                  V4      pWTV^,           V P                  ,          ,          ,           pK=  	  W5,          # )aV  Return the per-pixel loss of one class channel.

Args:
    pred: probabilities of the class with a shape of ``(B, 1, H, W)`` or ``(B, 1, D, H, W)``.
    target: the binary map of the class, of the same shape.

Returns:
    ``error * sum_i (i + 1) ** alpha * erode^(i + 1)(error > 0)`` for ``i = 0, ..., k - 1``, of the shape of
    ``pred``.
)
Ú_MISCLASSIFIED_SQUARED_ERRORÚ	clamp_minÚtor?   r6   Ú
zeros_likeÚranger   re   r   )r0   ri   rj   ÚerrorÚ	survivorsÚweightr)   s   &&&    r   Úperform_erosionÚ$_HausdorffERLossBase.perform_erosionw   s›   € ð •- AÕ%Ô(DÕDÈÔMiÕIiÕjˆØ—‘ Ó"ˆð
 ˜Q‘Y—N‘N 5§;¡;Ó/ˆ	Ü×!Ò! %Ó(ˆÜ�t—v‘v–ˆAØŸ™ IÓ.ˆIØ¨1¨q­5°T·Z±ZÕ*?Õ?Õ?ŠFñ ð �~Ðr   c               ó$   € V ^8„  d   QhRRRRRR/# rh   r   )r   s   "r   r   r   ’   s!   € ÷ 4ñ 4˜Lð 4°,ð 4À<ñ 4r   c                ó†  € \        W4       VP                  R,          VP                  R,          8X  d<   VP                  ^ 4      VP                  ^ 4      8X  d   VP                  ^4      ^8X  g'   \        RVP                   RVP                   R24      hVP                  \
        P                  8w  d,   \        RVP                  ^4       RVP                   R24      h\        4       '       g�   VP                  4       ^ 8”  dz   VP                  4       VP                  ^4      8  d   VP                  4       ^ 8¼  gA   \        RVP                  ^4       RVP                  4        RVP                  4        R	24      h\
        P                  ! \        VP                  ^4      4       Uu. uF”  pV P                  VR
W3^,           13,          \
        P                  ! W#8H  \
        P                  ! ^VP                   VP                  R7      \
        P                  ! ^ VP                   VP                  R7      4      4      NK–  	  up4      pV P"                  R8X  d   VP%                  4       pV# V P"                  R8X  d   VP'                  4       pV# V P"                  R8X  d    V# \)        RV P"                   R24      hu upi )a3  Compute Hausdorff loss.

Args:
    pred: predicted torch.Tensor with a shape of ``(B, C, H, W)`` or ``(B, C, D, H, W)``.
        Each channel is as binary as: 1 -> fg, 0 -> bg.
    target: target torch.Tensor with a shape of ``(B, 1, H, W)`` or ``(B, 1, D, H, W)``.

Returns:
    Estimated Hausdorff Loss.

r   zTPrediction and target need to be of same size, and target should not be one-hot.Got z and r   z+Expect long type target value in range [0, z). Got z). (z, Ú):NNN)Údevicer?   r1   r2   r3   r   r   )r   rH   r#   r;   r?   r6   Úlongr   ÚnumelÚmaxÚminr\   rp   rt   ÚwhereÚtensorry   r   r1   r2   rD   )r0   ri   rj   r)   Úouts   &&&  r   ÚforwardÚ_HausdorffERLossBase.forward’   sU  € ô 	! Ô.à—
‘
˜2• &§,¡,¨rÕ"2Ô2°t·y±yÀ³|ÀvÇ{Á{ÐSTÃ~Ô7UÐZ`×ZeÑZeÐfgÓZhÐlmÔZmÜðØ—z‘z�l %¨¯© ~°Qð8óð ð
 �<‰<œ5Ÿ:™:Ô%ÜÐJÈ4Ï9É9ÐUVË<È.ÐX_Ð`f×`lÑ`lÐ_mÐmnÐoÓpÐpô �~Š~ &§,¡,£.°1Ô"4¸f¿j¹j»lÈTÏYÉYÐWXË\Ô>YÐ^d×^hÑ^hÓ^jÐnoÔ^oÜØ=¸d¿i¹iÈ»l¸^È4ÐPV×PZÑPZÓP\È~Ð]_Ð`f×`jÑ`jÓ`lÐ_mÐmnÐoóð ô �kŠkô ˜tŸy™y¨›|Ô,ó
ñ -�Að ×$Ñ$Ø˜˜A A¥˜I˜Õ&Ü—K’KØ™ÜŸš Q¨v¯}©}ÀFÇLÁLÔQÜŸš Q¨v¯}©}ÀFÇLÁLÔQóöñ -ñ
ó
ˆð �>‰>˜VÔ#Ø—(‘(“*ˆCð ˆ
ð �^‰^˜uÔ$Ø—'‘'“)ˆCð ˆ
ð �^‰^˜vÔ%Øð ˆ
ô &¨°D·N±NÐ3CÐCbÐ&cÓdÐdùò)
s   Æ*BJ>)rK   r.   r   r   r   )g       @é
   r1   r(   )rC   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r5   rE   re   rt   r�   Ú__static_attributes__Ú__classcell__©rM   s   @r   r	   r	   #   s,   ø† ñ÷&
ò 
÷@	"õ,õ*÷64ó 4r   r	   c                  óB   a € ] tR t^ÉtRtRR R lltR V 3R lltRtV ;t# )ÚHausdorffERLossa’  Compute the erosion-based Hausdorff loss of ``(B, C, H, W)`` probabilities against ``(B, 1, H, W)`` labels.

``criterion = HausdorffERLoss(alpha, k, reduction)`` stores its arguments, and ``loss = criterion(pred, target)``
scores, for each class channel ``c``, a surrogate of the Hausdorff distance between the predicted and the labelled
segmentation, after ``Loss_ER`` of :cite:`karimi2019reducing` (Eq. 12): the per-pixel error :math:`e`, weighted
by the ``k`` successive erosions :math:`\varepsilon` of the misclassified set that keep the pixel:

.. math::

    \mathcal{L} = e \sum_{i=1}^{k} i^\alpha \, \varepsilon^i([e > 0]), \qquad
    e = \max\left(\frac{(p_c - [y = c])^2 - 1/4}{3/4},\ 0\right)

Convention:
    - ``pred`` holds per-class probabilities ``(B, C, H, W)`` and nothing is applied to it, unlike the logits of
      :func:`~kornia.losses.focal_loss`: pass a softmax. ``target`` holds int64 labels ``(B, 1, H, W)`` in
      ``[0, C)``. Channel ``c`` is compared with ``target == c``, class 0 included.
    - The ``[0, C)`` check reads the data, so it is skipped wherever the call captures a graph
      (``torch.compile`` or ``torch.export``). A captured call whose target holds an out-of-range label scores
      those voxels in no class and returns a finite loss instead of raising; an eager call still raises.
    - The default ``'mean'`` is the plain mean of the ``'none'`` tensor.
    - :math:`e` is nonzero exactly where thresholding :math:`p_c` at 0.5 gets the pixel wrong,
      :math:`|p_c - [y = c]| > 1/2`, and is 1 for a fully wrong pixel. A correct pixel adds nothing and gets no
      gradient, however uncertain; a probability of exactly 0.5 counts as correct. With two classes this is the
      argmax decision. With three or more it is a one-vs-rest margin, stricter than argmax: a pixel whose true
      class wins the argmax with :math:`p_c < 1/2` still counts in channel :math:`c`.
    - :math:`\varepsilon` takes the minimum over the pixel and its four neighbours. Pixels outside the image count
      as :math:`+\infty`, so the image border is not an edge of an error.
    - The weight of a misclassified pixel is :math:`\sum_{i=1}^{\min(k, d - 1)} i^\alpha`, for its city-block
      distance :math:`d` to the nearest correctly classified pixel. It is a constant: the gradient reaches each
      misclassified pixel through :math:`e`, in proportion to that weight. The pixels on the edge of an error
      (:math:`d = 1`) get none, and errors at most two pixels wide add nothing.
    - The weight measures how thick an error is, not how far it lies from the target, so a thin or small error
      far from the object, which can set the Hausdorff distance, adds little or nothing
      (`#6680 <https://github.com/kornia/kornia/issues/6680>`_).
    - Use it as an auxiliary term next to an overlap loss, never alone, as the paper does:
      ``region_loss + lam * hausdorff_loss``, with ``lam`` set so that both terms weigh the same (the paper
      recomputes it from their means after each epoch) or ramped up from a small value. Choose ``k`` from the
      expected error radius in pixels: an error deeper than ``k`` gets the same weight as one ``k`` deep.
    - The value is a unitless surrogate, at most :math:`\sum_{i=1}^{k} i^\alpha` per pixel (385 at the
      defaults), not a distance in pixels.
    - The paper erodes :math:`(p_c - [y = c])^2` itself, by a convolution followed by a soft threshold at 0.5,
      which leaves nothing of a solid error after two erosions and ignores misclassified pixels whose
      neighbourhood-averaged squared error is below 1/2. On a binary prediction this loss equals the exact
      erosion of :math:`e` (`#6676 <https://github.com/kornia/kornia/issues/6676>`_).

Args:
    alpha: exponent of the weight :math:`(i + 1)^\alpha` of erosion :math:`i = 0, \dots, k - 1`.
    k: number of erosions.
    reduction: ``'mean'`` (default), ``'sum'`` or ``'none'``.

Shape:
    - pred: probabilities ``(B, C, H, W)``.
    - target: int64 class labels ``(B, 1, H, W)``.
    - Output: a scalar for ``'mean'`` and ``'sum'``, ``(C, B, 1, H, W)`` for ``'none'``.

See Also:
    - :class:`~kornia.losses.HausdorffERLoss3D`: the same loss for volumes.
    - :class:`~kornia.losses.DiceLoss`: an overlap loss that takes logits, not probabilities.

Examples:
    >>> hdloss = HausdorffERLoss()
    >>> input = torch.randn(5, 3, 20, 20).softmax(1)
    >>> target = (torch.rand(5, 1, 20, 20) * 2).long()
    >>> res = hdloss(input, target)

    Next to :class:`~kornia.losses.DiceLoss`, which takes the logits and ``(B, H, W)`` labels:

    >>> logits = torch.randn(5, 3, 20, 20)
    >>> loss = kornia.losses.DiceLoss()(logits, target[:, 0]) + 0.1 * hdloss(logits.softmax(1), target)

c               ó    € V ^8„  d   QhRRRR/# rP   r   )r   s   "r   r   ÚHausdorffERLoss.__annotate__  s   € ÷ ñ Ð 2ð ¸lñ r   c                ó–   € \         P                  ! . RO. RO. RO..VR7      pV\         P                  ! RVR7      ,          pVR,          # )z˜Get the structuring element of the erosion: the pixel and its four neighbours.

Args:
    dtype: dtype of the kernel; ``None`` gives the default dtype.
©r?   gš™™™™™É?N©r   r!   r   ©r!   r!   r!   )r6   r   )r0   r?   Úcrossr   s   &&  r   rE   ÚHausdorffERLoss.get_kernel  s=   € ô —’šyª)²YÐ?Ð@ÈÔNˆØœŸš c°Ô7Õ7ˆØ�d�|Ðr   c               ó$   € V ^8„  d   QhRRRRRR/# rh   r   )r   s   "r   r   rŽ     ó!   € ÷ -ñ -˜Lð -°,ð -À<ñ -r   c                óf  <€ \        V\        P                  4      '       g   \        R\	        V4       R24      h\        V\        P                  4      '       g   \        R\	        V4       R24      hVP                  4       ^8w  d   \        RVP                  4        R24      h\        SV `!  W4      # )a  Compute Hausdorff loss.

Args:
    pred: predicted torch.Tensor with a shape of ``(B, C, H, W)``.
        Each channel is as binary as: 1 -> fg, 0 -> bg.
    target: target torch.Tensor with a shape of ``(B, 1, H, W)``.

Returns:
    Estimated Hausdorff Loss.

ú%pred type is not a torch.Tensor. Got r   ú'target type is not a torch.Tensor. Got zOnly 2D images supported. Got ©	r<   r6   r>   r@   rB   Údimr;   r4   r�   ©r0   ri   rj   rM   s   &&&€r   r�   ÚHausdorffERLoss.forward  ó‘   ø€ ô ˜$¤§¡×-Ò-ÜÐCÄDÈÃJÀ<ÈqÐQÓRÐRÜ˜&¤%§,¡,×/Ò/ÜÐEÄdÈ6ÃlÀ^ÐSTÐUÓVÐVØ�8‰8‹:˜Œ?ÜÐ=¸d¿h¹h»j¸\ÈÐKÓLÐLä‰w‰˜tÓ,Ð,r   r   r(   ©	rC   r„   r…   r†   r‡   rE   r�   rˆ   r‰   rŠ   s   @r   rŒ   rŒ   É   s   ø† ñF÷P÷-ö -r   rŒ   c                  óB   a € ] tR tRtRtRR R lltR V 3R lltRtV ;t# )	ÚHausdorffERLoss3Di2  aã  Compute the erosion-based Hausdorff loss of ``(B, C, D, H, W)`` probabilities against volume labels.

``criterion = HausdorffERLoss3D(alpha, k, reduction)`` stores its arguments, and
``loss = criterion(pred, target)`` is :class:`~kornia.losses.HausdorffERLoss` on volumes :cite:`karimi2019reducing`.

Convention:
    - See the Convention block of :class:`~kornia.losses.HausdorffERLoss`. The erosion takes the minimum over the
      voxel and its six face neighbours, so it also runs along ``D``, and the distance :math:`d` is the city-block
      distance in the volume.

Args:
    alpha: exponent of the weight :math:`(i + 1)^\alpha` of erosion :math:`i = 0, \dots, k - 1`.
    k: number of erosions.
    reduction: ``'mean'`` (default), ``'sum'`` or ``'none'``.

Shape:
    - pred: probabilities ``(B, C, D, H, W)``.
    - target: int64 class labels ``(B, 1, D, H, W)``.
    - Output: a scalar for ``'mean'`` and ``'sum'``, ``(C, B, 1, D, H, W)`` for ``'none'``.

See Also:
    - :class:`~kornia.losses.HausdorffERLoss`: the same loss for images.

Examples:
    >>> hdloss = HausdorffERLoss3D()
    >>> input = torch.randn(5, 3, 20, 20, 20).softmax(1)
    >>> target = (torch.rand(5, 1, 20, 20, 20) * 2).long()
    >>> res = hdloss(input, target)

c               ó    € V ^8„  d   QhRRRR/# rP   r   )r   s   "r   r   ÚHausdorffERLoss3D.__annotate__R  s   € ÷ 	ñ 	Ð 2ð 	¸lñ 	r   c                ó  € \         P                  ! . RO. RO. RO..VR7      p\         P                  ! . RO. RO. RO..VR7      p\         P                  ! W2V.^4      \         P                  ! RVR7      ,          pVR,          # )zœGet the structuring element of the erosion: the voxel and its six face neighbours.

Args:
    dtype: dtype of the kernel; ``None`` gives the default dtype.
r�   Nr‘   r’   )r   r   r   g’$I’$IÂ?)r6   r   r\   )r0   r?   r“   Úboundr   s   &&   r   rE   ÚHausdorffERLoss3D.get_kernelR  sh   € ô —’šyª)²YÐ?Ð@ÈÔNˆÜ—’šyª)²YÐ?Ð@ÈÔNˆÜ—’˜e¨EÐ2°AÓ6¼¿ºÀeÐSXÔ9YÕYˆØ�d�|Ðr   c               ó$   € V ^8„  d   QhRRRRRR/# rh   r   )r   s   "r   r   r£   ]  r–   r   c                óf  <€ \        V\        P                  4      '       g   \        R\	        V4       R24      h\        V\        P                  4      '       g   \        R\	        V4       R24      hVP                  4       ^8w  d   \        RVP                  4        R24      h\        SV `!  W4      # )a  Compute 3D Hausdorff loss.

Args:
    pred: predicted torch.Tensor with a shape of ``(B, C, D, H, W)``.
        Each channel is as binary as: 1 -> fg, 0 -> bg.
    target: target torch.Tensor with a shape of ``(B, 1, D, H, W)``.

Returns:
    Estimated Hausdorff Loss.

r˜   r   r™   zOnly 3D images supported. Got rš   rœ   s   &&&€r   r�   ÚHausdorffERLoss3D.forward]  rž   r   r   r(   rŸ   rŠ   s   @r   r¡   r¡   2  s   ø† ñ÷>	÷-ö -r   r¡   )Ú
__future__r   r8   rA   r6   Útorch.nn.functionalr   Ú
functionalrY   Úkornia.core.checkr   Úkornia.core.opsr   Úkornia.core.utilsr   rl   ÚModuler	   rŒ   r¡   r   r   r   Ú<module>r±      s]   ðõ$ #ã Û ã ß Ð Ý å 6Ý *Ý *ð  $Ð ôc˜2Ÿ9™9ô côLf-Ð*ô f-ôR>-Ð,ö >-r   