§
    ’©ºjØÃ  ã                   ó¸  — d dl Z d dlZd dlmZmZ d dlZd dlmZ d dlmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ ded	ed
eeef         fd„Zded	ed
dfd„Z	 	 d8ded	ededee         ded         d
eeef         fd„Zdeded
efd„Zded
efd„Zded
dfd„Zdedeedf         d
efd„Zdeded
efd„Z	 d9dedee         d eeedf                  d!ed
ef
d"„Z	 	 	 d:ded%eeeee         f                  d&ed'         d(ed)         d
ef
d*„Z 	 	 d;ded	ed,ed-eeeeef         eeeef         f                  d
eeeef         eeeeef         f         f
d.„Z!	 	 d<ded	ed/ed'         d-eeeee         f                  d
ef
d0„Z"	 	 	 d=ded	ed/ed'         d-eeeee         f                  d2ed
eeeeef         f         fd3„Z#e j$        	 d>d-eeeef         eeeef         f         d4eej%                 d
eeef         fd5„¦   «         Z&d>d-eeef         d4eej%                 d
eeef         fd6„Z'e j$        d>d-eeeef         d4eej%                 d
eeef         fd7„¦   «         Z(dS )?é    N)ÚOptionalÚUnion)ÚTensor)Úconv2dÚconv3dÚpadÚunfold)ÚLiteral)Ú_check_same_shape)Ú_SCIPY_AVAILABLEÚpredsÚtargetÚreturnc                 óŽ   — | j         d         dk    r| dd…dd…f         n| } |j         d         dk    r|dd…dd…f         n|}| |fS )zQIgnore the background class in the computation assuming it is the first, index 0.é   N©Úshape©r   r   s     úz/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/segmentation/utils.pyÚ_ignore_backgroundr      s^   € à!œK¨œN¨QÒ.Ð.ˆE�!�!�!�Q�R�R�%ŒLˆL°E€EØ$œl¨1œo°Ò1Ð1ˆV�A�A�A�q�r�r�EŒ]ˆ]°v€FØ�&ˆ=Ðó    c                 ón  — |                       ¦   «         |                      ¦   «         dz   k    r^| j        d         |j        d         k    s | j        dd…         |j        dd…         k    r t          d| j        › d|j        › d�¦  «        ‚dS |                       ¦   «         dz   |                      ¦   «         k    r^| j        d         |j        d         k    s | j        dd…         |j        dd…         k    r t          d| j        › d|j        › d�¦  «        ‚dS t          d| j        › d|j        › d�¦  «        ‚)zHCheck that predictions and target have the same shape, else raise error.r   r   é   NzAPredictions and targets are expected to have the same shape, got ú and ú.)Údimr   ÚRuntimeErrorr   s     r   Ú_check_mixed_shaper   "   sY  € à‡y‚y�{„{�v—z’z‘|”| aÑ'Ò(Ð(ØŒ;�qŒ>˜Vœ\¨!œ_Ò,Ð,°´¸A¸B¸B´À6Ä<ÐPQÐPRÐPRÔCSÒ0SÐ0SÝØuÐTYÔT_ÐuÐuÐflÔfrÐuÐuÐuñô ð ð 1TÐ0Sð �)Š)‰+Œ+˜‰/˜fŸjšj™lœlÒ	*Ð	*ØŒ;�qŒ>˜Vœ\¨!œ_Ò,Ð,°´¸A¸B¸B´À6Ä<ÐPQÐPRÐPRÔCSÒ0SÐ0SÝØuÐTYÔT_ÐuÐuÐflÔfrÐuÐuÐuñô ð ð 1TÐ0Sõ
 ØqÐPUÔP[ÐqÐqÐbhÔbnÐqÐqÐqñ
ô 
ð 	
r   úone-hotÚinclude_backgroundÚnum_classesÚinput_format)r   ÚindexÚmixedc                 ó„  — |dk    rt          | |¦  «         nt          | |¦  «         |dk    r‡|€t          d¦  «        ‚t          j        j                             | |¬¦  «                             dd¦  «        } t          j        j                             ||¬¦  «                             dd¦  «        }�nQ|dk    r3|€t          | ¦  «        }t          | |¦  «        } t          ||¦  «        }�n|dk    �r|  
                    ¦   «         | 
                    ¦   «         dz   k    r\|€t          | ¦  «        }t          | |¦  «        } t          j        j                             ||¬¦  «                             dd¦  «        }nˆ|  
                    ¦   «         dz   | 
                    ¦   «         k    r[|€t          |¦  «        }t          ||¦  «        }t          j        j                             | |¬¦  «                             dd¦  «        } | j        d	k     rt          d
| j        › d�¦  «        ‚|st          | |¦  «        \  } }| |fS )z1Check and format inputs to the one-hot encodings.r$   r#   NzDArgument `num_classes` must be provided when `input_format='index'`.©r!   éÿÿÿÿr   r   é   zJExpected both `preds` and `target` to have at least 3 dimensions, but got r   )r   r   Ú
ValueErrorÚtorchÚnnÚ
functionalÚone_hotÚmovedimÚ_get_num_classesÚ_format_logitsr   Úndimr   )r   r   r    r!   r"   s        r   Ú_segmentation_inputs_formatr2   4   s,  € ð �wÒÐÝ˜5 &Ñ)Ô)Ð)Ð)å˜% Ñ(Ô(Ð(à�wÒÐØÐÝÐcÑdÔdÐdÝ”Ô#×+Ò+¨E¸{Ð+ÑKÔK×SÒSÐTVÐXYÑZÔZˆÝ”Ô$×,Ò,¨VÀÐ,ÑMÔM×UÒUÐVXÐZ[Ñ\Ô\ˆ‰Ø	˜Ò	"Ð	"ØÐÝ*¨5Ñ1Ô1ˆKÝ˜u kÑ2Ô2ˆÝ ¨Ñ4Ô4ˆ‰Ø	˜Ò	 Ñ	 Ø�9Š9‰;Œ;˜6Ÿ:š:™<œ<¨!Ñ+Ò,Ð,ØÐ"Ý.¨uÑ5Ô5�Ý" 5¨+Ñ6Ô6ˆEÝ”XÔ(×0Ò0°À[Ð0ÑQÔQ×YÒYÐZ\Ð^_Ñ`Ô`ˆFˆFØ�iŠi‰kŒk˜A‰o &§*¢*¡,¤,Ò.Ð.ØÐ"Ý.¨vÑ6Ô6�Ý# F¨KÑ8Ô8ˆFÝ”HÔ'×/Ò/°À;Ð/ÑOÔO×WÒWÐXZÐ\]Ñ^Ô^ˆEà„z�A‚~€~ÝÐsÐfkÔfpÐsÐsÐsÑtÔtÐtàð :Ý*¨5°&Ñ9Ô9‰ˆˆvà�&ˆ=Ðr   Útensorc                 óÎ   — t          j        | ¦  «        rP|                      d¬¦  «        } t           j        j                             | |¬¦  «                             dd¦  «        } | S )zATransform logits or probabilities into integer one-hot encodings.r   ©r   r&   r'   )r*   Úis_floating_pointÚargmaxr+   r,   r-   r.   )r3   r!   s     r   r0   r0   `   s]   € åÔ˜vÑ&Ô&ð ]Ø—’ 1�Ñ%Ô%ˆÝ”Ô$×,Ò,¨VÀÐ,ÑMÔM×UÒUÐVXÐZ[Ñ\Ô\ˆØ€Mr   c                 ó¢   — 	 | j         d         }n&# t          $ r}t          d| › d�¦  «        |‚d}~ww xY w|dk    rt          d|› d�¦  «        ‚|S )z/Get num classes from a tensor if it is not set.r   z,Cannot determine `num_classes` from tensor: r   Nr   zBExpected argument `num_classes` to be a positive integer, but got )r   Ú
IndexErrorr)   )r3   r!   Úerrs      r   r/   r/   h   s�   € ð\Ø”l 1”oˆˆøÝð \ð \ð \ÝÐQÈÐQÐQÐQÑRÔRÐX[Ð[øøøøð\øøøà�aÒÐÝÐlÐ^iÐlÐlÐlÑmÔmÐmØÐs   ‚ �
3š.®3Úxc                 óx   — t          j        |                      ¦   «         | k    ¦  «        st          d¦  «        ‚dS )zÛCheck if tensor is binarized.

    Example:
        >>> from torchmetrics.functional.segmentation.utils import check_if_binarized
        >>> import torch
        >>> check_if_binarized(torch.tensor([0, 1, 1, 0]))

    zInput x should be binarizedN)r*   ÚallÚboolr)   )r;   s    r   Úcheck_if_binarizedr?   s   s;   € õ Œ9�Q—V’V‘X”X ’]Ñ#Ô#ð 8ÝÐ6Ñ7Ô7Ð7ð8ð 8r   Úkernel_size.c                 ó„  — | j         dd…         \  }}| j        dz
  }|dk    rt          | |¦  «        S |d         |d         z  |d         z  }|dgd„ |D ¦   «         z   }t          j        || j        | j        ¬¦  «        }  |j        |dg|¢R Ž j        |Ž }t          | |d¬¦  «        }|                     |||z  d¦  «        S )	a.  Unfold the input tensor to a matrix. Function supports 3d images e.g. (B, C, D, H, W).

    Inspired by:
    https://github.com/f-dangel/unfoldNd/blob/main/unfoldNd/unfold.py

    Args:
        x: Input tensor to be unfolded.
        kernel_size: The size of the sliding blocks in each dimension.

    Nr   r   r   c                 ó   — g | ]}d ‘ŒS ©r   © ©Ú.0Ú_s     r   ú
