Ë
    g^(h…  ã                   ó´   — 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)zLAssorted 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    úP/var/www/skyplay_api_hub/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           
      ój  — t        | «      t        t        fvr	 t        j                  | «      g} t        | D �cg c]  }t        |||«      ‘Œ c}«      } |sJt        t        t        t        | «      «      «      t        | «      k7  r|rt        d|› d�«      ‚t        d«      ‚| S # t
        $ r Y Œ}w xY wc c}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`
    zrepeated axis in `z
` argumentzrepeated axis)ÚtypeÚtupleÚlistÚoperatorÚindexÚ	TypeErrorr)   r   ÚsetÚmapÚintÚ
ValueError)Úaxisr'   r(   Úallow_duplicater&   s        r   Únormalize_axis_tupler7   8   sª   € ô< ˆDƒzœ%¤˜Ñ&ð	Ü—N‘N 4Ó(Ð)ˆDô ÀDÖI¸bÔ& r¨4°Õ9ÒIÓJ€DÙœs¤3¤s¬3°£~Ó#6Ó7¼3¸t»9ÒDÙÜÐ1°'°¸*ÐEÓFÐFä˜_Ó-Ð-Ø€Køô ò 	Ùð	üò Js   ™B! ¸B0Â!	B-Â,B-c                 óF   — | €| S t        | «      dk7  rt        d«      ‚| d   S )Nr   zdoes not handle tuple axisr   )r   ÚNotImplementedError©r5   s    r   Úallow_only_single_axisr;   e   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+   r-   r,   r   r7   ÚiterÚrangeÚnext)Ú	arr_shaper5   Úout_ndimÚshape_itr&   Úshapes         r   Úexpand_shaperD   m   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Ú
contiguousrD   rC   Úreshape)r   r5   r'   rC   s       r   Úapply_keepdimsrJ   x   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)Ú.0Úars     r   ú	<genexpr>z$axis_none_flatten.<locals>.<genexpr>†   s   è ø€ Ò7¨˜Ÿ
™
ŸÑ7ùs   ‚r   ©r,   )r5   Útensorss     r   Úaxis_none_flattenrS   ƒ   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   r0   r   )ÚtÚtarget_dtyperU   Ú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[   )rN   rX   rU   rY   s     €€r   rP   z#typecast_tensors.<locals>.<genexpr>­   s   øè ø€ ÒL¸q”  L°'×:ÑLùs   ƒrQ   )rR   rY   rU   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   r9   )Úobjr   ÚeÚmesgs       r   Ú_try_convert_to_tensorrf   °   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   «      }|r|j                  «       }|S # t        j                  |«       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" coersion function. Does not handle wrapper
    ndarrays (those should be handled in the ndarray-aware layer prior to
    invoking this function).
    r   rF   )r   ra   ÚTensorÚget_default_dtypeÚset_default_dtyper   Úget_default_dtype_forÚfloat32rf   r   r'   ÚviewrC   Úclone)rc   r   ÚcopyÚndminr   Údefault_dtypeÚ
ndim_extras          r   Ú_coerce_to_tensorrs   ¹   sÉ   € ô6 �#”u—|‘|Ô$Ø‰ô ×/Ñ/Ó1ˆÜ×Ñ¤× BÑ BÄ5Ç=Á=Ó QÔRð	3Ü+¨CÓ0ˆFä×#Ñ# MÔ2ô ˜F EÓ*€Fð ˜Ÿ™Ñ$€JØ�A‚~Ø—‘˜T JÑ.°·±Ñ=Ó>ˆñ Ø—‘“ˆà€Møô ×#Ñ# MÕ2ús   Á)C ÃC5c                  óR  — 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J ‚t        | «      S )zHConvert all ndarrays from `inputs` to tensors. (other things are intact)r   )Úndarrayr   )	Ú_ndarrayru   r   r4   r   r   r,   Úndarrays_to_tensorsÚappend)Úinputsru   Úinput_ÚresultÚ	sub_inputÚ
sub_results         r   rw   rw   ñ   s¢   € å!ä
ˆ6ƒ{�aÒÜ‹|ÐÜ	ˆV‹˜Ò	Ø˜‘ˆÜ�f˜gÔ&Ø—=‘=Ð Ü˜¤Ô&ØˆFØ#ò *�	Ü0°Ó;�
Ø—‘˜jÕ)ð*ô ˜“=Ð àˆMä˜&¤%Ô(Ð(Ð(Ü" 6Ó*Ð*r   r   )NF)NFr   )Ú__doc__r.   ra   Ú r   r   r4   Ú
IndexErrorr   r0   ÚRuntimeErrorr   r   r$   r)   r7   r;   rD   rJ   rS   r[   r^   rf   rs   rw   r   r   r   ú<module>r‚      s€   ðñó ã å òô	�
˜Jô 	ô	�Y ô 	òòóó*òZòòð &*ô ò+ò@Mòó5óp+r   