§
    ŠŠtjœ  ã                   óÂ   — 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dS )zKAssorted utilities, which do not need anything other than torch and stdlib.é    Né   )Ú_dtypes_implc                 óx   — t          | t          ¦  «        rdS 	 t          | ¦  «         n# t          $ r Y dS w xY wdS )NFT)Ú
isinstanceÚstrÚlenÚ	Exception)Úseqs    úP/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/_numpy/_util.pyÚis_sequencer      sR   € Ý�#•sÑÔð ØˆuðÝˆC‰ŒˆˆøÝð ð ð Øˆuˆuðøøøàˆ4s   ™) ©
7¶7c                   ó   — e Zd ZdS )Ú	AxisErrorN©Ú__name__Ú
__module__Ú__qualname__© ó    r   r   r      ó   € € € € € Ø€Dr   r   c                   ó   — e Zd ZdS )ÚUFuncTypeErrorNr   r   r   r   r   r      r   r   r   c                 óJ   — |� | j         |k    r|                      |¦  «        } | S ©N)ÚdtypeÚto)Útensorr   s     r   Úcast_if_neededr      s*   € àÐ˜Vœ\¨UÒ2Ð2Ø—’˜5Ñ!Ô!ˆØ€Mr   c                 ó–   — t          j        | j        ¦  «        dk     r+|                      t          j        ¦   «         j        ¦  «        } | S )Né   )r   Ú	_categoryr   r   Údefault_dtypesÚfloat_dtype)Úxs    r   Úcast_int_to_floatr$   &   s<   € åÔ˜aœgÑ&Ô&¨Ò*Ð*Ø�DŠD•Ô,Ñ.Ô.Ô:Ñ;Ô;ˆØ€Hr   c                 óf   — | | 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)   .   sY   € ØˆE�RÐÐÒÐ˜$ÒÐÐÐÝÐS ÐSÐSÈTÐSÐSÑTÔTÐTØ	ˆA‚v€vØ
ˆd‰
ˆØ€Ir   Fc                 ó–  ‡‡— t          | ¦  «        t          t          fvr'	 t          j        | ¦  «        g} n# t
          $ r Y nw xY wt          ˆˆfd„| D ¦   «         ¦  «        } |sdt          t          t          t          | ¦  «        ¦  «        ¦  «        t          | ¦  «        k    r$‰rt          d‰› d�¦  «        ‚t          d¦  «        ‚| S )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   ó:   •K  — | ]}t          |‰‰¦  «        V — Œd S r   )r)   )Ú.0r&   r(   r'   s     €€r   ú	<genexpr>z'normalize_axis_tuple.<locals>.<genexpr>[   s0   øè è € ÐHÐH¸RÕ% b¨$°Ñ8Ô8ÐHÐHÐHÐHÐHÐHr   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„z�%¥˜Ð&Ð&ð	Ý”N 4Ñ(Ô(Ð)ˆDˆDøÝð 	ð 	ð 	ØˆDð	øøøõ ÐHÐHÐHÐHÐHÀ4ÐHÑHÔHÑHÔH€DØð .�s¥3¥s­3°¡~¤~Ñ#6Ô#6Ñ7Ô7½3¸t¹9¼9ÒDÐDØð 	.ÝÐE°'ÐEÐEÐEÑFÔFÐFå˜_Ñ-Ô-Ð-Ø€Ks   ¡7 ·
AÁAc                 ó^   — | €| S t          | ¦  «        dk    rt          d¦  «        ‚| d         S )Nr   zdoes not handle tuple axisr   )r   ÚNotImplementedError©r8   s    r   Úallow_only_single_axisr>   d   s3   € Ø€|ØˆÝ
ˆ4�y„y�A‚~€~Ý!Ð">Ñ?Ô?Ð?Ø�Œ7€Nr   c                 óþ   ‡‡— t          ‰¦  «        t          t          fvr‰fŠt          ‰¦  «        t          | ¦  «        z   }t	          ‰|¦  «        Št          | ¦  «        Šˆˆfd„t          |¦  «        D ¦   «         }|S )Nc                 ó:   •— g | ]}|‰v rd nt          ‰¦  «        ‘ŒS ©r   )Únext)r,   r&   r8   Úshape_its     €€r   ú
<listcomp>z expand_shape.<locals>.<listcomp>s   s+   ø€ ÐKÐKÐK°R�"˜�*�*ˆQˆQ¥$ x¡.¤.ÐKÐKÐKr   )r.   r0   r/   r   r:   ÚiterÚrange)Ú	arr_shaper8   Úout_ndimÚshaperC   s    `  @r   Úexpand_shaperJ   l   sw   øø€ åˆD�z„z�$¥˜Ð&Ð&ØˆwˆÝ�4‰yŒy�3˜y™>œ>Ñ)€HÝ  hÑ/Ô/€DÝ�I‰Œ€HØKÐKÐKÐKÐK½5À¹?¼?ÐKÑKÔK€EØ€Lr   c                 ó¸   — |€-d|z  }|                       |¦  «                             ¦   «         } n*t          | j        |¦  «        }|                      |¦  «        } | S )NrA   )ÚexpandÚ
contiguousrJ   rI   Úreshape)r   r8   r'   rI   s       r   Úapply_keepdimsrO   w   sV   € Ø€|à�t‘ˆØ—’˜uÑ%Ô%×0Ò0Ñ2Ô2ˆˆå˜Vœ\¨4Ñ0Ô0ˆØ—’ Ñ&Ô&ˆØ€Mr   r=   c                 óH   — | €t          d„ |D ¦   «         ¦  «        }|dfS || fS )z#Flatten the arrays if axis is None.Nc              3   ó>   K  — | ]}|                      ¦   «         V — Œd S r   )Úflatten)r,   Úars     r   r-   z$axis_none_flatten.<locals>.<genexpr>…   s*   è è € Ð7Ð7¨˜Ÿ
š
™œÐ7Ð7Ð7Ð7Ð7Ð7r   r   ©r/   )r8   Útensorss     r   Úaxis_none_flattenrV   ‚   s7   € à€|ÝÐ7Ð7¨wÐ7Ñ7Ô7Ñ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   r3   r   )ÚtÚtarget_dtyperX   Úcan_casts       r   Útypecast_tensorr^   ‹   s…   € õ, Ô)€Hàˆ8�A”G˜\°7Ð;Ñ;Ô;ð 
ÝðA¨1¬7ð Að AØðAð AØ6=ðAð Að Añ
ô 
ð 	
õ ˜!˜\Ñ*Ô*Ð*r   c                 ó>   ‡‡— t          ˆˆfd„| D ¦   «         ¦  «        S )Nc              3   ó:   •K  — | ]}t          |‰‰¦  «        V — Œd S r   )r^   )r,   r[   rX   r\   s     €€r   r-   z#typecast_tensors.<locals>.<genexpr>¬   s/   øè è € ÐLÐL¸q•  L°'Ñ:Ô:ÐLÐLÐLÐLÐLÐLr   rT   )rU   r\   rX   s    ``r   Útypecast_tensorsra   «   s*   øø€ ÝÐLÐLÐLÐLÐLÀGÐLÑLÔLÑLÔLÐLr   c                 ó    — 	 t          j        | ¦  «        }n7# t          $ r*}d| › dt          |¦  «        › d�}t	          |¦  «        ‚d }~ww xY w|S )Nzfailed to convert z! to ndarray. 
Internal error is: ú.)ÚtorchÚ	as_tensorr	   r   r<   )Úobjr   ÚeÚmesgs       r   Ú_try_convert_to_tensorri   ¯   sj   € ð(Ý” Ñ%Ô%ˆˆøÝð (ð (ð (ØT CÐTÐTÍ3ÈqÉ6Ì6ÐTÐTÐTˆÝ! $Ñ'Ô'Ð'øøøøð(øøøð €Ms   ‚ —
A¡%AÁAc                 ó4  — t          | t          j        ¦  «        r| }n�t          j        ¦   «         }t          j        t          j        t          j        ¦  «        ¦  «         	 t          | ¦  «        }t          j        |¦  «         n# t          j        |¦  «         w xY wt          ||¦  «        }||j
        z
  }|dk    r |                     d|z  |j        z   ¦  «        }	 t          |¦  «        }n# t          $ r d}Y nw xY w|r|                     ¦   «         }|S )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   rA   F)r   rd   ÚTensorÚget_default_dtypeÚset_default_dtyper   Úget_default_dtype_forÚfloat32ri   r   r'   ÚviewrI   Úboolr7   Úclone)rf   r   ÚcopyÚndminr   Údefault_dtypeÚ