<listcomp>z_unfold.<locals>.<listcomp>‘   s   € Ð5Ð5Ð5 A˜aÐ5Ð5Ð5r   ©ÚdeviceÚdtype)ÚweightÚbiasr'   )
r   r1   r	   r*   ÚeyerJ   rK   ÚreshapeÚrepeatr   )	r;   r@   Ú
batch_sizeÚchannelsÚnÚkernel_size_numelrP   rL   Úunfold_xs	            r   Ú_unfoldrV   €   sè   € ð œ7 2 A 2œ;Ñ€J�Ø	Œ�‰
€AØˆA‚v€vÝ�a˜Ñ%Ô%Ð%à# Aœ¨°Q¬Ñ7¸+Àa¼.ÑHÐØ˜ˆ]Ð5Ð5¨Ð5Ñ5Ô5Ñ5€FÝŒYÐ(°´ÀÄÐIÑIÔI€FØFˆ^ˆVŒ^Ð-¨qÐ?°;Ð?Ð?Ð?ÔFÈÐO€FÝ�a ¨TÐ2Ñ2Ô2€HØ×Ò˜J¨Ð3DÑ(DÀbÑIÔIÐIr   ÚrankÚconnectivityc                 óH  — |dk     rd}| dk     r!t          j        dgt           j        ¬¦  «        S t          j        d„ t	          | ¦  «        D ¦   «         d¬¦  «        }t          j        t          j        |d¬¦  «        dz
  ¦  «        }t          j        |d¬¦  «        }||k    S )a  Translated version of the function from scipy.ndimage.morphology.

    Args:
        rank: The rank of the structuring element.
        connectivity: The number of neighbors connected to a given pixel.

    Returns:
        The structuring element.

    Examples::
        >>> from torchmetrics.functional.segmentation.utils import generate_binary_structure
        >>> import torch
        >>> generate_binary_structure(2, 1)
        tensor([[False,  True, False],
                [ True,  True,  True],
                [False,  True, False]])
        >>> generate_binary_structure(2, 2)
        tensor([[True,  True,  True],
                [True,  True,  True],
                [True,  True,  True]])
        >>> generate_binary_structure(3, 2)  # doctest: +NORMALIZE_WHITESPACE
        tensor([[[False,  True, False],
                 [ True,  True,  True],
                 [False,  True, False]],
                [[ True,  True,  True],
                 [ True,  True,  True],
                 [ True,  True,  True]],
                [[False,  True, False],
                 [ True,  True,  True],
                 [False,  True, False]]])

    r   )rK   c                 ó6   — g | ]}t          j        d ¦  «        ‘ŒS )r(   )r*   ÚarangerE   s     r   rH   z-generate_binary_structure.<locals>.<listcomp>½   s    € ÐAÐAÐA°�EœL¨™OœOÐAÐAÐAr   Úij)Úindexingr   r5   )r*   r3   Úuint8ÚmeshgridÚrangeÚabsÚstackÚsum)rW   rX   ÚgridsÚoutputs       r   Úgenerate_binary_structurerf   ˜   s¢   € ðB �aÒÐØˆØˆa‚x€xÝŒ|˜Q˜C¥u¤{Ð3Ñ3Ô3Ð3ÝŒNÐAÐAµU¸4±[´[ÐAÑAÔAÈDÐQÑQÔQ€EÝŒY•u”{ 5¨aÐ0Ñ0Ô0°1Ñ4Ñ5Ô5€FÝŒY�v 1Ð%Ñ%Ô%€FØ�\Ò!Ð!r   ÚimageÚ	structureÚoriginÚborder_valuec           	      ó€  ‡‡— t          | t          ¦  «        st          dt          | ¦  «        › �¦  «        ‚| j        dvrt          d| j        › �¦  «        ‚t          | ¦  «         ‰€Bt          | j        dz
  d¦  «                             ¦   «          	                    | j
        ¦  «        Št          ‰¦  «         ‰€
‰j        dz  Št          | ˆˆfd„t          t          ‰¦  «        ¦  «        D ¦   «         d	|¬
¦  «        }t          |                     ¦   «         ‰j        ¬¦  «        }t#          j        ‰¦  «                             d¦  «                             d¦  «        }||                     ¦   «         z
  }|                     d¬¦  «        \  }}	t#          j        || j        ¦  «        dz                        ¦   «         S )a¦  Binary erosion of a tensor image.

    Implementation inspired by answer to this question: https://stackoverflow.com/questions/56235733/

    Args:
        image: The image to be eroded, must be a binary tensor with shape ``(batch_size, channels, height, width)``.
        structure: The structuring element used for the erosion. If no structuring element is provided, an element
            is generated with a square connectivity equal to one.
        origin: The origin of the structuring element.
        border_value: The value to be used for the border.

    Examples::
        >>> from torchmetrics.functional.segmentation.utils import binary_erosion
        >>> import torch
        >>> image = torch.tensor([[[[0, 0, 0, 0, 0],
        ...                         [0, 1, 1, 1, 0],
        ...                         [0, 1, 1, 1, 0],
        ...                         [0, 1, 1, 1, 0],
        ...                         [0, 0, 0, 0, 0]]]])
        >>> binary_erosion(image)
        tensor([[[[0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0],
                  [0, 0, 1, 0, 0],
                  [0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0]]]], dtype=torch.uint8)
        >>> binary_erosion(image, structure=torch.ones(4, 4))
        tensor([[[[0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0]]]], dtype=torch.uint8)

    z9Expected argument `image` to be of type Tensor but found )é   é   z>Expected argument `image` to be of rank 4 or 5 but found rank Nr   r   rC   c                 ó\   •— g | ](}‰|         ‰j         |         ‰|         z
  d z
  fD ]}|‘ŒŒ)S rC   r   )rF   Úir;   ri   rh   s      €€r   rH   z"binary_erosion.<locals>.<listcomp>ø   sH   ø€ Ð`Ð`Ð`ˆq°¸´¸I¼OÈAÔ<NÐQWÐXYÔQZÑ<ZÐ]^Ñ<^Ð0_Ð`Ð`¨1ˆÐ`Ð`Ð`Ð`r   Úconstant)ÚmodeÚvalue)r@   r   r'   r5   )Ú
isinstancer   Ú	TypeErrorÚtyper1   r)   r?   rf   ÚintÚtorJ   r   r`   ÚlenrV   Úfloatr   r*   ÚflattenÚ	unsqueezeÚminrO   Úbyte)
rg   rh   ri   rj   Ú	image_padÚimage_unfoldÚstrel_flattenÚsumsÚresultrG   s
    ``       r   Úbinary_erosionrƒ   Ã   s¯  øø€ õH �e�VÑ$Ô$ð cÝÐaÕTXÐY^ÑT_ÔT_ÐaÐaÑbÔbÐbØ„z˜ÐÐÝÐfÐZ_ÔZdÐfÐfÑgÔgÐgÝ�uÑÔÐð ÐÝ-¨e¬j¸1©n¸aÑ@Ô@×DÒDÑFÔF×IÒIÈ%Ì,ÑWÔWˆ	Ý�yÑ!Ô!Ð!à€~Ø” $Ñ&ˆõ ØØ`Ð`Ð`Ð`Ð`•E�#˜f™+œ+Ñ&Ô&Ð`Ñ`Ô`ØØð	ñ ô €Iõ ˜9Ÿ?š?Ñ,Ô,¸)¼/ÐJÑJÔJ€Lå”M )Ñ,Ô,×6Ò6°qÑ9Ô9×CÒCÀBÑGÔG€MØ˜-×+Ò+Ñ-Ô-Ñ-€Dð —’˜Q�‘”�I€FˆAõ ŒM˜& %¤+Ñ.Ô.°Ñ2×8Ò8Ñ:Ô:Ð:r   Ú	euclideanÚpytorchÚsamplingÚmetric©r„   Ú
chessboardÚtaxicabÚengine©r…   Úscipyc                 óâ  — t          | t          ¦  «        s t          dt          | ¦  «        › d�¦  «        ‚| j        dk    rt          d| j        › d�¦  «        ‚|�5t          |t
          ¦  «        s t          dt          |¦  «        › d�¦  «        ‚|dvrt          d|› d�¦  «        ‚|d	vrt          d
|› d�¦  «        ‚|€ddg}n3t          |¦  «        dk    r t          dt          |¦  «        › d�¦  «        ‚|dk    �rÚ|                      ¦   «         } t          j	        | dk    ¦  «        \  }}t          j	        | dk    ¦  «        \  }}| 
                    dd¦  «        | 
                    dd¦  «        z
                       ¦   «         }| 
                    dd¦  «        | 
                    dd¦  «        z
                       ¦   «         }	| j        \  }
}|dk    r/|d         |z  dz  |d         |	z  dz  z                        ¦   «         }|dk    r9t          j        |d         |z  |d         |	z  ¦  «                             ¦   «         }|dk    r)|d         |z  |d         |	z  z                        ¦   «         }t          j        |d¬¦  «        \  }}t          j        | ¦  «         
                    d¦  «        }||||
