+
     åûj”5  ã                   ó  € ^ RI t ^ RIt^ RIHtHtHtHtHt ^ RIt^ RI	H
t
Ht ^ RIHt ^ RI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 R lltRtR R ltR R ltR R ltR R ltR# ) é    N)ÚAnyÚDictÚListÚTupleÚUnion)ÚKORNIA_CHECKÚare_checks_enabled)ÚTypeCheckError)Ú_to_device_nonblockingÚis_compilingc                ó0   € V ^8„  d   QhR\         R\        /# )é   ÚnÚreturn)r   Úbool)Úformats   "ÚKC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\core\ops.pyÚ__annotate__r      s   € ÷ Qñ Q”cð Qœdñ Qó    c                ód   € \        V 4      pVP                  R8H  ;'       d    VP                  R9   # )aA  Return whether ``n`` is a NumPy boolean scalar, read off its type so that this module does not import NumPy.

NumPy 1.x boolean scalars implement ``__index__`` (deprecated there, removed in NumPy 2.0), so ``operator.index``
reads ``np.True_`` as 1; the type is ``numpy.bool_`` on NumPy 1.x and ``numpy.bool`` on NumPy 2.
Únumpy)Úbool_r   )ÚtypeÚ
__module__Ú__name__)r   Ún_types   & r   Ú_is_numpy_boolr      s0   € ô �!‹W€FØ×Ñ Ñ'×PÐP¨F¯O©OÐ?PÑ,PÐPr   c                ó(   € V ^8„  d   QhR\         RR/# ©r   r   r   N)r   )r   s   "r   r   r   '   s   € ÷ 
ñ 
œ3ð 
 4ñ 
r   c                óF  € \        4       '       g   R# Rp\        V \        4      '       g@   \        V \        P                  4      '       d#   V P
                  \        P                  8X  d   RpMc\        V \        \        P                  34      '       g>   \        V R4      '       d   \        V 4      '       d   RpM \        P                  ! V 4       V'       g7   \        RV : R\        V 4      P                   R2\        V 4      \        R7      hR#   \         d    Rp LOi ; i)	aÐ  Raise `TypeCheckError` naming ``n`` unless it is an integer size.

Accepts an ``int``, a NumPy integer, an integer tensor with one element and a ``SymInt``: whatever
``operator.index`` reads as an integer. ``bool`` is an ``int`` subclass and ``operator.index`` accepts it, as it
does a boolean tensor and, on NumPy 1.x, a NumPy boolean scalar, so all three are rejected by name; ``torch.eye``
and ``torch.zeros`` refuse the first two as sizes anyway. An integer tensor that cannot be read (a meta tensor)
raises torch's own ``RuntimeError``. Python-only: TorchScript cannot compile this body, and types ``n`` as ``int``
already. Like the ``KORNIA_CHECK*`` helpers, it does nothing once `disable_checks` has been called.
NTFÚ	__index__zn must be an integer. Got: z (Ú))Úactual_typeÚexpected_type)r	   Ú
isinstancer   ÚtorchÚTensorÚdtypeÚintÚSymIntÚhasattrr   ÚoperatorÚindexÚ	TypeErrorr
   r   r   )r   Ú
is_integers   & r   Ú_check_n_is_integerr0   '   sá   € ô ×ÒÙØ€JÜ�!”T×Òœz¨!¬U¯\©\×:Ò:¸q¿w¹wÌ%Ï*É*Ô?TØ‰
Ü˜œC¤§¡Ð.×/Ò/ô �q˜+×&Ò&¬.¸×*;Ò*;Ø‰Jð#Ü—’˜qÔ!÷ ÜØ)¨!©¨b´°a³×1AÑ1AÐ0BÀ!ÐDÔRVÐWXÓRYÔilô
ð 	
ñ øô ô #Ø"’
ð#ús   Â:D ÄD ÄD c                ó(   € V ^8„  d   QhR\         RR/# r   )r)   )r   s   "r   r   r   G   s   € ÷ 9ñ 9”ð 9˜ñ 9r   c                óˆ   € \         P                  P                  4       '       g   \        V 4       \	        V ^ 8„  RV  24       R# )zgValidate the ``n`` of `eye_like` and `vec_like`: an integer, else `TypeCheckError`, and a positive one.zn must be positive. Got: N)r&   ÚjitÚis_scriptingr0   r   )r   s   &r   Ú_check_nr5   G   s3   € ä�9‰9×!Ñ!×#Ò#Ü˜AÔÜ��Q‘Ð3°A°3Ð7Ö8r   c                óp   € V ^8„  d   QhR\         R\        P                  R\        R\        P                  /# )r   r   ÚinputÚshared_memoryr   ©r)   r&   r'   r   )r   s   "r   r   r   N   s6   € ÷ (yñ (y”ð (yœEŸL™Lð (y¼ð (yÌ%Ï,É,ñ (yr   c                óˆ  € \        V 4       \        \        VP                  4      ^8¬  RVP                   24       \        P
                  ! WP                  VP                  R7      pV'       d+   VR,          P                  VP                  ^ ,          W 4      # VR,          P                  VP                  ^ ,          ^^4      # )aŽ  Build a batch of ``N x N`` identity matrices with the batch size, dtype and device of a tensor.

