ó
    Eñiœ  ã                   ó¼   • S r SSKrSSKrSSKJr  S r " S S\\5      r " S S	\	\
5      rS
 rS rSS jrSS jrS rS rS rSS.S jrS rS rS rSS jrS rg)zKAssorted utilities, which do not need anything other then torch and stdlib.é    Né   )Ú_dtypes_implc                 óh   • [        U [        5      (       a  g [        U 5        g! [         a     gf = f)NFT)Ú
isinstanceÚstrÚlenÚ	Exception)Úseqs    ÚO/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/_numpy/_util.pyÚis_sequencer      s7   € Ü�#”s×ÑØðÜˆCŒð øô ó Ùðús   ˜$ ¤
1°1c                   ó   • \ rS rSrSrg)Ú	AxisErroré   © N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   ó    r   r   r      ó   † Úr   r   c                   ó   • \ rS rSrSrg)ÚUFuncTypeErroré   r   Nr   r   r   r   r   r      r   r   r   c                 óN   • Ub!  U R                   U:w  a  U R                  U5      n U $ ©N)ÚdtypeÚto)Útensorr   s     r   Úcast_if_neededr!      s&   € àÑ˜VŸ\™\¨UÓ2Ø—‘˜5Ó!ˆØ€Mr   c                 óª   • [         R                  " U R                  5      S:  a.  U R                  [         R                  " 5       R
                  5      n U $ )Né   )r   Ú	_categoryr   r   Údefault_dtypesÚfloat_dtype)Úxs    r   Úcast_int_to_floatr(   &   s;   € ä×Ò˜aŸg™gÓ&¨Ó*Ø�D‰D”×,Ò,Ó.×:Ñ:Ó;ˆØ€Hr   c                 ó\   • U* U s=::  a  U:  d  O  [        SU  SU 35      eU S:  a  X-  n U $ )Nzaxis z) is out of bounds for array of dimension r   )r   )ÚaxÚndimÚargnames      r   Únormalize_axis_indexr-   .   s=   € ØˆE�RÕ˜$ÕÜ˜% ˜tÐ#LÈTÈFÐSÓTÐTØ	ˆAƒvØ