z  |z   <   | 
                    | j        ¦  «        S t"          st          d¦  «        ‚ddlm} |dk    r:|                     |                      ¦   «                              ¦   «         |¦  «        S |                     |                      ¦   «                              ¦   «         ||¬¦  «        S )a°  Calculate distance transform of a binary tensor.

    This function calculates the distance transform of a binary tensor, replacing each foreground pixel with the
    distance to the closest background pixel. The distance is calculated using the euclidean, chessboard or taxicab
    distance.

    The memory consumption of this function is in the worst cast N/2**2 where N is the number of pixel. Since we need
    to compare all foreground pixels to all background pixels, the memory consumption is quadratic in the number of
    pixels. The memory consumption can be reduced by using the ``scipy`` engine, which is more memory efficient but
    should also be slower for larger images.

    Args:
        x: The binary tensor to calculate the distance transform of.
        sampling: The sampling refers to the pixel spacing in the image, i.e. the distance between two adjacent pixels.
            If not provided, the pixel spacing is assumed to be 1.
        metric: The distance to use for the distance transform. Can be one of ``"euclidean"``, ``"chessboard"``
            or ``"taxicab"``.
        engine: The engine to use for the distance transform. Can be one of ``["pytorch", "scipy"]``. In general,
            the ``pytorch`` engine is faster, but the ``scipy`` engine is more memory efficient.

    Returns:
        The distance transform of the input tensor.

    Examples::
        >>> from torchmetrics.functional.segmentation.utils import distance_transform
        >>> import torch
        >>> x = torch.tensor([[0, 0, 0, 0, 0],
        ...                   [0, 1, 1, 1, 0],
        ...                   [0, 1, 1, 1, 0],
        ...                   [0, 1, 1, 1, 0],
        ...                   [0, 0, 0, 0, 0]])
        >>> distance_transform(x)
        tensor([[0., 0., 0., 0., 0.],
                [0., 1., 1., 1., 0.],
                [0., 1., 2., 1., 0.],
                [0., 1., 1., 1., 0.],
                [0., 0., 0., 0., 0.]])

    z<Expected argument `x` to be of type `torch.Tensor` but got `ú`.r   z4Expected argument `x` to be of rank 2 but got rank `NzLExpected argument `sampling` to either be `None` or of type `list` but got `rˆ   zZExpected argument `metric` to be one of `['euclidean', 'chessboard', 'taxicab']` but got `rŒ   zHExpected argument `engine` to be one of `['pytorch', 'scipy']` but got `r   z>Expected argument `sampling` to have length 2 but got length `r…   r   r'   r„   r‰   rŠ   r5   zhThe `scipy` engine requires `scipy` to be installed. Either install `scipy` or use the `pytorch` engine.)Úndimage)r‡   )rs   r   r)   ru   r1   Úlistrx   ry   r*   ÚwhereÚviewra   r   ÚsqrtÚmaxr|   Ú
zeros_liker   r�   r�   Údistance_transform_edtÚcpuÚnumpyÚdistance_transform_cdt)r;   r†   r‡   r‹   Úi0Új0Úi1Új1Údis_rowÚdis_colÚhrG   ÚdisÚmindisÚzr�   s                   r   Údistance_transformr¥   	  sƒ  € õZ �a�Ñ Ô ð eÝÐcÕX\Ð]^ÑX_ÔX_ÐcÐcÐcÑdÔdÐdØ„v�‚{€{ÝÐZÐPQÔPVÐZÐZÐZÑ[Ô[Ð[ØÐ¥J¨x½Ñ$>Ô$>ÐÝØmÕ[_Ð`hÑ[iÔ[iÐmÐmÐmñ
ô 
ð 	
ð Ð;Ð;Ð;ÝØsÐioÐsÐsÐsñ
ô 
ð 	
ð Ð)Ð)Ð)ÝÐnÐdjÐnÐnÐnÑoÔoÐoàÐØ�q�6ˆˆåˆx‰=Œ=˜AÒÐÝÐoÕ^aÐbjÑ^kÔ^kÐoÐoÐoÑpÔpÐpà�ÒÑØ�GŠG‰IŒIˆå”˜Q !šVÑ$Ô$‰ˆˆBÝ”˜Q !šVÑ$Ô$‰ˆˆBØ—7’7˜2˜q‘>”> B§G¢G¨A¨r¡N¤NÑ2×7Ò7Ñ9Ô9ˆØ—7’7˜2˜q‘>”> B§G¢G¨A¨r¡N¤NÑ2×7Ò7Ñ9Ô9ˆð Œw‰ˆˆ1Ø�[Ò Ð Ø˜Q”K 'Ñ)¨aÑ/°8¸A´;ÀÑ3HÈQÑ2NÑN×TÒTÑVÔVˆCØ�\Ò!Ð!Ý”)˜H QœK¨'Ñ1°8¸A´;ÀÑ3HÑIÔI×OÒOÑQÔQˆCØ�YÒÐØ˜A”; Ñ(¨8°A¬;¸Ñ+@Ñ@×GÒGÑIÔIˆCõ ”I˜c qÐ)Ñ)Ô)‰	ˆ�ÝÔ˜QÑÔ×$Ò$ RÑ(Ô(ˆØˆˆ"ˆq‰&�2‰+‰Ø�vŠv�a”g‰ŒÐåð 
ÝØvñ
ô 
ð 	
ð ÐÐÐÐÐà�ÒÐØ×-Ò-¨a¯eªe©g¬g¯mªm©o¬o¸xÑHÔHÐHØ×)Ò)¨!¯%ª%©'¬'¯-ª-©/¬/¸8ÈFÐ)ÑSÔSÐSr   TÚcropÚspacingc                 óö  — t          | |¦  «         | j        dvrt          d| j        › d�¦  «        ‚t          | ¦  «         t          |¦  «         |r{| |z  }|                     ¦   «         s.t          j        | ¦  «        t          j        |¦  «        }}||||fS t          | | j        ddgz  ¦  «        t          ||j        ddgz  ¦  «        }} |€˜t          |  	                    d¦  «         	                    d¦  «        ¦  «         
                    ¦   «         | z  }t          | 	                    d¦  «         	                    d¦  «        ¦  «         
                    ¦   «         |z  }||fS t          || j        ¬¦  «        \  }	}
t          |¦  «        }|dk    rt          nt          }t          j        |  	                    d¦  «        | 	                    d¦  «        gd¬	¦  «                             ¦   «         } |||
                     |¦  «        ¦  «        \  }}t          |	¦  «        dz
  }|dk    ||k    z  }|dk    ||k    z  }t          j        |	d|                     d
¦  «                             ¦   «         ¦  «                             |¦  «        }t          j        |	d|                     d
¦  «                             ¦   «         ¦  «                             |¦  «        }|d         |d         |d         |d         fS )a¬  Get the edges of binary segmentation masks.

    Args:
        preds: The predicted binary segmentation mask
        target: The ground truth binary segmentation mask
        crop: Whether to crop the edges to the region of interest. If ``True``, the edges are cropped to the bounding
        spacing: The pixel spacing of the input images. If provided, the edges are calculated using the euclidean

    Returns:
        If spacing is not provided, a 2-tuple containing the edges of the predicted and target mask respectively is
        returned. If spacing is provided, a 4-tuple containing the edges and areas of the predicted and target mask
        respectively is returned.

    )r   r(   z=Expected argument `preds` to be of rank 2 or 3 but got rank `r�   r   Nr   ©rJ   r   r5   r'   )r   r1   r)   r?   Úanyr*   r–   r   rƒ   r{   ÚsqueezeÚget_neighbour_tablesrJ   rx   r   r   rb   ry   rw   Úindex_selectr“   rv   Úview_as)r   r   r¦   r§   Úor_valÚpÚtÚbe_predÚ	be_targetÚtableÚkernelÚspatial_dimsÚconv_operatorÚvolumeÚ
code_predsÚcode_targetÚall_onesÚedges_predsÚedges_targetÚareas_predsÚareas_targets                        r   Ú
mask_edgesrÀ   m  sÍ  € õ( �e˜VÑ$Ô$Ð$Ø„z˜ÐÐÝÐgÐY^ÔYcÐgÐgÐgÑhÔhÐhÝ�uÑÔÐÝ�vÑÔÐàð [Ø˜‘ˆØ�zŠz‰|Œ|ð 	ÝÔ# EÑ*Ô*­EÔ,<¸VÑ,DÔ,DˆqˆAØ�a˜˜A�:Ðå˜E 5¤:°°A°Ñ#6Ñ7Ô7½¸VÀVÄ[ÐTUÐWXÐSYÑEYÑ9ZÔ9Zˆvˆà€å  §¢°Ñ!3Ô!3×!=Ò!=¸aÑ!@Ô!@ÑAÔA×IÒIÑKÔKÈeÑSˆÝ" 6×#3Ò#3°AÑ#6Ô#6×#@Ò#@ÀÑ#CÔ#CÑDÔD×LÒLÑNÔNÐQWÑWˆ	Ø˜	Ð!Ð!õ )¨¸¼ÐFÑFÔF�M€Eˆ6Ý�w‘<”<€LØ*¨aÒ/Ð/•F�FµV€MÝŒ[˜%Ÿ/š/¨!Ñ,Ô,¨f×.>Ò.>¸qÑ.AÔ.AÐBÈÐJÑJÔJ×PÒPÑRÔR€FØ+˜m¨F°F·I²I¸fÑ4EÔ4EÑFÔFÑ€J�õ �5‰zŒz˜A‰~€HØ ’? z°XÒ'=Ñ>€KØ 1Ò$¨¸Ò)@ÑA€Lõ Ô$ U¨A¨z¯ª¸rÑ/BÔ/B×/FÒ/FÑ/HÔ/HÑIÔI×QÒQÐR\Ñ]Ô]€KÝÔ% e¨Q°×0@Ò0@ÀÑ0DÔ0D×0HÒ0HÑ0JÔ0JÑKÔK×SÒSÐT_Ñ`Ô`€LØ�qŒ>˜<¨œ?¨K¸¬N¸LÈ¼OÐKÐKr   Údistance_metricc                 ó²  — | j         t          j        k    r|j         t          j        k    s t          d| j         › d|j         › d�¦  «        ‚t          j        |¦  «        s"t          j        t          j        |¦  «        z  }nPt          j        | ¦  «        s)t          j        t          j        | ¦  «        z  }||         S t          | ||¬¦  «        }||          S )aä  Calculate the surface distance between two binary edge masks.

    May return infinity if the predicted mask is empty and the target mask is not, or vice versa.

    Args:
        preds: The predicted binary edge mask.
        target: The target binary edge mask.
        distance_metric: The distance metric to use. One of `["euclidean", "chessboard", "taxicab"]`.
        spacing: The spacing between pixels along each spatial dimension.

    Returns:
        A tensor with length equal to the number of edges in predictions e.g. `preds.sum()`. Each element is the
        distance from the corresponding edge in `preds` to the closest edge in `target`.

    Example::
        >>> import torch
        >>> from torchmetrics.functional.segmentation.utils import surface_distance
        >>> preds = torch.tensor([[1, 1, 1, 1, 1],
        ...                       [1, 0, 0, 0, 1],
        ...                       [1, 0, 0, 0, 1],
        ...                       [1, 0, 0, 0, 1],
        ...                       [1, 1, 1, 1, 1]], dtype=torch.bool)
        >>> target = torch.tensor([[1, 1, 1, 1, 0],
        ...                        [1, 0, 0, 1, 0],
        ...                        [1, 0, 0, 1, 0],
        ...                        [1, 0, 0, 1, 0],
        ...                        [1, 1, 1, 1, 0]], dtype=torch.bool)
        >>> surface_distance(preds, target, distance_metric="euclidean", spacing=[1, 1])
        tensor([0., 0., 0., 0., 1., 0., 1., 0., 1., 0., 1., 0., 0., 0., 0., 1.])

    z9Expected both inputs to be of type `torch.bool`, but got r   r   )r†   r‡   )rK   r*   r>   r)   rª   ÚinfÚ	ones_liker¥   )r   r   rÁ   r§   r¢   s        r   Úsurface_distancerÅ   §  sÉ   € ðJ ŒK�5œ:Ò%Ð%¨&¬,½%¼*Ò*DÐ*DÝÐvÐUZÔU`ÐvÐvÐgmÔgsÐvÐvÐvÑwÔwÐwåŒ9�VÑÔð TÝŒi�%œ/¨&Ñ1Ô1Ñ1ˆˆåŒy˜ÑÔð 	Ý”)�eœo¨eÑ4Ô4Ñ4ˆCØ�v”;ÐÝ  & °7À?ÐSÑSÔSˆØˆuŒ:Ðr   FÚ	symmetricc                 ó   — t          | |¦  «        }|d                              ¦   «         |d                              ¦   «         }}|r&t          ||||¬¦  «        t          ||||¬¦  «        fS t          ||||¬¦  «        S )a5  Extracts the edges from the input masks and calculates the surface distance between them.

    Args:
        preds: The predicted binary edge mask.
        target: The target binary edge mask.
        distance_metric: The distance metric to use. One of `["euclidean", "chessboard", "taxicab"]`.
        spacing: The spacing between pixels along each spatial dimension.
        symmetric: Whether to calculate the symmetric distance between the edges.

    Returns:
        A tensor with length equal to the number of edges in predictions e.g. `preds.sum()`. Each element is the
        distance from the corresponding edge in `preds` to the closest edge in `target`. If `symmetric` is `True`, the
        function returns a tuple containing the distances from the predicted edges to the target edges and vice versa.

    r   r   )rÁ   r§   )rÀ   r>   rÅ   )r   r   rÁ   r§   rÆ   re   r¼   r½   s           r   Úedge_surface_distancerÈ   Ù  sŽ   € õ, ˜˜vÑ&Ô&€FØ & q¤	§¢Ñ 0Ô 0°&¸´)·.².Ñ2BÔ2B�€KØð 