``eye = eye_like(n, input)`` returns a ``(B, N, N)`` tensor holding one identity matrix per sample, where ``B`` is
``input.shape[0]``, with the dtype and device of ``input`` (a ``bool`` input gives ``True`` on the diagonal). The
result does not require grad.

Convention:
    - ``shared_memory=False`` (the default) returns a contiguous copy per sample, safe to write into.
    - ``shared_memory=True`` returns one identity expanded along the batch: writing into one sample, such as
      ``eye[0, 0, 0] = 5``, writes every sample, and for a batch of more than one, in-place arithmetic such as
      ``add_`` raises ``RuntimeError``.

Args:
    n: the number of rows ``N``, a positive integer: an ``int``, a NumPy integer or a 0-d integer tensor.
        A ``float`` or a ``bool`` is rejected.
    input: the tensor whose batch size ``B``, dtype and device the result takes, of shape ``(B, *)``.
    shared_memory: whether to return an expanded view instead of a copy per sample.

Returns:
    The identity matrices, ``(B, N, N)``.

Raises:
    TypeCheckError: if ``n`` is not an integer.
    BaseError: if ``n`` is not positive, or if ``input`` has no dimension.

See Also:
    - :func:`vec_like`: a batch of ``(N, 1)`` zero vectors instead.

Example:
    >>> eye_like(2, torch.zeros(3, 5)).shape
    torch.Size([3, 2, 2])

