+
    åûj{  ã                   óz   € ^ RI t ^ RIHu Ht ^ RIHt ^ RIHtH	t	 ^ RI
HtHt ]! ^^	4      tR	R R lltR R ltR# )
é    N)Útorch_version_ge)ÚKORNIA_CHECKÚKORNIA_CHECK_IS_TENSOR)Úis_compilingÚis_exportingc                ó°   € V ^8„  d   QhR\         P                  R\        R\         P                  R\         P                  R\
        R\         P                  /# )é   ÚlabelsÚnum_classesÚdeviceÚdtypeÚepsÚreturn)ÚtorchÚTensorÚintr   r   Úfloat)Úformats   "ÚQC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\losses\one_hot.pyÚ__annotate__r      sT   € ÷ B.ñ B.Ü�L‰LðB.Ü'*ðB.Ü49·L±LðB.ÜINÏÉðB.Ü[`ðB.ä
‡\�\ñB.ó    c                ó–  € \        V R4       \        V P                  \        P                  8H  RV P                   24       \        V^8¬  RV 24       V^ 8w  dg   \        P
                  P                  4       '       d(   \        P                  ! ^ VR7      P                  4       pMVP                  p\        VRV 24       \        P                  ! WR7      pV P                  p^ .V.,           \        \        ^V4      4      ,           pVP                  V4      pVP                  W2R7      pV^ 8X  d   V# VRV,
          ,          V,           # )	aˆ  Convert int64 class labels ``(N, *)`` to a one-hot tensor ``(N, C, *)``.

``onehot = one_hot(labels, num_classes, device, dtype)`` puts a 1 at each label's class and 0 elsewhere.

Convention:
    - The class axis is dim 1, where :func:`~torch.nn.functional.one_hot` puts it last. With the default
      ``eps=0.0`` the result is ``F.one_hot(labels, num_classes).movedim(-1, 1).to(device, dtype)``.
    - Kornia does not validate the labels: a label outside ``[0, num_classes)`` raises a ``RuntimeError`` from
      torch on the CPU in eager mode.

Args:
    labels: int64 class labels ``(N, *)`` in ``[0, num_classes)``.
    num_classes: number of classes ``C``.
    device: device of the result.
    dtype: data type of the result.
    eps: smoothing floor. The default 0 returns the exact one-hot. A non-zero value replaces the zeros with ``eps``
      and keeps the ones, which needs a floating point ``dtype``.

Returns:
    the one-hot tensor ``(N, C, *)``.

See Also:
    - :func:`~kornia.losses.dice_loss`: the segmentation losses take int64 class indices, not this tensor.

Examples:
    >>> labels = torch.LongTensor([[[0, 1], [2, 0]]])
    >>> one_hot(labels, num_classes=3, device=torch.device('cpu'), dtype=torch.float32)
    tensor([[[[1., 0.],
              [0., 1.]],
    <BLANKLINE>
             [[0., 1.],
              [0., 0.]],
    <BLANKLINE>
             [[0., 0.],
              [1., 0.]]]])

z#Input labels must be a torch.Tensorz*labels must be of dtype torch.int64. Got: z)The number of classes must be >= 1. Got: )r   z2A non-zero eps needs a floating point dtype. Got: )r   )r   r   g      ð?)r   r   r   r   Úint64ÚjitÚis_scriptingÚemptyÚis_floating_pointÚFÚone_hotÚndimÚlistÚrangeÚpermuteÚto)	r
   r   r   r   r   Úis_floatingÚone_hot_tensorr    Úpermute_dimss	   &&&&&    r   r   r      s  € ôP ˜6Ð#HÔIÜ�—‘¤§¡Ñ,Ð0ZÐ[a×[gÑ[gÐZhÐ.iÔjÜ� Ñ!Ð%NÈ{ÈmÐ#\Ô]Ø
ˆa„xä�9‰9×!Ñ!×#Ò#ÜŸ+š+ a¨uÔ5×GÑGÓI‰Kà×1Ñ1ˆKÜ�[Ð$VÐW\ÐV]Ð"^Ô_ô —Y’Y˜vÔ?€Nð
 �;‰;€DØ�3˜$˜•<¤$¤u¨Q°£~Ó"6Õ6€LØ#×+Ñ+¨LÓ9€Nà#×&Ñ&¨UÐ&ÓB€NØ