å˜[¨,ÈÐahÐiÑiÔiÝ˜\¨;ÈÐahÐiÑiÔið
ð 	
õ ˜K¨ÀÐ`gÐhÑhÔhÐhr   rJ   c                 ó   — t          | t          ¦  «        r#t          | ¦  «        dk    rt          | |¦  «        S t          | t          ¦  «        r#t          | ¦  «        dk    rt	          | |¦  «        S t          d¦  «        ‚)aÿ  Create a table that maps neighbour codes to the contour length or surface area of the corresponding contour.

    Args:
        spacing: The spacing between pixels along each spatial dimension.
        device: The device on which the table should be created.

    Returns:
        A tuple containing as its first element the table that maps neighbour codes to the contour length or surface
        area of the corresponding contour and as its second element the kernel used to compute the neighbour codes.

    r   r(   z-The spacing must be a tuple of length 2 or 3.)rs   Útuplerx   Útable_contour_lengthÚtable_surface_arear)   )r§   rJ   s     r   r¬   r¬   ù  sw   € õ �'�5Ñ!Ô!ð 5¥c¨'¡l¤l°aÒ&7Ð&7Ý# G¨VÑ4Ô4Ð4Ý�'�5Ñ!Ô!ð 3¥c¨'¡l¤l°aÒ&7Ð&7Ý! '¨6Ñ2Ô2Ð2Ý
ÐDÑ
EÔ
EÐEr   c                 ó–  — t          | t          ¦  «        s"t          | ¦  «        dk    rt          d¦  «        ‚| \  }}dt	          j        |dz  |dz  z   ¦  «        z  }t          j        dt          j        |¬¦  «        }dD ]}|||<   ŒdD ]}|||<   ŒdD ]}|||<   Œd	D ]
}d|z  ||<   Œt          j	        d
dgddgggg|¬¦  «        }||fS )a  Create a table that maps neighbour codes to the contour length of the corresponding contour.

    Adopted from:
    https://github.com/deepmind/surface-distance/blob/master/surface_distance/lookup_tables.py

    Args:
        spacing: The spacing between pixels along each spatial dimension. Should be a tuple of length 2.
        device: The device on which the table should be created.

    Returns:
        A tuple containing as its first element the table that maps neighbour codes to the contour length of the
        corresponding contour and as its second element the kernel used to compute the neighbour codes.

    Example::
        >>> from torchmetrics.functional.segmentation.utils import table_contour_length
        >>> table, kernel = table_contour_length((2,2))
        >>> table
        tensor([0.0000, 1.4142, 1.4142, 2.0000, 1.4142, 2.0000, 2.8284, 1.4142, 1.4142,
                2.8284, 2.0000, 1.4142, 2.0000, 1.4142, 1.4142, 0.0000])
        >>> kernel
        tensor([[[[8, 4],
                  [2, 1]]]])

    r   z(The spacing must be a tuple of length 2.ç      à?é   ©rK   rJ   )r   r   rl   é   é   é   é   é   )r(   é   )rm   é
   )é   é	   rÒ   rl   r   r©   )
rs   rÊ   rx   r)   Úmathr”   r*   ÚzerosÚfloat32Ú	as_tensor)r§   rJ   ÚfirstÚsecondÚdiagr´   ro   rµ   s           r   rË   rË     s  € õ2 �g�uÑ%Ô%ð E­#¨g©,¬,¸!Ò*;Ð*;ÝÐCÑDÔDÐDà�M€Eˆ6Ø•”˜5 !™8 f¨a¡iÑ/Ñ0Ô0Ñ0€DÝŒK˜¥%¤-¸Ð?Ñ?Ô?€EØ(ð ð ˆØˆˆa‰ˆØð ð ˆØˆˆa‰ˆØð ð ˆØˆˆa‰ˆØð ð ˆØ�t‘8ˆˆa‰ˆÝŒ_  A ¨¨A¨Ð/Ð0Ð1¸&ÐAÑAÔA€FØ�&ˆ=Ðr   c                 óŒ  — t          | t          ¦  «        s"t          | ¦  «        dk    rt          d¦  «        ‚g d¢}t	          j        g ||||g‘g d¢|||g‘g d¢|||g‘g d¢g d¢||g‘g d¢|||g‘g d	¢g d
¢||g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢|||g‘g d¢g d¢||g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢|||g‘g d¢g d¢||g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d ¢g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢|||g‘g d¢g d¢||g‘g d¢g d¢||g‘g d¢g d!¢g d"¢|g‘g d¢g d¢||g‘g d¢g d	¢g d
¢|g‘g d¢g d¢g d¢|g‘g d#¢g d$¢g d!¢g d	¢g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d%¢g d¢g d¢|g‘g d"¢g d"¢g d!¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d¢g d&¢g d¢g d'¢g‘g d¢g d¢g d¢|g‘g d¢g d ¢||g‘g d(¢g d¢g d¢|g‘g d(¢g d¢g d)¢|g‘g d(¢g d¢||g‘g d¢g d ¢g d¢|g‘g d*¢g d¢g d¢g d ¢g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d ¢|g‘g d(¢g d"¢g d¢g d¢g‘g d+¢g d¢g d¢g d¢g‘g d(¢g d"¢g d¢|g‘g d¢g d ¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢|||g‘g d¢g d¢||g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d,¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d-¢g d¢g d¢g d'¢g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d.¢g d)¢g d¢|g‘g d)¢g d)¢g d¢g d¢g‘g d/¢g d&¢g d¢g d¢g‘g d¢g d)¢g d¢|g‘g d¢g d0¢||g‘g d%¢g d¢g d¢|g‘g d¢g d¢g d0¢|g‘g d	¢g d1¢g d¢g d¢g‘g d¢g d"¢g d¢|g‘g d%¢g d,¢||g‘g d¢g d¢g d¢g d,¢g‘g d¢g d¢g d,¢|g‘g d¢g d0¢g d¢|g‘g d%¢g d¢g d¢g d¢g‘g d¢g d¢g d¢g d0¢g‘g d¢g d
¢g d
¢|g‘g d
¢g d#¢g d ¢g d¢g‘g d%¢g d¢g d¢|g‘g d¢g d
¢g d
¢|g‘g d
¢g d
¢||g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d!¢g d"¢g d¢g‘g d¢g d¢g d¢|g‘g d,¢g d¢g d¢g d¢g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d%¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d.¢g d)¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d2¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d-¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d#¢g d¢g d¢g d¢g‘g d¢g d¢g d,¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d	¢g d
¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢||g‘g d¢|||g‘g d¢|||g‘g d¢g d¢||g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d	¢g d
¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢g d,¢|g‘g d#¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d-¢g d¢g d¢g d¢g‘g d¢g d¢g d¢g d¢g‘g d¢g d2¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d.¢g d)¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d%¢g d¢g d¢g d¢g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d,¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d!¢g d"¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d
¢g d
¢||g‘g d¢g d
¢g d
¢|g‘g d%¢g d¢g d¢|g‘g d
¢g d#¢g d ¢g d¢g‘g d¢g d
¢g d
¢|g‘g d	¢g d
¢g d
¢g d
¢g‘g d%¢g d¢g d¢g d¢g‘g d¢g d0¢g d¢|g‘g d¢g d¢g d,¢|g‘g d¢g d¢g d¢g d,¢g‘g d%¢g d,¢||g‘g d¢g d"¢g d¢|g‘g d	¢g d1¢g d¢g d¢g‘g d¢g d¢g d0¢|g‘g d%¢g d¢g d¢|g‘g d¢g d0¢||g‘g d¢g d)¢g d¢|g‘g d/¢g d&¢g d¢g d¢g‘g d)¢g d)¢g d¢g d¢g‘g d.¢g d)¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d-¢g d¢g d¢g d'¢g‘g d¢g d¢g d¢|g‘g d,¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢||g‘g d¢|||g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d(¢g d"¢g d¢|g‘g d+¢g d¢g d¢g d¢g‘g d(¢g d"¢g d¢g d¢g‘g d¢g d¢g d ¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d*¢g d¢g d¢g d ¢g‘g d¢g d ¢g d¢|g‘g d(¢g d¢||g‘g d(¢g d¢g d)¢|g‘g d(¢g d¢g d¢|g‘g d¢g d ¢||g‘g d¢g d¢g d¢|g‘g d¢g d&¢g d¢g d'¢g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d"¢g d"¢g d!¢g d¢g‘g d%¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d#¢g d$¢g d!¢g d	¢g‘g d¢g d¢g d¢|g‘g d¢g d	¢g d
¢|g‘g d¢g d¢||g‘g d¢g d!¢g d"¢|g‘g d¢g d¢||g‘g d¢g d¢||g‘g d¢|||g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢g d ¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢g d¢g d¢g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢||g‘g d¢|||g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d¢g d¢||g‘g d¢|||g‘g d¢g d¢g d¢|g‘g d¢g d¢||g‘g d	¢g d
¢||g‘g d¢|||g‘g d¢g d¢||g‘g d¢|||g‘g d¢|||g‘||||g‘t          j        |¬3¦  «        }t	          j        | d4         | d5         z  | d6         | d5         z  | d6         | d4         z  ggg||j        ¬7¦  «        }t          j	         
                    ||z  d8¬9¦  «        }|                     d8¦  «        }t	          j        d:d;gd<d=ggd>d?gd5d4ggggg|¬@¦  «        }||fS )Aa€  Create a table that maps neighbour codes to the surface area of the corresponding surface.

    Adopted from:
    https://github.com/deepmind/surface-distance/blob/master/surface_distance/lookup_tables.py

    Args:
        spacing: The spacing between pixels along each spatial dimension. Should be a tuple of length 3.
        device: The device on which the table should be created.

    Returns:
        A tuple containing as its first element the table that maps neighbour codes to the surface area of the
        corresponding surface and as its second element the kernel used to compute the neighbour codes.

    Example::
        >>> from torchmetrics.functional.segmentation.utils import table_surface_area
        >>> table, kernel = table_surface_area((2,2,2))
        >>> table
        tensor([0.0000, 0.8660, 0.8660, 2.8284, 0.8660, 2.8284, 1.7321, 4.5981, 0.8660,
                1.7321, 2.8284, 4.5981, 2.8284, 4.5981, 4.5981, 4.0000, 0.8660, 2.8284,
                1.7321, 4.5981, 1.7321, 4.5981, 2.5981, 5.1962, 1.7321, 3.6945, 3.6945,
                6.2925, 3.6945, 6.2925, 5.4641, 4.5981, 0.8660, 1.7321, 2.8284, 4.5981,
                1.7321, 3.6945, 3.6945, 6.2925, 1.7321, 2.5981, 4.5981, 5.1962, 3.6945,
                5.4641, 6.2925, 4.5981, 2.8284, 4.5981, 4.5981, 4.0000, 3.6945, 6.2925,
                5.4641, 4.5981, 3.6945, 5.4641, 6.2925, 4.5981, 5.6569, 3.6945, 3.6945,
                2.8284, 0.8660, 1.7321, 1.7321, 3.6945, 2.8284, 4.5981, 3.6945, 6.2925,
                1.7321, 2.5981, 3.6945, 5.4641, 4.5981, 5.1962, 6.2925, 4.5981, 2.8284,
                4.5981, 3.6945, 6.2925, 4.5981, 4.0000, 5.4641, 4.5981, 3.6945, 5.4641,
                5.6569, 3.6945, 6.2925, 4.5981, 3.6945, 2.8284, 1.7321, 2.5981, 3.6945,
                5.4641, 3.6945, 5.4641, 5.6569, 3.6945, 2.5981, 3.4641, 5.4641, 2.5981,
                5.4641, 2.5981, 3.6945, 1.7321, 4.5981, 5.1962, 6.2925, 4.5981, 6.2925,
                4.5981, 3.6945, 2.8284, 5.4641, 2.5981, 3.6945, 1.7321, 3.6945, 1.7321,
                1.7321, 0.8660, 0.8660, 1.7321, 1.7321, 3.6945, 1.7321, 3.6945, 2.5981,
                5.4641, 2.8284, 3.6945, 4.5981, 6.2925, 4.5981, 6.2925, 5.1962, 4.5981,
                1.7321, 3.6945, 2.5981, 5.4641, 2.5981, 5.4641, 3.4641, 2.5981, 3.6945,
                5.6569, 5.4641, 3.6945, 5.4641, 3.6945, 2.5981, 1.7321, 2.8284, 3.6945,
                4.5981, 6.2925, 3.6945, 5.6569, 5.4641, 3.6945, 4.5981, 5.4641, 4.0000,
                4.5981, 6.2925, 3.6945, 4.5981, 2.8284, 4.5981, 6.2925, 5.1962, 4.5981,
                5.4641, 3.6945, 2.5981, 1.7321, 6.2925, 3.6945, 4.5981, 2.8284, 3.6945,
                1.7321, 1.7321, 0.8660, 2.8284, 3.6945, 3.6945, 5.6569, 4.5981, 6.2925,
                5.4641, 3.6945, 4.5981, 5.4641, 6.2925, 3.6945, 4.0000, 4.5981, 4.5981,
                2.8284, 4.5981, 6.2925, 5.4641, 3.6945, 5.1962, 4.5981, 2.5981, 1.7321,
                6.2925, 3.6945, 3.6945, 1.7321, 4.5981, 2.8284, 1.7321, 0.8660, 4.5981,
                5.4641, 6.2925, 3.6945, 6.2925, 3.6945, 3.6945, 1.7321, 5.1962, 2.5981,
                4.5981, 1.7321, 4.5981, 1.7321, 2.8284, 0.8660, 4.0000, 4.5981, 4.5981,
                2.8284, 4.5981, 2.8284, 1.7321, 0.8660, 4.5981, 1.7321, 2.8284, 0.8660,
                2.8284, 0.8660, 0.8660, 0.0000])
        >>> kernel
        tensor([[[[[128,  64],
                   [ 32,  16]],
                  [[  8,   4],
                   [  2,   1]]]]])

    r(   z(The spacing must be a tuple of length 3.)ç        râ   râ   )ç      À?rã   rã   )ç      À¿rä   rã   )ç      Ð¿rå   râ   )ç      Ð?ræ   ç       €)rã   rä   rã   )rå   rç   rå   )ræ   râ   ræ   )rÎ   râ   rç   )ræ   ræ   ræ   )rä   rã   rã   )rå   râ   ræ   )rÎ   râ   râ   )rå   rå   ræ   )ræ   rå   râ   )ræ   rå   ræ   )rä   rã   rä   )ç      à¿râ   râ   )rå   ræ   ræ   )rã   rä   rä   )râ   rå   rå   )râ   ræ   ræ   )râ   rè   râ   )râ   râ   rè   )rä   rä   rä   )rå   rå   rå   )ç      Ø?ré   ré   )râ   rå   ræ   )râ   ræ   rå   )rå   ræ   râ   )rã   rã   rä   )ræ   ræ   rå   )ç      Ø¿rê   ré   )rç   ræ   ræ   )rç   râ   rÎ   )ré   rê   rê   )ræ   ræ   râ   )râ   rÎ   râ   )rå   ræ   rå   )rê   rê   rê   )rê   ré   rê   )râ   râ   rÎ   )ré   rê   ré   )rç   rÎ   râ   )rå   râ   rå   )ræ   râ   rå   )rê   ré   ré   )ræ   rå   rå   rÐ   r   r   r   rI   r'   r5   é€   é@   é    rÏ   rÒ   rl   r©   )rs   rÊ   rx   r)   r*   r3   rÜ   rÝ   rK   ÚlinalgÚnormrc   )r§   rJ   rÛ   r´   Úspacerï   rµ   s          r   rÌ   rÌ   :  s¿)  € õn �g�uÑ%Ô%ð E­#¨g©,¬,¸!Ò*;Ð*;ÝÐCÑDÔDÐDàˆOˆO€EÝŒLðA	
Ø�E˜5 %Ð(ðA	
à"Ð"Ð" E¨5°%Ð8ðA	
ð %Ð$Ð$ e¨U°EÐ:ðA	
ð !Ð Ð Ð"4Ð"4Ð"4°e¸UÐCð	A	
ð
 $Ð#Ð# U¨E°5Ð9ðA	
ð "Ð!Ð!Ð#4Ð#4Ð#4°e¸UÐCðA	
ð $Ð#Ð#Ð%<Ð%<Ð%<¸eÀUÐKðA	
ð ÐÐÐ1Ð1Ð1Ð3HÐ3HÐ3HÈ%ÐPðA	
ð $Ð#Ð# U¨E°5Ð9ðA	
ð #Ð"Ð"Ð$:Ð$:Ð$:¸EÀ5ÐIðA	
ð  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðA	
ð ˆ_ˆ_Ð2Ð2Ð2Ð4KÐ4KÐ4KÈUÐSðA	
ð  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðA	
ð ˆ_ˆ_Ð1Ð1Ð1Ð3JÐ3JÐ3JÈEÐRðA	
ð ÐÐÐ2Ð2Ð2Ð4JÐ4JÐ4JÈEÐRðA	
ð  ˆ_ˆ_˜o˜o˜o¨u°eÐ<ð!A	
ð" %Ð$Ð$ e¨U°EÐ:ð#A	
ð$ !Ð Ð Ð"3Ð"3Ð"3°U¸EÐBð%A	
ð& %Ð$Ð$Ð&=Ð&=Ð&=¸uÀeÐLð'A	
ð( ÐÐÐ1Ð1Ð1Ð3HÐ3HÐ3HÈ%ÐPð)A	
ð* $Ð#Ð#Ð%<Ð%<Ð%<¸eÀUÐKð+A	
ð, ÐÐÐ1Ð1Ð1Ð3KÐ3KÐ3KÈUÐSð-A	
ð. %Ð$Ð$Ð&<Ð&<Ð&<Ð>UÐ>UÐ>UÐW\Ð]ð/A	
ð0 &Ð%Ð%Ð'<Ð'<Ð'<Ð>PÐ>PÐ>PÐRgÐRgÐRgÐhð1A	
ð2 $Ð#Ð#Ð%<Ð%<Ð%<¸eÀUÐKð3A	
ð4 !Ð Ð Ð"3Ð"3Ð"3Ð5KÐ5KÐ5KÈUÐSð5A	
ð6  ÐÐÐ!3Ð!3Ð!3Ð5LÐ5LÐ5LÈeÐTð7A	
ð8 #Ð"Ð"Ð$9Ð$9Ð$9Ð;MÐ;MÐ;MÐOaÐOaÐOaÐbð9A	
ð: %Ð$Ð$Ð&8Ð&8Ð&8Ð:LÐ:LÐ:LÈeÐTð;A	
ð< #Ð"Ð"Ð$6Ð$6Ð$6Ð8PÐ8PÐ8PÐRdÐRdÐRdÐeð=A	
ð> ÐÐÐ7Ð7Ð7Ð9NÐ9NÐ9NÐPeÐPeÐPeÐfð?A	
ð@ ÐÐÐ7Ð7Ð7Ð9NÐ9NÐ9NÐPUÐVðAA	
ðB $Ð#Ð# U¨E°5Ð9ðCA	
ðD #Ð"Ð"Ð$:Ð$:Ð$:¸EÀ5ÐIðEA	
ðF  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðGA	
ðH ÐÐÐ5Ð5Ð5Ð7JÐ7JÐ7JÈEÐRðIA	
ðJ $Ð#Ð#Ð%;Ð%;Ð%;¸UÀEÐJðKA	
ðL $Ð#Ð#Ð%9Ð%9Ð%9Ð;LÐ;LÐ;LÈeÐTðMA	
ðN  ÐÐÐ!3Ð!3Ð!3Ð5KÐ5KÐ5KÈUÐSðOA	
ðP %Ð$Ð$Ð&8Ð&8Ð&8Ð:PÐ:PÐ:PÐRfÐRfÐRfÐgðQA	
ðR $Ð#Ð#Ð%;Ð%;Ð%;¸UÀEÐJðSA	
ðT #Ð"Ð"Ð$:Ð$:Ð$:Ð<RÐ<RÐ<RÐTYÐZðUA	
ðV ÐÐÐ3Ð3Ð3Ð5LÐ5LÐ5LÈeÐTðWA	
ðX !Ð Ð Ð"5Ð"5Ð"5Ð7MÐ7MÐ7MÐOfÐOfÐOfÐgðYA	
ðZ $Ð#Ð#Ð%7Ð%7Ð%7Ð9KÐ9KÐ9KÈUÐSð[A	
ð\ ˆ_ˆ_Ð1Ð1Ð1Ð3JÐ3JÐ3JÐLbÐLbÐLbÐcð]A	
ð^  ÐÐÐ!8Ð!8Ð!8Ð:PÐ:PÐ:PÐRcÐRcÐRcÐdð_A	
ð` ÐÐÐ3Ð3Ð3Ð5LÐ5LÐ5LÈeÐTðaA	
ðb  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðcA	
ðd ˆ_ˆ_Ð1Ð1Ð1Ð3JÐ3JÐ3JÈEÐRðeA	
ðf ˆ_ˆ_Ð4Ð4Ð4Ð6JÐ6JÐ6JÈEÐRðgA	
ðh ˆ_ˆ_Ð.Ð.Ð.°°uÐ=ðiA	
ðj  ÐÐÐ!3Ð!3Ð!3Ð5KÐ5KÐ5KÈUÐSðkA	
ðl &Ð%Ð%Ð'9Ð'9Ð'9Ð;SÐ;SÐ;SÐUgÐUgÐUgÐhðmA	
ðn #Ð"Ð"Ð$4Ð$4Ð$4Ð6KÐ6KÐ6KÐMeÐMeÐMeÐfðoA	
ðp ÐÐÐ4Ð4Ð4Ð6NÐ6NÐ6NÐPUÐVðqA	
ðr $Ð#Ð#Ð%7Ð%7Ð%7Ð9KÐ9KÐ9KÈUÐSðsA	
ðt ˆ_ˆ_Ð1Ð1Ð1Ð3JÐ3JÐ3JÐLcÐLcÐLcÐdðuA	
ðv %Ð$Ð$Ð&9Ð&9Ð&9Ð;RÐ;RÐ;RÐTfÐTfÐTfÐgðwA	
ðx ˆ_ˆ_Ð1Ð1Ð1Ð3JÐ3JÐ3JÈEÐRðyA	
ðz  ÐÐÐ!3Ð!3Ð!3Ð5GÐ5GÐ5GÐI[ÐI[ÐI[Ð\ð{A	
ð| !Ð Ð Ð"5Ð"5Ð"5Ð7NÐ7NÐ7NÐPUÐVð}A	
ð~ #Ð"Ð"Ð$7Ð$7Ð$7Ð9LÐ9LÐ9LÈeÐTðA	
ð@ !Ð Ð Ð"5Ð"5Ð"5°u¸eÐDðAA	
ðB %Ð$Ð$ e¨U°EÐ:ðCA	
ðD #Ð"Ð"Ð$;Ð$;Ð$;¸UÀEÐJðEA	
ðF %Ð$Ð$Ð&=Ð&=Ð&=¸uÀeÐLðGA	
ðH %Ð$Ð$Ð&9Ð&9Ð&9Ð;MÐ;MÐ;MÈuÐUðIA	
ðJ  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðKA	
ðL ˆ_ˆ_Ð1Ð1Ð1Ð3IÐ3IÐ3IÈ5ÐQðMA	
ðN  ÐÐÐ!3Ð!3Ð!3Ð5LÐ5LÐ5LÈeÐTðOA	
ðP $Ð#Ð#Ð%8Ð%8Ð%8Ð:QÐ:QÐ:QÐSdÐSdÐSdÐeðQA	
ðR %Ð$Ð$Ð&<Ð&<Ð&<¸eÀUÐKðSA	
ðT #Ð"Ð"Ð$;Ð$;Ð$;Ð=SÐ=SÐ=SÐUZÐ[ðUA	
ðV %Ð$Ð$Ð&8Ð&8Ð&8Ð:LÐ:LÐ:LÈeÐTðWA	
ðX ˆ_ˆ_Ð2Ð2Ð2Ð4KÐ4KÐ4KÐMdÐMdÐMdÐeðYA	
ðZ ÐÐÐ3Ð3Ð3Ð5KÐ5KÐ5KÈUÐSð[A	
ð\ "Ð!Ð!Ð#7Ð#7Ð#7Ð9PÐ9PÐ9PÐRiÐRiÐRiÐjð]A	
ð^ !Ð Ð Ð"9Ð"9Ð"9Ð;MÐ;MÐ;MÐOeÐOeÐOeÐfð_A	
ð` ˆ_ˆ_Ð2Ð2Ð2Ð4JÐ4JÐ4JÈEÐRðaA	
ðb  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðcA	
ðd ÐÐÐ2Ð2Ð2Ð4JÐ4JÐ4JÈEÐRðeA	
ðf %Ð$Ð$Ð&8Ð&8Ð&8Ð:LÐ:LÐ:LÈeÐTðgA	
ðh "Ð!Ð!Ð#9Ð#9Ð#9Ð;NÐ;NÐ;NÐPfÐPfÐPfÐgðiA	
ðj ÐÐÐ2Ð2Ð2Ð4KÐ4KÐ4KÈUÐSðkA	
ðl ÐÐ˜˜˜°°uÐ=ðmA	
ðn #Ð"Ð"Ð$9Ð$9Ð$9Ð;MÐ;MÐ;MÈÈÈÐ_ðoA	
ðp #Ð"Ð"Ð$6Ð$6Ð$6¸¸¸ÈÐOðqA	
ðr  ÐÐÐ!3Ð!3Ð!3Ð5KÐ5KÐ5KÈUÐSðsA	
ðt ÐÐÐ2Ð2Ð2Ð4JÐ4JÐ4JÐLbÐLbÐLbÐcðuA	
ðv  ÐÐÐ!3Ð!3Ð!3Ð5GÐ5GÐ5GÐI[ÐI[ÐI[Ð\ðwA	
ðx $Ð#Ð#Ð%6Ð%6Ð%6Ð8IÐ8IÐ8IÈ5ÐQðyA	
ðz ÐÐÐ 7Ð 7Ð 7Ð9KÐ9KÐ9KÐMdÐMdÐMdÐeð{A	
ð| ÐÐÐ2Ð2Ð2Ð4JÐ4JÐ4JÈEÐRð}A	
ð~ #Ð"Ð"Ð$5Ð$5Ð$5Ð7HÐ7HÐ7HÈ%ÐPðA	
ð@ ÐÐÐ 1Ð 1Ð 1°5¸%Ð@ðAA	
ðB %Ð$Ð$Ð&<Ð&<Ð&<¸eÀUÐKðCA	
ðD #Ð"Ð"Ð$;Ð$;Ð$;Ð=SÐ=SÐ=SÐUZÐ[ðEA	
ðF %Ð$Ð$Ð&8Ð&8Ð&8Ð:LÐ:LÐ:LÈeÐTðGA	
ðH ÐÐÐ5Ð5Ð5Ð7JÐ7JÐ7JÐLcÐLcÐLcÐdðIA	
ðJ  ÐÐÐ!3Ð!3Ð!3Ð5KÐ5KÐ5KÈUÐSðKA	
ðL ˆ_ˆ_Ð1Ð1Ð1Ð3IÐ3IÐ3IÐKaÐKaÐKaÐbðMA	
ðN  ÐÐÐ!3Ð!3Ð!3Ð5GÐ5GÐ5GÐI[ÐI[ÐI[Ð\ðOA	
ðP ÐÐÐ 1Ð 1Ð 1Ð3JÐ3JÐ3JÈEÐRðQA	
ðR $Ð#Ð#Ð%;Ð%;Ð%;Ð=TÐ=TÐ=TÐV[Ð\ðSA	
ðT $Ð#Ð#Ð%;Ð%;Ð%;Ð=TÐ=TÐ=TÐVkÐVkÐVkÐlðUA	
ðV ÐÐÐ3Ð3Ð3Ð5LÐ5LÐ5LÐNeÐNeÐNeÐfðWA	
ðX #Ð"Ð"Ð$:Ð$:Ð$:Ð<SÐ<SÐ<SÐUZÐ[ðYA	
ðZ ÐÐÐ3Ð3Ð3Ð5KÐ5KÐ5KÐMcÐMcÐMcÐdð[A	
ð\ #Ð"Ð"Ð$;Ð$;Ð$;Ð=TÐ=TÐ=TÐV[Ð\ð]A	
ð^ !Ð Ð Ð"3Ð"3Ð"3Ð5JÐ5JÐ5JÈEÐRð_A	
ð` #Ð"Ð"Ð$;Ð$;Ð$;¸UÀEÐJðaA	
ðb ÐÐÐ3Ð3Ð3Ð5LÐ5LÐ5LÈeÐTðcA	
ðd !Ð Ð Ð"8Ð"8Ð"8Ð:MÐ:MÐ:MÐOfÐOfÐOfÐgðeA	
ðf $Ð#Ð#Ð%6Ð%6Ð%6Ð8OÐ8OÐ8OÐQcÐQcÐQcÐdðgA	
ðh ÐÐÐ2Ð2Ð2Ð4JÐ4JÐ4JÈEÐRðiA	
ðj %Ð$Ð$Ð&8Ð&8Ð&8Ð:KÐ:KÐ:KÐMdÐMdÐMdÐeðkA	
ðl $Ð#Ð#Ð%8Ð%8Ð%8¸/¸/¸/È5ÐQðmA	
ðn #Ð"Ð"Ð$5Ð$5Ð$5Ð7HÐ7HÐ7HÈ%ÐPðoA	
ðp ÐÐÐ 1Ð 1Ð 1°5¸%Ð@ðqA	
ðr ÐÐÐ1Ð1Ð1Ð3HÐ3HÐ3HÐJ_ÐJ_ÐJ_Ð`ðsA	
ðt $Ð#Ð#Ð%<Ð%<Ð%<Ð>SÐ>SÐ>SÐUZÐ[ðuA	
ðv "Ð!Ð!Ð#4Ð#4Ð#4Ð6KÐ6KÐ6KÈUÐSðwA	
ðx #Ð"Ð"Ð$:Ð$:Ð$:¸EÀ5ÐIðyA	
ðz !Ð Ð Ð"4Ð"4Ð"4Ð6KÐ6KÐ6KÈUÐSð{A	
ð| #Ð"Ð"Ð$;Ð$;Ð$;¸UÀEÐJð}A	
ð~ #Ð"Ð"Ð$9Ð$9Ð$9¸5À%ÐHðA	
ð@ #Ð"Ð" E¨5°%Ð8ðAA	
ðB #Ð"Ð" E¨5°%Ð8ðCA	
ðD #Ð"Ð"Ð$9Ð$9Ð$9¸5À%ÐHðEA	
ðF #Ð"Ð"Ð$;Ð$;Ð$;¸UÀEÐJðGA	
ðH !Ð Ð Ð"4Ð"4Ð"4Ð6KÐ6KÐ6KÈUÐSðIA	
ðJ #Ð"Ð"Ð$:Ð$:Ð$:¸EÀ5ÐIðKA	
ðL "Ð!Ð!Ð#4Ð#4Ð#4Ð6KÐ6KÐ6KÈUÐSðMA	
ðN $Ð#Ð#Ð%<Ð%<Ð%<Ð>SÐ>SÐ>SÐUZÐ[ðOA	
ðP ÐÐÐ1Ð1Ð1Ð3HÐ3HÐ3HÐJ_ÐJ_ÐJ_Ð`ðQA	
ðR ÐÐÐ 1Ð 1Ð 1°5¸%Ð@ðSA	
ðT #Ð"Ð"Ð$5Ð$5Ð$5Ð7HÐ7HÐ7HÈ%ÐPðUA	
ðV $Ð#Ð#Ð%8Ð%8Ð%8¸/¸/¸/È5ÐQðWA	
ðX %Ð$Ð$Ð&8Ð&8Ð&8Ð:KÐ:KÐ:KÐMdÐMdÐMdÐeðYA	
ðZ ÐÐÐ2Ð2Ð2Ð4JÐ4JÐ4JÈEÐRð[A	
ð\ $Ð#Ð#Ð%6Ð%6Ð%6Ð8OÐ8OÐ8OÐQcÐQcÐQcÐdð]A	
ð^ !Ð Ð Ð"8Ð"8Ð"8Ð:MÐ:MÐ:MÐOfÐOfÐOfÐgð_A	
ð` ÐÐÐ3Ð3Ð3Ð5LÐ5LÐ5LÈeÐTðaA	
ðb #Ð"Ð"Ð$;Ð$;Ð$;¸UÀEÐJðcA	
ðd !Ð Ð Ð"3Ð"3Ð"3Ð5JÐ5JÐ5JÈEÐRðeA	
ðf #Ð"Ð"Ð$;Ð$;Ð$;Ð=TÐ=TÐ=TÐV[Ð\ðgA	
ðh ÐÐÐ3Ð3Ð3Ð5KÐ5KÐ5KÐMcÐMcÐMcÐdðiA	
ðj #Ð"Ð"Ð$:Ð$:Ð$:Ð<SÐ<SÐ<SÐUZÐ[ðkA	
ðl ÐÐÐ3Ð3Ð3Ð5LÐ5LÐ5LÐNeÐNeÐNeÐfðmA	
ðn $Ð#Ð#Ð%;Ð%;Ð%;Ð=TÐ=TÐ=TÐVkÐVkÐVkÐlðoA	
ðp $Ð#Ð#Ð%;Ð%;Ð%;Ð=TÐ=TÐ=TÐV[Ð\ðqA	
ðr ÐÐÐ 1Ð 1Ð 1Ð3JÐ3JÐ3JÈEÐRðsA	
ðt !Ð Ð Ð"3Ð"3Ð"3Ð5FÐ5FÐ5FÐHYÐHYÐHYÐZðuA	
ðv ˆ_ˆ_Ð1Ð1Ð1Ð3IÐ3IÐ3IÐKaÐKaÐKaÐbðwA	
ðx  ÐÐÐ!3Ð!3Ð!3Ð5KÐ5KÐ5KÈUÐSðyA	
ðz ÐÐÐ5Ð5Ð5Ð7JÐ7JÐ7JÐLcÐLcÐLcÐdð{A	
ð| %Ð$Ð$Ð&8Ð&8Ð&8Ð:LÐ:LÐ:LÈeÐTð}A	
ð~ #Ð"Ð"Ð$;Ð$;Ð$;Ð=SÐ=SÐ=SÐUZÐ[ðA	
ð@ %Ð$Ð$Ð&<Ð&<Ð&<¸eÀUÐKðAA	
ðB ÐÐÐ 1Ð 1Ð 1°5¸%Ð@ðCA	
ðD #Ð"Ð"Ð$5Ð$5Ð$5Ð7HÐ7HÐ7HÈ%ÐPðEA	
ðF ÐÐÐ2Ð2Ð2Ð4JÐ4JÐ4JÈEÐRðGA	
ðH ÐÐÐ 7Ð 7Ð 7Ð9KÐ9KÐ9KÐMdÐMdÐMdÐeðIA	
ðJ $Ð#Ð#Ð%6Ð%6Ð%6Ð8IÐ8IÐ8IÈ5ÐQðKA	
ðL "Ð!Ð!Ð#4Ð#4Ð#4Ð6GÐ6GÐ6GÐIZÐIZÐIZÐ[ðMA	
ðN ÐÐÐ2Ð2Ð2Ð4JÐ4JÐ4JÐLbÐLbÐLbÐcðOA	
ðP  ÐÐÐ!3Ð!3Ð!3Ð5KÐ5KÐ5KÈUÐSðQA	
ðR #Ð"Ð"Ð$6Ð$6Ð$6¸¸¸ÈÐOðSA	
ðT #Ð"Ð"Ð$9Ð$9Ð$9Ð;MÐ;MÐ;MÈÈÈÐ_ðUA	
ðV ÐÐ˜˜˜°°uÐ=ðWA	
ðX ÐÐÐ2Ð2Ð2Ð4KÐ4KÐ4KÈUÐSðYA	
ðZ "Ð!Ð!Ð#9Ð#9Ð#9Ð;NÐ;NÐ;NÐPfÐPfÐPfÐgð[A	
ð\ %Ð$Ð$Ð&8Ð&8Ð&8Ð:LÐ:LÐ:LÈeÐTð]A	
ð^ ÐÐÐ2Ð2Ð2Ð4JÐ4JÐ4JÈEÐRð_A	
ð`  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðaA	
ðb ˆ_ˆ_Ð2Ð2Ð2Ð4JÐ4JÐ4JÈEÐRðcA	
ðd !Ð Ð Ð"9Ð"9Ð"9Ð;MÐ;MÐ;MÐOeÐOeÐOeÐfðeA	
ðf "Ð!Ð!Ð#7Ð#7Ð#7Ð9PÐ9PÐ9PÐRiÐRiÐRiÐjðgA	
ðh ÐÐÐ3Ð3Ð3Ð5KÐ5KÐ5KÈUÐSðiA	
ðj ˆ_ˆ_Ð2Ð2Ð2Ð4KÐ4KÐ4KÐMdÐMdÐMdÐeðkA	
ðl %Ð$Ð$Ð&8Ð&8Ð&8Ð:LÐ:LÐ:LÈeÐTðmA	
ðn #Ð"Ð"Ð$;Ð$;Ð$;Ð=SÐ=SÐ=SÐUZÐ[ðoA	
ðp %Ð$Ð$Ð&<Ð&<Ð&<¸eÀUÐKðqA	
ðr $Ð#Ð#Ð%8Ð%8Ð%8Ð:QÐ:QÐ:QÐSdÐSdÐSdÐeðsA	
ðt  ÐÐÐ!3Ð!3Ð!3Ð5LÐ5LÐ5LÈeÐTðuA	
ðv ˆ_ˆ_Ð1Ð1Ð1Ð3IÐ3IÐ3IÈ5ÐQðwA	
ðx  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðyA	
ðz %Ð$Ð$Ð&9Ð&9Ð&9Ð;MÐ;MÐ;MÈuÐUð{A	
ð| %Ð$Ð$Ð&=Ð&=Ð&=¸uÀeÐLð}A	
ð~ #Ð"Ð"Ð$;Ð$;Ð$;¸UÀEÐJðA	
ð@ %Ð$Ð$ e¨U°EÐ:ðAA	
ðB !Ð Ð Ð"5Ð"5Ð"5°u¸eÐDðCA	
ðD #Ð"Ð"Ð$7Ð$7Ð$7Ð9LÐ9LÐ9LÈeÐTðEA	
ðF !Ð Ð Ð"5Ð"5Ð"5Ð7NÐ7NÐ7NÐPUÐVðGA	
ðH !Ð Ð Ð"5Ð"5Ð"5Ð7JÐ7JÐ7JÐL^ÐL^ÐL^Ð_ðIA	
ðJ ˆ_ˆ_Ð1Ð1Ð1Ð3JÐ3JÐ3JÈEÐRðKA	
ðL %Ð$Ð$Ð&9Ð&9Ð&9Ð;RÐ;RÐ;RÐTfÐTfÐTfÐgðMA	
ðN ˆ_ˆ_Ð1Ð1Ð1Ð3JÐ3JÐ3JÐLcÐLcÐLcÐdðOA	
ðP $Ð#Ð#Ð%7Ð%7Ð%7Ð9KÐ9KÐ9KÈUÐSðQA	
ðR ÐÐÐ4Ð4Ð4Ð6NÐ6NÐ6NÐPUÐVðSA	
ðT #Ð"Ð"Ð$4Ð$4Ð$4Ð6KÐ6KÐ6KÐMeÐMeÐMeÐfðUA	
ðV &Ð%Ð%Ð'9Ð'9Ð'9Ð;SÐ;SÐ;SÐUgÐUgÐUgÐhðWA	
ðX  ÐÐÐ!3Ð!3Ð!3Ð5KÐ5KÐ5KÈUÐSðYA	
ðZ ˆ_ˆ_Ð.Ð.Ð.°°uÐ=ð[A	
ð\ ˆ_ˆ_Ð4Ð4Ð4Ð6JÐ6JÐ6JÈEÐRð]A	
ð^ ˆ_ˆ_Ð1Ð1Ð1Ð3JÐ3JÐ3JÈEÐRð_A	
ð`  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðaA	
ðb ÐÐÐ3Ð3Ð3Ð5LÐ5LÐ5LÈeÐTðcA	
ðd  ÐÐÐ!8Ð!8Ð!8Ð:PÐ:PÐ:PÐRcÐRcÐRcÐdðeA	
ðf ˆ_ˆ_Ð1Ð1Ð1Ð3JÐ3JÐ3JÐLbÐLbÐLbÐcðgA	
ðh $Ð#Ð#Ð%7Ð%7Ð%7Ð9KÐ9KÐ9KÈUÐSðiA	
ðj !Ð Ð Ð"5Ð"5Ð"5Ð7MÐ7MÐ7MÐOfÐOfÐOfÐgðkA	
ðl ÐÐÐ3Ð3Ð3Ð5LÐ5LÐ5LÈeÐTðmA	
ðn #Ð"Ð"Ð$:Ð$:Ð$:Ð<RÐ<RÐ<RÐTYÐZðoA	
ðp $Ð#Ð#Ð%;Ð%;Ð%;¸UÀEÐJðqA	
ðr %Ð$Ð$Ð&8Ð&8Ð&8Ð:PÐ:PÐ:PÐRfÐRfÐRfÐgðsA	
ðt  ÐÐÐ!3Ð!3Ð!3Ð5KÐ5KÐ5KÈUÐSðuA	
ðv $Ð#Ð#Ð%9Ð%9Ð%9Ð;LÐ;LÐ;LÈeÐTðwA	
ðx $Ð#Ð#Ð%;Ð%;Ð%;¸UÀEÐJðyA	
ðz ÐÐÐ5Ð5Ð5Ð7JÐ7JÐ7JÈEÐRð{A	
ð|  ÐÐÐ!3Ð!3Ð!3°U¸EÐBð}A	
ð~ #Ð"Ð"Ð$:Ð$:Ð$:¸EÀ5ÐIðA	
ð@ $Ð#Ð# U¨E°5Ð9ðAA	
ðB ÐÐÐ7Ð7Ð7Ð9NÐ9NÐ9NÐPUÐVðCA	
ðD ÐÐÐ7Ð7Ð7Ð9NÐ9NÐ9NÐPeÐPeÐPeÐfðEA	
ðF #Ð"Ð"Ð$6Ð$6Ð$6Ð8PÐ8PÐ8PÐRdÐRdÐRdÐeðGA	
ðH %Ð$Ð$Ð&8Ð&8Ð&8Ð:LÐ:LÐ:LÈeÐTðIA	
ðJ #Ð"Ð"Ð$9Ð$9Ð$9Ð;MÐ;MÐ;MÐOaÐOaÐOaÐbðKA	
ðL  ÐÐÐ!3Ð!3Ð!3Ð5LÐ5LÐ5LÈeÐTðMA	
ðN !Ð Ð Ð"3Ð"3Ð"3Ð5KÐ5KÐ5KÈUÐSðOA	
ðP $Ð#Ð#Ð%<Ð%<Ð%<¸eÀUÐKðQA	
ðR &Ð%Ð%Ð'<Ð'<Ð'<Ð>PÐ>PÐ>PÐRgÐRgÐRgÐhðSA	
ðT %Ð$Ð$Ð&<Ð&<Ð&<Ð>UÐ>UÐ>UÐW\Ð]ðUA	
ðV ÐÐÐ1Ð1Ð1Ð3KÐ3KÐ3KÈUÐSðWA	
ðX $Ð#Ð#Ð%<Ð%<Ð%<¸eÀUÐKðYA	
ðZ ÐÐÐ1Ð1Ð1Ð3HÐ3HÐ3HÈ%ÐPð[A	
ð\ %Ð$Ð$Ð&=Ð&=Ð&=¸uÀeÐLð]A	
ð^ !Ð Ð Ð"3Ð"3Ð"3°U¸EÐBð_A	
ð` %Ð$Ð$ e¨U°EÐ:ðaA	
ðb ˆ_ˆ_˜o˜o˜o¨u°eÐ<ðcA	
ðd ÐÐÐ2Ð2Ð2Ð4JÐ4JÐ4JÈEÐRðeA	
ðf ˆ_ˆ_Ð1Ð1Ð1Ð3JÐ3JÐ3JÈEÐRðgA	
ðh  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðiA	
ðj ˆ_ˆ_Ð2Ð2Ð2Ð4KÐ4KÐ4KÈUÐSðkA	
ðl  ÐÐÐ!3Ð!3Ð!3°U¸EÐBðmA	
ðn #Ð"Ð"Ð$:Ð$:Ð$:¸EÀ5ÐIðoA	
ðp $Ð#Ð# U¨E°5Ð9ðqA	
ðr ÐÐÐ1Ð1Ð1Ð3HÐ3HÐ3HÈ%ÐPðsA	
ðt $Ð#Ð#Ð%<Ð%<Ð%<¸eÀUÐKðuA	
ðv "Ð!Ð!Ð#4Ð#4Ð#4°e¸UÐCðwA	
ðx #Ð"Ð" E¨5°%Ð8ðyA	
ðz !Ð Ð Ð"4Ð"4Ð"4°e¸UÐCð{A	
ð| #Ð"Ð" E¨5°%Ð8ð}A	
ð~ #Ð"Ð" E¨5°%Ð8ðA	
ð@ �E˜5 %Ð(ðAA	
õD ŒmØðIEñ Eô E€EõN ŒOØ�1Œ:˜ œ
Ñ" G¨A¤J°¸´Ñ$;¸WÀQ¼ZÈ'ÐRSÌ*Ñ=TÐ
UÐ	VÐWØØŒkðñ ô €Eõ
 Œ<×Ò˜U U™]°ÐÑ3Ô3€DØ�HŠH�R‰LŒL€EÝŒ_ # r ¨R°¨HÐ 5¸¸A¸ÀÀAÀÐ7GÐHÐIÐJÐSYÐZÑZÔZ€FØ�&ˆ=Ðr   )Nr   )NNr   )Nr„   r…   )TN)r„   N)r„   NF)N))Ú	functoolsrÚ   Útypingr   r   r*   r   Útorch.nn.functionalr   r   r   r	   Útyping_extensionsr
   Útorchmetrics.utilities.checksr   Útorchmetrics.utilities.importsr   rÊ   r   r   r>   rv   r2   r0   r/   r?   rV   rf   rƒ   r‘   ry   r¥   rÀ   rÅ   rÈ   Ú	lru_cacherJ   r¬   rË   rÌ   rD   r   r   ú<module>rø      sÿ  ðð Ð Ð Ð Ø €€€Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ð Ð Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø %Ð %Ð %Ð %Ð %Ð %à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;ð˜fð ¨fð ¸¸vÀv¸~Ô9Nð ð ð ð ð
˜fð 
¨fð 
¸ð 
ð 
ð 
ð 
ð, "&Ø9Bð)ð )Øð)àð)ð ð)ð ˜#”ð	)ð
 Ð5Ô6ð)ð ˆ6�6ˆ>Ôð)ð )ð )ð )ðX˜6ð °ð ¸ð ð ð ð ð˜Vð ¨ð ð ð ð ð
8˜&ð 
8 Tð 
8ð 
8ð 
8ð 
8ðJˆvð J E¨#¨s¨(¤Oð J¸ð Jð Jð Jð Jð0(" Cð ("°sð ("¸vð ("ð ("ð ("ð ("ðX vwðC;ð C;ØðC;Ø& vÔ.ðC;Ø?GÈÈcÐSVÈhÌÔ?XðC;ØorðC;àðC;ð C;ð C;ð C;ðP 6:Ø<GØ*3ð	aTð aTØðaTà�u˜V T¨%¤[Ð0Ô1Ô2ðaTð Ð8Ô9ðaTð Ð&Ô'ð	aTð
 ðaTð aTð aTð aTðN ØFJð	7Lð 7LØð7Làð7Lð ð7Lð �e˜E # s (œO¨U°3¸¸S°=Ô-AÐAÔBÔCð	7Lð
 ˆ5�˜�Ô  %¨°¸ÀÐ(FÔ"GÐGÔHð7Lð 7Lð 7Lð 7Lðz FQØ48ð	/ð /Øð/àð/ð ÐAÔBð/ð �e˜F D¨¤KÐ/Ô0Ô1ð	/ð
 ð/ð /ð /ð /ðj FQØ48Øðið iØðiàðið ÐAÔBðið �e˜F D¨¤KÐ/Ô0Ô1ð	ið
 ðið ˆ6�5˜ ˜Ô(Ð(Ô)ðið ið ið ið@ Ôà\`ðFð FØ�5˜˜c˜”? E¨#¨s°C¨-Ô$8Ð8Ô9ðFØCKÈEÌLÔCYðFà
ˆ6�6ˆ>ÔðFð Fð Fñ ÔðFð*(ð ( %¨¨S¨¤/ð (¸8ÀEÄLÔ;Qð (Ð]bÐciÐkqÐcqÔ]rð (ð (ð (ð (ðV ÔðIð I  c¨3° mÔ 4ð I¸hÀuÄ|Ô>Tð IÐ`eÐflÐntÐftÔ`uð Ið Ið Iñ ÔðIð Ið Ir   