Ë
    L²jœ  ã                   ó´   — d Z ddlZddlZddlmZ d„ Z G d„ dee«      Z G d„ d	e	e
«      Zd
„ Zd„ Zdd„Zdd„Zd„ Zd„ Zd„ Zddœd„Zd„ Zd„ Zd„ Zdd„Zd„ Zy)zKAssorted utilities, which do not need anything other then torch and stdlib.é    Né   )Ú_dtypes_implc                 ó\   — t        | t        «      ry	 t        | «       y# t        $ r Y yw xY w)NFT)Ú
isinstanceÚstrÚlenÚ	Exception)Úseqs    úQ/var/www/html/ia-enhanced/venv/lib/python3.12/site-packages/torch/_numpy/_util.pyÚis_sequencer      s4   € Ü�#”sÔØðÜˆCŒð øô ò Ùðús   “ Ÿ	+ª+c                   ó   — e Zd Zy)Ú	AxisErrorN©Ú__name__Ú
__module__Ú__qualname__© ó    r   r   r      ó   „ Ør   r   c                   ó   — e Zd Zy)ÚUFuncTypeErrorNr   r   r   r   r   r      r   r   r   c                 óJ   — |� | j                   |k7  r| j                  |«      } | S ©N)ÚdtypeÚto)Útensorr   s     r   Úcast_if_neededr      s&   € àÐ˜VŸ\™\¨UÒ2Ø—‘˜5Ó!ˆØ€Mr   c                 ó¤   — t        j                  | j                  «      dk  r-| j                  t        j                  «       j
                  «      } | S )Né   )r   Ú	_categoryr   r   Údefault_dtypesÚfloat_dtype)Úxs    r   Úcast_int_to_floatr$   &   s;   € ä×Ñ˜aŸg™gÓ&¨Ò*Ø�D‰D”×,Ñ,Ó.×:Ñ:Ó;ˆØ€Hr   c                 óX   — | | cxk  r|k  sn t        d| › d|› �«      ‚| dk  r| |z  } | S )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Ø
ˆd‰
ˆØ€Ir   c                 óF  ‡‡— t        | «      t        t        fvr	 t        j                  | «      g} t        ˆˆfd„| D «       «      } |sJt        t        t        t        | «      «      «      t        | «      k7  r‰rt        d‰› d�«      ‚t        d«      ‚| S # t
        $ r Y Œnw xY w)aÎ  
    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   ó8   •K  — | ]  }t        |‰‰«      –— Œ y ­wr   )r)   )Ú.0r&   r(   r'   s     €€r   ú	<genexpr>z'normalize_axis_tuple.<locals>.<genexpr>[   s   øè ø€ ÒH¸RÔ% b¨$°×8ÑHùó   ƒ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 Â	B ÂB c                 óF   — | €| S t        | «      dk7  rt        d«      ‚| d   S )Nr   zdoes not handle tuple axisr   )r   ÚNotImplementedError©r9   s    r   Úallow_only_single_axisr?   d   s,   € Ø€|ØˆÜ