ndim_extras          r   Ú_coerce_to_tensorrw   ¸   s!  € õ6 �#•u”|Ñ$Ô$ð 3Øˆˆõ Ô/Ñ1Ô1ˆÝÔ¥Ô BÅ5Ä=Ñ QÔ QÑRÔRÐRð	3Ý+¨CÑ0Ô0ˆFåÔ# MÑ2Ô2Ð2Ð2ø�EÔ# MÑ2Ô2Ð2Ð2øøøõ ˜F EÑ*Ô*€Fð ˜œÑ$€JØ�A‚~€~Ø—’˜T JÑ.°´Ñ=Ñ>Ô>ˆðÝ�D‰zŒzˆˆøÝð ð ð àˆˆˆðøøøð ð  Ø—’‘”ˆà€Ms   Á"B ÂBÃ C0 Ã0C?Ã>C?c                  óæ  — ddl m} t          | ¦  «        dk    rt          ¦   «         S t          | ¦  «        dk    rp| d         }t	          ||¦  «        r|j        S t	          |t          ¦  «        r:g }|D ]&}t          |¦  «        }|                     |¦  «         Œ'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 )Ú_ndarrayry   r   r7   r   r   r/   Úndarrays_to_tensorsÚappendÚAssertionErrorr.   r   )Úinputsry   Úinput_ÚresultÚ	sub_inputÚ
sub_results         r   r{   r{   ö   s  € à!Ð!Ð!Ð!Ð!Ð!å
ˆ6�{„{�aÒÐÝ‰|Œ|ÐÝ	ˆV‰Œ˜Ò	Ð	Ø˜”ˆÝ�f˜gÑ&Ô&ð 		Ø”=Ð Ý˜¥Ñ&Ô&ð 	ØˆFØ#ð *ð *�	Ý0°Ñ;Ô;�
Ø—’˜jÑ)Ô)Ð)Ð)Ý˜‘=”=Ð àˆMå˜&¥%Ñ(Ô(ð 	Ý ØMµd¸6±l´lÔ6KÐMÐMñô ð õ # 6Ñ*Ô*Ð*r   r   )NF)NFr   )Ú__doc__r1   rd   Ú r   r   r7   Ú
IndexErrorr   r3   ÚRuntimeErrorr   r   r$   r)   r:   r>   rJ   rO   rV   r^   ra   ri   rw   r{   r   r   r   ú<module>r‡      sŠ  ðð RÐ Qà €€€à €€€à Ð Ð Ð Ð Ð ðð ð ð	ð 	ð 	ð 	ð 	�
˜Jñ 	ô 	ð 	ð	ð 	ð 	ð 	ð 	�Y ñ 	ô 	ð 	ðð ð ðð ð ðð ð ð ð*ð *ð *ð *ðZð ð ðð ð ðð ð ð &*ð ð ð ð ð ð+ð +ð +ð@Mð Mð Mðð ð ð;ð ;ð ;ð ;ð|+ð +ð +ð +ð +r   