‰
ˆØ€Ir   c                 óf  ^^• [        U 5      [        [        4;  a   [        R                  " U 5      /n [        UU4S jU  5       5      n U(       dP  [        [        [        [        U 5      5      5      [        U 5      :w  a!  T(       a  [        ST S35      e[        S5      eU $ ! [
         a     N{f = f)ar  
Normalizes an axis argument into a tuple of non-negative integer axes.

This handles shorthands such as ``1`` and converts them to ``(1,)``,
as well as performing the handling of negative indices covered by
`normalize_axis_index`.

By default, this forbids axes from being specified multiple times.
Used internally by multi-axis-checking logic.

Parameters
----------
axis : int, iterable of int
    The un-normalized index or indices of the axis.
ndim : int
    The number of dimensions of the array that `axis` should be normalized
    against.
argname : str, optional
    A prefix to put before the error message, typically the name of the
    argument.
allow_duplicate : bool, optional
    If False, the default, disallow an axis from being specified twice.

Returns
-------
normalized_axes : tuple of int
    The normalized axis index, such that `0 <= normalized_axis < ndim`
c              3   ó>   >#   • U  H  n[        UTT5      v •  M     g 7fr   )r-   )Ú.0r*   r,   r+   s     €€r   Ú	<genexpr>Ú'normalize_axis_tuple.<locals>.<genexpr>[   s   øé € ÐHÂ4¸RÔ% b¨$°×8Ð8Â4ùó   ƒzrepeated axis in `z
` argumentzrepeated axis)ÚtypeÚtupleÚlistÚoperatorÚindexÚ	TypeErrorr   ÚsetÚmapÚintÚ
ValueError)Úaxisr+   r,   Úallow_duplicates    `` r   Únormalize_axis_tupler@   7   s—   ù€ ô< ˆDƒzœ%¤˜Ó&ð	Ü—N’N 4Ó(Ð)ˆDô ÕHÁ4ÓHÓH€DÞœs¤3¤s¬3°£~Ó#6Ó7¼3¸t»9ÓDÞÜÐ1°'°¸*ÐEÓFÐFä˜_Ó-Ð-Ø€Køô ó 	Ùð	ús   �B# Â#
B0Â/B0c                 óJ   • U c  U $ [        U 5      S:w  a  [        S5      eU S   $ )Nr   zdoes not handle tuple axisr   )r   ÚNotImplementedError©r>   s    r   Úallow_only_single_axisrD   d   s,   € Ø�|ØˆÜ
ˆ4ƒy�Aƒ~Ü!Ð">Ó?Ð?Ø�‰7€Nr   c                 óø   • [        U5      [        [        4;  a  U4n[        U5      [        U 5      -   n[	        X5      n[        U 5      n[        U5       Vs/ s H  oDU;   a  SO
[        U5      PM     nnU$ s  snf )Nr   )r4   r6   r5   r   r@   ÚiterÚrangeÚnext)Ú	arr_shaper>   Úout_ndimÚshape_itr*   Úshapes         r   Úexpand_shaperM   l   sn   € äˆDƒzœ$¤˜Ó&ØˆwˆÜ�4‹yœ3˜y›>Ñ)€HÜ Ó/€DÜ�I‹€HÜ;@À¼?ÓKº?°R˜“*‰Q¤$ x£.Ò0¹?€EÐKØ€Lùò Ls   ÁA7c                 ó¦   • Uc&  SU-  nU R                  U5      R                  5       n U $ [        U R                  U5      nU R	                  U5      n U $ )N©r   )ÚexpandÚ
contiguousrM   rL   Úreshape)r    r>   r+   rL   s       r   Úapply_keepdimsrS   w   sS   € Ø�|à�t‘ˆØ—‘˜uÓ%×0Ñ0Ó2ˆð €Mô ˜VŸ\™\¨4Ó0ˆØ—‘ Ó&ˆØ€Mr   rC   c                 ó:   • U c  [        S U 5       5      nUS4$ X4$ )z#Flatten the arrays if axis is None.c              3   ó@   #   • U  H  oR                  5       v •  M     g 7fr   )Úflatten)r0   Úars     r   r1   Ú$axis_none_flatten.<locals>.<genexpr>…   s   é € Ð7ªw¨Ÿ
™
Ÿ˜ªwùs   ‚r   ©r5   )r>   Útensorss     r   Úaxis_none_flattenr[   ‚   s)   € à�|ÜÑ7©wÓ7Ó7ˆØ˜ˆzÐàˆ}Ðr   c           	      ó¢   • [         R                  nU" U R                  XS9(       d  [        SU R                   SU SU S35      e[	        X5      $ )a„  Dtype-cast tensor to target_dtype.

Parameters
----------
t : torch.Tensor
    The tensor to cast
target_dtype : torch dtype object
    The array dtype to cast all tensors to
casting : str
    The casting mode, see `np.can_cast`

 Returns
 -------
`torch.Tensor` of the `target_dtype` dtype

 Raises
 ------
 ValueError
    if the argument cannot be cast according to the `casting` rule

)ÚcastingzCannot cast array data from z to z according to the rule 'Ú')r   Úcan_cast_implr   r9   r!   )ÚtÚtarget_dtyper]   Úcan_casts       r   Útypecast_tensorrc   ‹   s[   € ô, ×)Ñ)€Há�A—G‘G˜\×;ÜØ*¨1¯7©7¨)ð 4Øˆ~Ð5°g°Y¸aðAó
ð 	
ô ˜!Ó*Ð*r   c                 ó2   ^^• [        UU4S jU  5       5      $ )Nc              3   ó>   >#   • U  H  n[        UTT5      v •  M     g 7fr   )rc   )r0   r`   r]   ra   s     €€r   r1   Ú#typecast_tensors.<locals>.<genexpr>¬   s   øé € ÐLÂG¸q”  L°'×:Ð:ÂGùr3   rY   )rZ   ra   r]   s    ``r   Útypecast_tensorsrg   «   s   ù€ ÜÕLÁGÓLÓLÐLr   c                 ó’   •  [         R                  " U 5      nU$ ! [         a"  nSU  S[        U5       S3n[	        U5      eS nAff = f)Nzfailed to convert z! to ndarray. 
Internal error is: Ú.)ÚtorchÚ	as_tensorr	   r   rB   )Úobjr    ÚeÚmesgs       r   Ú_try_convert_to_tensorro   ¯   sS   € ð(Ü—’ Ó%ˆð €Møô ó (Ø# C 5Ð(JÌ3ÈqË6È(ÐRSÐTˆÜ! $Ó'Ð'ûð(ús   ‚ š
A¤AÁAc                 óH  • [        U [        R                  5      (       a  U nOo[        R                  " 5       n[        R                  " [
        R                  " [        R                  5      5         [        U 5      n[        R                  " U5        [        XA5      nX4R                  -
  nUS:”  a!  UR                  SU-  UR                  -   5      n [        U5      nU(       a  UR                  5       nU$ ! [        R                  " U5        f = f! [         a    Sn NBf = f)ad  The core logic of the array(...) function.

Parameters
----------
obj : tensor_like
    The thing to coerce
dtype : torch.dtype object or None
    Coerce to this torch dtype
copy : bool
    Copy or not
ndmin : int
    The results as least this many dimensions
is_weak : bool
    Whether obj is a weakly typed python scalar.

Returns
-------
tensor : torch.Tensor
    a tensor object with requested dtype, ndim and copy semantics.

Notes
-----
This is almost a "tensor_like" coercive function. Does not handle wrapper
ndarrays (those should be handled in the ndarray-aware layer prior to
invoking this function).
r   rO   F)r   rj   ÚTensorÚget_default_dtypeÚset_default_dtyper   Úget_default_dtype_forÚfloat32ro   r!   r+   ÚviewrL   Úboolr=   Úclone)rl   r   ÚcopyÚndminr    Údefault_dtypeÚ
ndim_extras          r   Ú_coerce_to_tensorr}   ¸   së   € ô6 �#”u—|‘|×$Ñ$Ø‰ô ×/Ò/Ó1ˆÜ×Ò¤× BÒ BÄ5Ç=Á=Ó QÔRð	3Ü+¨CÓ0ˆFä×#Ò# MÔ2ô ˜FÓ*€Fð Ÿ™Ñ$€JØ�Aƒ~Ø—‘˜T JÑ.°·±Ñ=Ó>ˆðÜ�D‹zˆö
 Ø—‘“ˆà€Møô) ×#Ò# MÕ2ûô ó àŠðús   Á1C7 ÃD Ã7DÄD!Ä D!c                  ó´  • SSK Jn  [        U 5      S:X  a
  [        5       $ [        U 5      S:X  aj  U S   n[	        X!5      (       a  UR
                  $ [	        U[        5      (       a2  / nU H  n[        U5      nUR                  U5        M!     [        U5      $ U$ [	        U [        5      (       d!  [        S[        U 5      R                   35      e[        U 5      $ )zHConvert all ndarrays from `inputs` to tensors. (other things are intact)r   )Úndarrayr   z#Expected inputs to be a tuple, got )Ú_ndarrayr   r   r=   r   r    r5   Úndarrays_to_tensorsÚappendÚAssertionErrorr4   r   )Úinputsr   Úinput_ÚresultÚ	sub_inputÚ
sub_results         r   r�   r�   ö   sÂ   € å!ä
ˆ6ƒ{�aÓÜ‹|ÐÜ	ˆV‹˜Ó	Ø˜‘ˆÜ�f×&Ñ&Ø—=‘=Ð Ü˜¤×&Ñ&ØˆFÛ#�	Ü0°Ó;�
Ø—‘˜jÖ)ñ $ô ˜“=Ð àˆMä˜&¤%×(Ñ(Ü Ø5´d¸6³l×6KÑ6KÐ5LÐMóð ô # 6Ó*Ð*r   r   )NF)NFr   )Ú__doc__r7   rj   Ú r   r   r=   Ú
IndexErrorr   r9   ÚRuntimeErrorr   r!   r(   r-   r@   rD   rM   rS   r[   rc   rg   ro   r}   r�   r   r   r   Ú<module>r�      s   ðñ Rã ã å òô	�
˜Jô 	ô	�Y ô 	òòôô*òZòòð &*õ ò+ò@Mòô;ó|+r   