ˆ4ƒy�A‚~Ü!Ð">Ó?Ð?Ø�‰7€Nr   c                 óî   — t        |«      t        t        fvr|f}t        |«      t        | «      z   }t	        ||«      }t        | «      }t        |«      D �cg c]  }||v rdn
t        |«      ‘Œ }}|S c c}w )Nr   )r/   r1   r0   r   r;   ÚiterÚrangeÚnext)Ú	arr_shaper9   Úout_ndimÚshape_itr&   Úshapes         r   Úexpand_shaperH   l   sq   € äˆDƒzœ$¤˜Ñ&ØˆwˆÜ�4‹yœ3˜y›>Ñ)€HÜ  hÓ/€DÜ�I‹€HÜ;@À»?ÖK°R�"˜‘*‰Q¤$ x£.Ñ0ÐK€EÐKØ€Lùò Ls   ÁA2c                 ó¤   — |€&d|z  }| j                  |«      j                  «       } | S t        | j                  |«      }| j	                  |«      } | S )N©r   )ÚexpandÚ
contiguousrH   rG   Úreshape)r   r9   r'   rG   s       r   Úapply_keepdimsrN   w   sS   € Ø€|à�t‘ˆØ—‘˜uÓ%×0Ñ0Ó2ˆð €Mô ˜VŸ\™\¨4Ó0ˆØ—‘ Ó&ˆØ€Mr   r>   c                 ó:   — | €t        d„ |D «       «      }|dfS || fS )z#Flatten the arrays if axis is None.c              3   ó<   K  — | ]  }|j                  «       –— Œ y ­wr   )Úflatten)r,   Úars     r   r-   z$axis_none_flatten.<locals>.<genexpr>…   s   è ø€ Ò7¨˜Ÿ
™
ŸÑ7ùs   ‚r   ©r0   )r9   Útensorss     r   Úaxis_none_flattenrU   ‚   s+   € à€|ÜÑ7¨wÔ7Ó7ˆØ˜ˆzÐà˜ˆ}Ðr   c           	      ó¢   — t         j                  } || j                  ||¬«      st        d| j                  › d|› d|› d�«      ‚t	        | |«      S )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   r4   r   )ÚtÚtarget_dtyperW   Úcan_casts       r   Útypecast_tensorr]   ‹   s_   € ô, ×)Ñ)€Há�A—G‘G˜\°7Õ;ÜØ*¨1¯7©7¨)ð 4Øˆ~Ð5°g°Y¸aðAó
ð 	
ô ˜!˜\Ó*Ð*r   c                 ó0   ‡‡— t        ˆˆfd„| D «       «      S )Nc              3   ó8   •K  — | ]  }t        |‰‰«      –— Œ y ­wr   )r]   )r,   rZ   rW   r[   s     €€r   r-   z#typecast_tensors.<locals>.<genexpr>¬   s   øè ø€ ÒL¸q”  L°'×:ÑLùr.   rS   )rT   r[   rW   s    ``r   Útypecast_tensorsr`   «   s   ù€ ÜÔLÀGÔLÓLÐLr   c                 óŽ   — 	 t        j                  | «      }|S # t        $ r"}d| › dt        |«      › d�}t	        |«      ‚d }~ww xY w)Nzfailed to convert z! to ndarray. 
Internal error is: ú.)ÚtorchÚ	as_tensorr	   r   r=   )Úobjr   ÚeÚmesgs       r   Ú_try_convert_to_tensorrh   ¯   sS   € ð(Ü—‘ Ó%ˆð €Møô ò (Ø# C 5Ð(JÌ3ÈqË6È(ÐRSÐTˆÜ! $Ó'Ð'ûð(ús   ‚ ™	A¢?¿Ac                 ó*  — t        | t        j                  «      r| }nkt        j                  «       }t        j                  t        j                  t        j                  «      «       	 t        | «      }t        j                  |«       t        ||«      }||j                  z
  }|dkD  r!|j                  d|z  |j                  z   «      }	 t        |«      }|r|j                  «       }|S # t        j                  |«       w xY w# t        $ r d}Y Œ;w xY w)a¼  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   rJ   F)r   rc   ÚTensorÚget_default_dtypeÚset_default_dtyper   Úget_default_dtype_forÚfloat32rh   r   r'   ÚviewrG   Úboolr8   Úclone)re   r   ÚcopyÚndminr   Údefault_dtypeÚ
ndim_extras          r   Ú_coerce_to_tensorrv   ¸   sì   € ô6 �#”u—|‘|Ô$Ø‰ô ×/Ñ/Ó1ˆÜ×Ñ¤× BÑ BÄ5Ç=Á=Ó QÔRð	3Ü+¨CÓ0ˆFä×#Ñ# MÔ2ô ˜F EÓ*€Fð ˜Ÿ™Ñ$€JØ�A‚~Ø—‘˜T JÑ.°·±Ñ=Ó>ˆðÜ�D‹zˆñ
 Ø—‘“ˆà€Møô) ×#Ñ# MÕ2ûô ò àŠðús   Á)C* ÃD Ã*DÄDÄDc                  ó�  — ddl m} t        | «      dk(  r
t        «       S t        | «      dk(  r_| d   }t	        ||«      r|j
                  S t	        |t        «      r0g }|D ]  }t        |«      }|j                  |«       Œ  t        |«      S |S t	        | t        «      s!t        dt        | «      j                  › �«      ‚t        | «      S )zHConvert all ndarrays from `inputs` to tensors. (other things are intact)r   )Úndarrayr   z#Expected inputs to be a tuple, got )Ú_ndarrayrx   r   r8   r   r   r0   Úndarrays_to_tensorsÚappendÚAssertionErrorr/   r   )Úinputsrx   Úinput_ÚresultÚ	sub_inputÚ
sub_results         r   rz   rz   ö   sÀ   € å!ä
ˆ6ƒ{�aÒÜ‹|ÐÜ	ˆV‹˜Ò	Ø˜‘ˆÜ�f˜gÔ&Ø—=‘=Ð Ü˜¤Ô&ØˆFØ#ò *�	Ü0°Ó;�
Ø—‘˜jÕ)ð*ô ˜“=Ð àˆMä˜&¤%Ô(Ü Ø5´d¸6³l×6KÑ6KÐ5LÐMóð ô # 6Ó*Ð*r   r   )NF)NFr   )Ú__doc__r2   rc   Ú r   r   r8   Ú
IndexErrorr   r4   ÚRuntimeErrorr   r   r$   r)   r;   r?   rH   rN   rU   r]   r`   rh   rv   rz   r   r   r   ú<module>r†      s   ðñ Rã ã å òô	�
˜Jô 	ô	�Y ô 	òòóó*òZòòð &*ô ò+ò@Mòó;ó|+r   