ˆa„xØÐð ˜S 3�YÕ'¨#Õ-Ð-r   c                ód   € V ^8„  d   QhR\         P                  R\        R\         P                  /# )r	   r
   r   r   )r   r   r   )r   s   "r   r   r   b   s)   € ÷ *ñ *¤§¡ð *¼3ð *Ä5Ç<Á<ñ *r   c                ó@  € V P                   P                  R8w  d   V # \        P                  P	                  4       '       gÝ   \        P
                  P                  4       '       d   V # V P                  4       ^ 8”  d]   \        P                  ! V P                  R4      ^ R7      w  r#\        P                  ! V^ 8¬  R4       \        P                  ! W18  R4       \        '       d:   \        4       '       d*   \        4       '       g   V P                  ^ V^,
          4      # V # )aŽ  Raise :func:`one_hot`'s errors for CPU labels outside ``[0, num_classes)``, eager and compiled alike.

For a loss that gathers, scatters or indexes with the labels instead of building a one-hot target: index with the
labels it returns. Inductor's CPU kernel for such an op checks each index inside an OpenMP parallel region, where a
failed check cannot propagate, so an out-of-range label terminates the process (``index out of bounds``, exit code
134) instead of raising the eager op's ``RuntimeError``. ``torch._assert_async`` raises a ``RuntimeError`` on the
CPU, at once in eager code and from the compiled kernel that evaluates it, without a graph break.

Inductor may fuse the asserts into the index op's kernel and evaluate them after its parallel loop, so under
``torch.compile`` the labels come back clamped into range: the index op stays in bounds until the asserts raise.
They stay unclamped where the asserts may not survive, so that the index op fails instead of a wrong loss being
returned: before torch 2.9, whose Inductor compiles the assert to nothing, and in an exported graph, which ONNX
translates without it. torch 2.9.1 reports a ``torch.compile`` capture as an export too; its Inductor ran the
asserts first in every case checked.

Only CPU labels are checked: on CUDA the index kernels fail an out-of-range label with a device-side assert in
eager and compiled code alike, and so would this assert. Functorch transforms skip it, since ``vmap`` has no
batching rule for the assert, and so does TorchScript, whose scripted and traced graphs drop the assert anyway;
the index op raises its own ``RuntimeError`` there.

Args:
    labels: int64 class labels of any shape; labels to ignore must already be replaced by a valid class.
    num_classes: the number of classes.

Returns:
    ``labels``, clamped to ``[0, num_classes - 1]`` in a CPU ``torch.compile`` capture that is not an export,
    from torch 2.9 on.
Úcpu)Údimz"Class values must be non-negative.z.Class values must be smaller than num_classes.éÿÿÿÿ)r   Útyper   r   r   Ú_CÚ _are_functorch_transforms_activeÚnumelÚaminmaxÚreshapeÚ_assert_asyncÚ_INDUCTOR_KEEPS_ASSERT_ASYNCr   r   Úclamp)r
   r   ÚlowÚhighs   &&  r   Ú_check_class_labelsr8   b   sÆ   € ð: ‡}�}×Ñ˜UÔ"ØˆÜ�9‰9×!Ñ!×#Ò#Ü�8‰8×4Ñ4×6Ò6ØˆMð �<‰<‹>˜AÔÜŸš f§n¡n°RÓ&8¸aÔ@‰IˆCÜ×Ò  q¡Ð*NÔOÜ×Ò Ñ 2Ð4dÔeß'Ó'¬L¯NªNÄ<Ç>Â>Ø—<‘<  ;°¥?Ó3Ð3Ø€Mr   )g        )r   Útorch.nn.functionalÚnnÚ
functionalr   Úkornia.core._compatr   Úkornia.core.checkr   r   Úkornia.core.utilsr   r   r4   r   r8   © r   r   Ú<module>r@      s4   ðó$ ß Ð å 0ß Bß 8ñ  0°°1Ó5Ð ÷B.÷J*r   