z1input must have at least 1 dimension. Got shape: ©Údevicer(   N)
r5   r   ÚlenÚshaper&   Úeyer<   r(   ÚexpandÚrepeat)r   r7   r8   Úidentitys   &&& r   Úeye_likerC   N   s—   € ôD ˆQ„KÜ”�U—[‘[Ó! QÑ&Ð*[Ð\a×\gÑ\gÐ[hÐ(iÔjô �yŠy˜§<¡<°u·{±{ÔC€Hç:Gˆ8�D�>× Ñ  §¡¨Q¥°Ó6ÐxÈXÐVZÍ^×MbÑMbÐch×cnÑcnÐopÕcqÐstÐvwÓMxÐxr   c                óp   € V ^8„  d   QhR\         R\        P                  R\        R\        P                  /# )r   r   Útensorr8   r   r9   )r   s   "r   r   r   y   s6   € ÷ %qñ %q”ð %qœUŸ\™\ð %q¼$ð %qÌ5Ï<É<ñ %qr   c                óŽ  € \        V 4       \        \        VP                  4      ^8¬  RVP                   24       \        P
                  ! V ^VP                  VP                  R7      pV'       d,   VR,          P                  VP                  ^ ,          V ^4      # VR,          P                  VP                  ^ ,          ^^4      # )aC  Build a batch of ``N x 1`` zero column vectors with the batch size, dtype and device of a tensor.

``vec = vec_like(n, tensor)`` returns a ``(B, N, 1)`` tensor of zeros, where ``B`` is ``tensor.shape[0]``, with the
dtype and device of ``tensor``. The result does not require grad.

Convention:
    - ``shared_memory=False`` (the default) returns a contiguous copy per sample, safe to write into.
    - ``shared_memory=True`` returns one vector expanded along the batch: writing into one sample, such as
      ``vec[0, 0, 0] = 5``, writes every sample, and for a batch of more than one, in-place arithmetic such as
      ``add_`` raises ``RuntimeError``.

Args:
    n: the number of rows ``N``, a positive integer: an ``int``, a NumPy integer or a 0-d integer tensor.
        A ``float`` or a ``bool`` is rejected.
    tensor: the tensor whose batch size ``B``, dtype and device the result takes, of shape ``(B, *)``.
    shared_memory: whether to return an expanded view instead of a copy per sample.

Returns:
    The zero vectors, ``(B, N, 1)``.

Raises:
    TypeCheckError: if ``n`` is not an integer.
    BaseError: if ``n`` is not positive, or if ``tensor`` has no dimension.

See Also:
    - :func:`eye_like`: a batch of ``(N, N)`` identity matrices instead.

Example:
    >>> vec_like(3, torch.zeros(2, 4)).shape
    torch.Size([2, 3, 1])

z2tensor must have at least 1 dimension. Got shape: r;   N)
r5   r   r=   r>   r&   Úzerosr<   r(   r@   rA   )r   rE   r8   Úvecs   &&& r   Úvec_likerI   y   sš   € ôB ˆQ„KÜ”�V—\‘\Ó" aÑ'Ð+]Ð^d×^jÑ^jÐ]kÐ)lÔmä
�+Š+�a˜ 6§=¡=¸¿¹Ô
E€Cß6Cˆ3ˆt�9×Ñ˜FŸL™L¨�O¨Q°Ó2ÐpÈÈTÍ×IYÑIYÐZ`×ZfÑZfÐghÕZiÐklÐnoÓIpÐpr   c          
      óx   € V ^8„  d   QhR\         R\        \        ,          R\        \         ,          R\        RR/# )r   Údatar>   ÚleavesÚdepthr   N)r   r   r)   )r   s   "r   r   r   ¡   s8   € ÷ ñ œCð ¬¬S­	ð ¼4Ä½9ð ÌSð ÐY]ñ r   c                 óð   € \        V \        \        34      '       dI   V\        V4      8X  d   VP	                  \        V 4      4       V  F  p\        WAW#^,           4       K  	  R# VP	                  V 4       R# )é   N)r%   ÚlistÚtupler=   ÚappendÚ_flatten_constant)rK   r>   rL   rM   Úvalues   &&&& r   rS   rS   ¡   sU   € Ü�$œœu˜×&Ò&Ø”C˜“JÔØ�L‰Lœ˜T›Ô#ÛˆEÜ˜e¨F¸AµIÖ>ó ð 	�‰�dÖr   r<   c                ó  € V ^8„  d   QhR\         \        \        \        ,          \        \        R3,          3,          R\         \
        \        P                  R3,          R\        P                  R\        P                  /# ©r   rK   .r<   Nr(   r   ©
r   Úfloatr   r   r   Ústrr&   r<   r(   r'   )r   s   "r   r   r   «   sb   € ÷ +7ñ +7Ü
””tœC•y¤%¬¨S¨¥/Ð1Õ
2ð+7ô ”#”u—|‘| TÐ)Õ*ð+7ô �;‰;ð	+7ô
 ‡\�\ñ+7r   c          
     óZ  € \        V \        \        34      '       gl   \        V \        \        \
        P                  \
        P                  34      '       d   \
        P                  ! RWVR7      # \
        P                  ! WVR7      # . p. p\        WV4       V'       g   \
        P                  ! W1VR7      # / p. pV FÑ  p\        V4      \        \        39   g0   \        V4      \        J dz   \        P                  ! V4      '       g^   \        V4      V\        P                   ! RV4      3pW…9  d   \
        P                  ! RWqVR7      WX&   VP#                  WX,          4       K©  VP#                  \
        P                  ! RWqVR7      4       KÓ  	  \%        V4      P'                  V4      # )a¸  Construct small numeric constants inside the graph, without lifting tensor storage.

Inductor can reuse a lifted CPU tensor in a CUDA kernel without transferring it
(https://github.com/pytorch/pytorch/issues/196969). Scalar factories and stacks
avoid that path, including for constants returned alongside CUDA tensors. Indexed
scalar writes are unsafe too: tracing lifts their right-hand sides.

Eager execution, Dynamo and ``make_fx`` all run this same construction, which issues
no host-device copy. Each distinct Python scalar is filled once and a single stack
reuses it, so repeated coordinates such as box corners cost one kernel per value.

``data`` contains Python scalars or rectangular nested lists/tuples, never tensors.
Other array-likes, such as NumPy arrays, keep ``torch.as_tensor`` semantics. Callers
choose dtype explicitly and perform coordinate arithmetic before calling this helper
when rounding before versus after casting matters.
r;   g      ð?© )r%   rP   rQ   r)   rX   r&   r*   ÚSymFloatÚfullÚ	as_tensorrS   Úemptyr   r   ÚmathÚisnanÚcopysignrR   Ú_stack_without_autocastÚview)	rK   r<   r(   r>   rL   ÚfilledÚvaluesÚleafÚkeys	   &$$      r   Ú_constant_tensorri   «   s3  € ô, �dœT¤5˜M×*Ò*Ü�dœS¤%¬¯©´u·~±~ÐF×GÒGÜ—:’:˜b $¸UÔCÐCÜ�Š˜t¸%Ô@Ð@Ø€EØ€FÜ�d 6Ô*ßÜ�{Š{˜5°uÔ=Ð=Ø35€FØ!#€FÛˆô �‹:œ#œt˜Ô$¬¨d«´uÓ)<ÄTÇZÂZÐPT×EUÒEUÜ˜“:˜t¤T§]¢]°3¸Ó%=Ð>ˆCØÔ Ü#Ÿjšj¨¨TÈÔN�‘Ø�M‰M˜&�+Ö&à�M‰Mœ%Ÿ*š* R¨ÀEÔJÖKñ ô # 6Ó*×/Ñ/°Ó6Ð6r   c                ón   € V ^8„  d   QhR\         \        P                  ,          R\        P                  /# )r   rf   r   )r   r&   r'   )r   s   "r   r   r   Ý   s'   € ÷ ñ ¤D¬¯©Õ$6ð ¼5¿<¹<ñ r   c                ó^  € V ^ ,          P                   P                  pV\        9   d^   \        P                  ! V4      '       dB   \        P
                  ! VRR7      ;_uu_ 4        \        P                  ! V 4      uuRRR4       # \        P                  ! V 4      #   + '       g   i     L&; i)ao  Stack ``values`` in their own dtype, also inside an autocast region.

``torch.stack`` is on autocast's promote list, which rejects a half dtype other than the region's own (a
``float16`` stack inside CPU autocast, whose lower precision is ``bfloat16``). A literal keeps the dtype it was
asked for, as ``torch.tensor`` does, so autocast is switched off for the stack.
F)ÚenabledN)r<   r   Ú_AUTOCAST_DEVICE_TYPESr&   Úis_autocast_enabledÚautocastÚstack)rf   Údevice_types   & r   rc   rc   Ý   so   € ð ˜•)×"Ñ"×'Ñ'€KØÔ,Ô,´×1JÒ1JÈ;×1WÒ1WÜ�^Š^˜K°×7Ö7Ü—;’;˜vÓ&÷ 8Ò7ä�;Š;�vÓÐ÷ 8×7ús   Á%BÂB,	c                ó  € V ^8„  d   QhR\         \        \        \        ,          \        \        R3,          3,          R\         \
        \        P                  R3,          R\        P                  R\        P                  /# rV   rW   )r   s   "r   r   r   ë   s_   € ÷ >ñ >Ü
””tœC•y¤%¬¨S¨¥/Ð1Õ
2ð>Ü?DÄSÌ%Ï,É,ÐX\ÐE\Õ?]ð>Üfk×fqÑfqð>ä
‡\�\ñ>r   c               ó¸   € \        4       '       g'   V\        P                  8X  d*   \        V 4      '       g   \        P                  ! WVR7      # \        WVR7      # )a„  Return ``torch.tensor(data, device=device, dtype=dtype)`` for a literal of Python numbers, without a host sync.

An eager call fills the literal on the device with :func:`_constant_tensor`: ``torch.tensor(..., device=cuda)``
copies it from the host and waits for every queued kernel. Under ``torch.compile`` and ``torch.export`` the literal
stays ``torch.tensor(..., device=device)``, as before: capture makes it a constant of the graph on ``device``, which
costs no copy at run time and which Inductor folds into its consumer, where filled values would add kernels. Both
round the same Python numbers to ``dtype``, so the values are the same.
r;   )r   r&   Úfloat16Ú_fits_float16rE   ri   ©rK   r<   r(   s   &$$r   Ú_device_literalrw   ë   s>   € ô ‡~‚~˜%¤5§=¡=Ô0¼Àt×9LÒ9LÜ�|Š|˜D°uÔ=Ð=Ü˜D°uÔ=Ð=r   c                óà   € V ^8„  d   QhR\         \        \        \        ,          \        \        R3,          3,          R\
        P                  R\
        P                  R\
        P                  /# )r   rK   .r<   r(   r   )	r   rX   r   r   r   r&   r<   r(   r'   )r   s   "r   r   r   û   sX   € ÷ Kñ KÜ
””tœC•y¤%¬¨S¨¥/Ð1Õ
2ðKÜ?D¿|¹|ðKÜTY×T_ÑT_ðKä
‡\�\ñKr   c               ó”   € \        4       '       d   \        P                  ! WVR7      # \        \        P                  ! WR7      V4      # )a8  Return ``torch.tensor(data, device=device, dtype=dtype)`` for a literal of Python numbers, without a host sync.

An eager call builds the literal on the host and copies it with :func:`~kornia.core.utils._to_device_nonblocking`:
one copy that does not wait for queued kernels, where :func:`_device_literal` fills one kernel per distinct value,
so this suits a literal with many distinct values. Under ``torch.compile`` and ``torch.export`` the literal stays
``torch.tensor(..., device=device)``, as in :func:`_device_literal`: a host tensor moved inside the graph is no
graph constant to Inductor. Moving it there made compiled CUDA ``extract_patches_from_pyramid`` 1.2-1.6x slower
than ``torch.tensor(..., device=device)`` (torch 2.14, RTX 4090). Both round the same Python numbers to ``dtype``,
so the values are the same.
r;   )r(   )r   r&   rE   r   rv   s   &$$r   Ú_copied_literalrz   û   s2   € ô ‡~‚~Ü�|Š|˜D°uÔ=Ð=Ü!¤%§,¢,¨tÔ"AÀ6ÓJÐJr   c                óŒ   € V ^8„  d   QhR\         \        \        \        ,          \        \        R3,          3,          R\
        /# )r   rK   .r   )r   rX   r   r   r   r   )r   s   "r   r   r     s6   € ÷ mñ mœœe¤T¬#¥Y´´c¸3°hµÐ?Õ@ð mÄTñ mr   c                óˆ   € . p\        V . V4       \        ;QJ d    R V 4       F  '       d   K   R# 	  R# ! R V 4       4      # )a  Whether every finite number in ``data`` is within the float16 range.

``torch.full`` raises for a finite value beyond it on CUDA (and on the CPU in torch 2.5.1), where ``torch.tensor``
rounds it to 65504 or to infinity, so such a literal keeps ``torch.tensor``.
c              3   óÊ   "  € T FY  p\        V\        \        34      '       * ;'       g2    \        P                  ! V4      '       * ;'       g    \        V4      R 8*  x € K[  	  R# 5i)g     üï@N)r%   r)   rX   r`   ÚisfiniteÚabs)Ú.0Úvs   & r   Ú	<genexpr>Ú _fits_float16.<locals>.<genexpr>  sJ   é € ÐlÑekÐ`a”:˜a¤#¤u Ó.Ô.×[Ð[´d·m²mÀAÓ6FÔ2F×[Ð[Ì#ÈaË&ÐT[ÑJ[Ô[Óekùs   ‚&A#©"A#ÁA#FT)rS   Úall)rK   rL   s   & r   ru   ru     s@   € ð €FÜ�d˜B Ô'ß‹3ÑlÑekÓl�3Œ3ÐlŠ3Ðlˆ3ÑlÑekÓlÓlÐlr   )F)r   )ÚcpuÚcudaÚmpsÚxpuÚxlaÚhpu)r`   r,   Útypingr   r   r   r   r   r&   Úkornia.core.checkr   r	   Úkornia.core.exceptionsr
   Úkornia.core.utilsr   r   r   r0   r5   rC   rI   rS   ri   rm   rc   rw   rz   ru   r[   r   r   Ú<module>r�      sr   ðó$ Û ß 0Õ 0ã ç >Ý 1ß BõQõ
õ@9÷(y÷V%q÷Pð+7ð .2÷+7ð^ EÐ õõ>õ K÷$mr   