§
    ¦˜ºhN5  ã                   óè   — d Z ddlZddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 d„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Z G d„ d¦  «        Zd„ Zd„ Z G d„ d¦  «        Z e¦   «         Zd„ Zd„ Zdddœd„Zd„ Zd„ ZdS )zTools to support array_api.é    N©Úwrapsé   )Ú
get_configé   )Úparse_versionc                 óÖ   — | rd	 ddl }n# t          $ r t          d¦  «        ‚w xY wt          t          j        ¦  «        }d}|t          |¦  «        k     rt          d|› d�¦  «        ‚dS dS )z³Check that array_api_compat is installed and NumPy version is compatible.

    array_api_compat follows NEP29, which has a higher minimum NumPy version than
    scikit-learn.
    r   NzKarray_api_compat is required to dispatch arrays using the API specificationz1.21zNumPy must be z7 or newer to dispatch array using the API specification)Úarray_api_compatÚImportErrorr   ÚnumpyÚ__version__)Úarray_api_dispatchr
   Únumpy_versionÚmin_numpy_versions       ú`/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/sklearn/utils/_array_api.pyÚ_check_array_api_dispatchr      s¹   € ð ð ð	Ø#Ð#Ð#Ð#Ð#øÝð 	ð 	ð 	Ýð!ñô ð ð	øøøõ &¥eÔ&7Ñ8Ô8ˆØ"ÐØ�=Ð):Ñ;Ô;Ò;Ð;Ýð)Ð!2ð )ð )ð )ñô ð ðð ð <Ð;s   „	 ‰#c                 ó`   — t          | t          j        t          j        f¦  «        rdS | j        S )a  Hardware device the array data resides on.

    Parameters
    ----------
    x : array
        Array instance from NumPy or an array API compatible library.

    Returns
    -------
    out : device
        `device` object (see the "Device Support" section of the array API spec).
    Úcpu)Ú
isinstancer   ÚndarrayÚgenericÚdevice©Úxs    r   r   r   $   s+   € õ �!•e”m¥U¤]Ð3Ñ4Ô4ð ØˆuØŒ8€Oó    c                 ó4   — t          j        | j        ¦  «        S )zêReturn the total number of elements of x.

    Parameters
    ----------
    x : array
        Array instance from NumPy or an array API compatible library.

    Returns
    -------
    out : int
        Total number of elements.
    )ÚmathÚprodÚshaper   s    r   Úsizer    6   s   € õ Œ9�Q”WÑÔÐr   c                 ó   — | j         dv S )z%Return True if xp is backed by NumPy.>   úarray_api_compat.numpyr   únumpy.array_api)Ú__name__©Úxps    r   Ú_is_numpy_namespacer'   F   s   € àŒ;ÐPÐPÐPr   c                óŒ   ‡ ‡— t          |t          ¦  «        rt          ˆ ˆfd„|D ¦   «         ¦  «        S t          ‰ |‰¬¦  «        S )zàReturns a boolean indicating whether a provided dtype is of type "kind".

    Included in the v2022.12 of the Array API spec.
    https://data-apis.org/array-api/latest/API_specification/generated/array_api.isdtype.html
    c              3   ó<   •K  — | ]}t          ‰|‰¬ ¦  «        V — ŒdS ©r%   N©Ú_isdtype_single©Ú.0ÚkÚdtyper&   s     €€r   ú	<genexpr>zisdtype.<locals>.<genexpr>R   s2   øè è € ÐBÐB¸•? 5¨!°Ð3Ñ3Ô3ÐBÐBÐBÐBÐBÐBr   r%   )r   ÚtupleÚanyr,   )r0   Úkindr&   s   ` `r   Úisdtyper5   K   sS   øø€ õ �$�ÑÔð 3ÝÐBÐBÐBÐBÐB¸TÐBÑBÔBÑBÔBÐBå˜u d¨rÐ2Ñ2Ô2Ð2r   c                ó˜  ‡ ‡— t          |t          ¦  «        �r-|dk    r‰ ‰j        k    S |dk    r‰ ‰j        ‰j        ‰j        ‰j        hv S |dk    r‰ ‰j        ‰j        ‰j	        ‰j
        hv S |dk    rt          ˆ ˆfd„dD ¦   «         ¦  «        S |dk    r‰ ‰j        ‰j        hv S |dk    rft          ¦   «         }t          ‰d	¦  «        r|                     ‰j        ¦  «         t          ‰d
¦  «        r|                     ‰j        ¦  «         ‰ |v S |dk    rt          ˆ ˆfd„dD ¦   «         ¦  «        S t'          d|›�¦  «        ‚‰ |k    S )NÚboolúsigned integerúunsigned integerÚintegralc              3   ó<   •K  — | ]}t          ‰|‰¬ ¦  «        V — ŒdS r*   r+   r-   s     €€r   r1   z"_isdtype_single.<locals>.<genexpr>`   óF   øè è € ð ð àõ    q¨RÐ0Ñ0Ô0ðð ð ð ð ð r   )r8   r9   úreal floatingúcomplex floatingÚ	complex64Ú
complex128Únumericc              3   ó<   •K  — | ]}t          ‰|‰¬ ¦  «        V — ŒdS r*   r+   r-   s     €€r   r1   z"_isdtype_single.<locals>.<genexpr>p   r<   r   )r:   r=   r>   zUnrecognized data type kind: )r   Ústrr7   Úint8Úint16Úint32Úint64Úuint8Úuint16Úuint32Úuint64r3   Úfloat32Úfloat64ÚsetÚhasattrÚaddr?   r@   Ú
ValueError)r0   r4   r&   Úcomplex_dtypess   ` ` r   r,   r,   W   sÂ  øø€ Ý�$�ÑÔñ Ø�6Š>ˆ>Ø˜BœGÒ#Ð#ØÐ%Ò%Ð%Ø˜RœW b¤h°´¸"¼(ÐCÐCÐCØÐ'Ò'Ð'Ø˜RœX r¤y°"´)¸R¼YÐGÐGÐGØ�ZÒÐÝð ð ð ð ð à?ðñ ô ñ ô ð ð �_Ò$Ð$Ø˜RœZ¨¬Ð4Ð4Ð4ØÐ'Ò'Ð'õ !™UœUˆNÝ�r˜;Ñ'Ô'ð 1Ø×"Ò" 2¤<Ñ0Ô0Ð0Ý�r˜<Ñ(Ô(ð 2Ø×"Ò" 2¤=Ñ1Ô1Ð1Ø˜NÐ*Ð*Ø�YÒÐÝð ð ð ð ð àJðñ ô ñ ô ð õ
 ÐE¸TÐEÐEÑFÔFÐFà˜Š}Ðr   c                   ó0   — e Zd ZdZd„ Zd„ Zddœd„Zd„ ZdS )	Ú_ArrayAPIWrapperaÃ  sklearn specific Array API compatibility wrapper

    This wrapper makes it possible for scikit-learn maintainers to
    deal with discrepancies between different implementations of the
    Python array API standard and its evolution over time.

    The Python array API standard specification:
    https://data-apis.org/array-api/latest/

    Documentation of the NumPy implementation:
    https://numpy.org/neps/nep-0047-array-api-standard.html
    c                 ó   — || _         d S ©N)Ú
_namespace)ÚselfÚarray_namespaces     r   Ú__init__z_ArrayAPIWrapper.__init__ˆ   s   € Ø)ˆŒˆˆr   c                 ó,   — t          | j        |¦  «        S rV   )ÚgetattrrW   )rX   Únames     r   Ú__getattr__z_ArrayAPIWrapper.__getattr__‹   s   € Ý�t”¨Ñ-Ô-Ð-r   r   ©Úaxisc                ó¤  ‡— | j         j        dk    r1t          j        ‰||¬¦  «        }| j                              |¦  «        S |dvrt          d|› �¦  «        ‚‰j        dvrt          d‰j        › �¦  «        ‚|dk    r)‰j        dk    rˆfd	„|D ¦   «         }nˆfd
„|D ¦   «         }nˆfd„|D ¦   «         }| j                              ||¬¦  «        S )Nr#   r_   >   r   r   z&Only axis in (0, 1) is supported. Got >   r   r   z(Only X.ndim in (1, 2) is supported. Got r   r   c                 ó    •— g | ]
}‰|         ‘ŒS © rc   ©r.   ÚiÚXs     €r   ú
<listcomp>z)_ArrayAPIWrapper.take.<locals>.<listcomp>Ÿ   s   ø€ Ð2Ð2Ð2 Q˜A˜aœDÐ2Ð2Ð2r   c                 ó(   •— g | ]}‰|d d …f         ‘ŒS rV   rc   rd   s     €r   rg   z)_ArrayAPIWrapper.take.<locals>.<listcomp>¡   s%   ø€ Ð5Ð5Ð5¨˜A˜a   ˜dœGÐ5Ð5Ð5r   c                 ó(   •— g | ]}‰d d …|f         ‘ŒS rV   rc   rd   s     €r   rg   z)_ArrayAPIWrapper.take.<locals>.<listcomp>£   s%   ø€ Ð1Ð1Ð1 A˜˜!˜!˜!˜Q˜$œÐ1Ð1Ð1r   )rW   r$   r   ÚtakeÚasarrayrQ   ÚndimÚstack)rX   rf   Úindicesr`   ÚX_npÚselecteds    `    r   rj   z_ArrayAPIWrapper.takeŽ   s
  ø€ ð Œ?Ô#Ð'8Ò8Ð8Ý”:˜a ¨tÐ4Ñ4Ô4ˆDØ”?×*Ò*¨4Ñ0Ô0Ð0ð �vÐÐÝÐLÀdÐLÐLÑMÔMÐMàŒ6˜ÐÐÝÐPÈÌÐPÐPÑQÔQÐQà�1Š9ˆ9ØŒv˜Š{ˆ{Ø2Ð2Ð2Ð2¨'Ð2Ñ2Ô2��à5Ð5Ð5Ð5¨WÐ5Ñ5Ô5��à1Ð1Ð1Ð1¨Ð1Ñ1Ô1ˆHØŒ×$Ò$ X°DÐ$Ñ9Ô9Ð9r   c                 ó0   — t          ||| j        ¬¦  «        S ©Nr%   )r5   rW   ©rX   r0   r4   s      r   r5   z_ArrayAPIWrapper.isdtype¦   s   € Ý�u˜d t¤Ð7Ñ7Ô7Ð7r   N)r$   Ú
__module__Ú__qualname__Ú__doc__rZ   r^   rj   r5   rc   r   r   rT   rT   z   si   € € € € € ðð ð*ð *ð *ð.ð .ð .ð ()ð :ð :ð :ð :ð :ð08ð 8ð 8ð 8ð 8r   rT   c                 ó2   — | dvrt          d| ›�¦  «        ‚d S )N>   Nr   zUnsupported device for NumPy: )rQ   )r   s    r   Ú_check_device_cpurx   ª   s,   € Ø�]Ð"Ð"ÝÐD¸&ÐDÐDÑEÔEÐEð #Ð"r   c                 ó<   ‡ — t          ‰ ¦  «        ˆ fd„¦   «         }|S )Nc                  óZ   •— t          |                     dd ¦  «        ¦  «          ‰| i |¤ŽS )Nr   )rx   Úpop)ÚargsÚkwargsÚfuncs     €r   Úwrapped_funcz(_accept_device_cpu.<locals>.wrapped_func°   s4   ø€ å˜&Ÿ*š* X¨tÑ4Ô4Ñ5Ô5Ð5Øˆt�TÐ$˜VÐ$Ð$Ð$r   r   )r~   r   s   ` r   Ú_accept_device_cpur€   ¯   s4   ø€ Ý
ˆ4�[„[ð%ð %ð %ð %ñ „[ð%ð Ðr   c                   óŒ   — e Zd ZdZh d£Zh d£Zd„ Zed„ ¦   «         Zdddœd	„Z	d
d
d
dœd„Z
d„ Zd„ Zd„ Zd
dœd„Zd
dœd„Zd„ Zd
S )Ú_NumPyAPIWrapperaR  Array API compat wrapper for any numpy version

    NumPy < 1.22 does not expose the numpy.array_api namespace. This
    wrapper makes it possible to write code that uses the standard
    Array API while working with any version of NumPy supported by
    scikit-learn.

    See the `get_namespace()` public function for more details.
    >   ÚeyeÚfullÚonesÚemptyÚzerosÚarangeÚlinspaceÚ	full_likeÚ	ones_likeÚ
empty_likeÚ
zeros_like>   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   r?   r@   c                 óš   — t          t          |¦  «        }|| j        v rt          |¦  «        S || j        v rt          j        |¦  «        S |S rV   )r\   r   Ú_CREATION_FUNCSr€   Ú_DTYPESr0   )rX   r]   Úattrs      r   r^   z_NumPyAPIWrapper.__getattr__ã   sS   € Ý•u˜dÑ#Ô#ˆð �4Ô'Ð'Ð'Ý% dÑ+Ô+Ð+ð �4”<ÐÐÝ”;˜tÑ$Ô$Ð$Øˆr   c                 ó   — t           j        S rV   )r   Úbool_)rX   s    r   r7   z_NumPyAPIWrapper.boolï   s
   € åŒ{Ðr   TÚunsafe©ÚcopyÚcastingc                ó2   — |                      |||¬¦  «        S )Nr•   )Úastype)rX   r   r0   r–   r—   s        r   r™   z_NumPyAPIWrapper.astypeó   s   € à�xŠx˜ D°'ˆxÑ:Ô:Ð:r   N)r0   r   r–   c                ó‚   — t          |¦  «         |du rt          j        |d|¬¦  «        S t          j        ||¬¦  «        S )NT)r–   r0   )r0   )rx   r   Úarrayrk   )rX   r   r0   r   r–   s        r   rk   z_NumPyAPIWrapper.asarray÷   sE   € Ý˜&Ñ!Ô!Ð!à�4ˆ<ˆ<Ý”;˜q t°5Ð9Ñ9Ô9Ð9å”= ¨%Ð0Ñ0Ô0Ð0r   c                 ó.   — t          j        |d¬¦  «        S )NT)Úreturn_inverse©r   Úunique©rX   r   s     r   Úunique_inversez_NumPyAPIWrapper.unique_inverseÿ   s   € ÝŒ|˜A¨dÐ3Ñ3Ô3Ð3r   c                 ó.   — t          j        |d¬¦  «        S )NT)Úreturn_countsrž   r    s     r   Úunique_countsz_NumPyAPIWrapper.unique_counts  s   € ÝŒ|˜A¨TÐ2Ñ2Ô2Ð2r   c                 ó*   — t          j        |¦  «        S rV   rž   r    s     r   Úunique_valuesz_NumPyAPIWrapper.unique_values  s   € ÝŒ|˜A‰ŒÐr   r_   c                ó.   — t          j        ||¬¦  «        S )Nr_   )r   Úconcatenate)rX   Úarraysr`   s      r   Úconcatz_NumPyAPIWrapper.concat  s   € ÝÔ  ¨dÐ3Ñ3Ô3Ð3r   )r–   c                óÊ   — t          |t          ¦  «        s"t          d|›dt          |¦  «        › �¦  «        ‚|du r|                     ¦   «         }t          j        ||¦  «        S )zæGives a new shape to an array without changing its data.

        The Array API specification requires shape to be a tuple.
        https://data-apis.org/array-api/latest/API_specification/generated/array_api.reshape.html
        zshape must be a tuple, got z	 of type T)r   r2   Ú	TypeErrorÚtyper–   r   Úreshape)rX   r   r   r–   s       r   r®   z_NumPyAPIWrapper.reshape  sk   € õ ˜%¥Ñ'Ô'ð 	ÝØM¨eÐMÐMÅÀUÁÄÐMÐMñô ð ð �4ˆ<ˆ<Ø—’‘”ˆAÝŒ}˜Q Ñ&Ô&Ð&r   c                 ó&   — t          ||| ¬¦  «        S rr   )r5   rs   s      r   r5   z_NumPyAPIWrapper.isdtype  s   € Ý�u˜d tÐ,Ñ,Ô,Ð,r   )r$   rt   ru   rv   r�   r�   r^   Úpropertyr7   r™   rk   r¡   r¤   r¦   rª   r®   r5   rc   r   r   r‚   r‚   ¸   s$  € € € € € ðð ðð ð €Oðð ð €Gð
ð 
ð 
ð ðð ñ „Xðð (,°Xð ;ð ;ð ;ð ;ð ;ð #'¨t¸$ð 1ð 1ð 1ð 1ð 1ð4ð 4ð 4ð3ð 3ð 3ðð ð ð &*ð 4ð 4ð 4ð 4ð 4ð )-ð 'ð 'ð 'ð 'ð 'ð-ð -ð -ð -ð -r   r‚   c                  ó¶   — t          ¦   «         d         }|s	t          dfS t          |¦  «         ddl} |j        | Ž d}}|j        dv rt          |¦  «        }||fS )aÿ  Get namespace of arrays.

    Introspect `arrays` arguments and return their common Array API
    compatible namespace object, if any. NumPy 1.22 and later can
    construct such containers using the `numpy.array_api` namespace
    for instance.

    See: https://numpy.org/neps/nep-0047-array-api-standard.html

    If `arrays` are regular numpy arrays, an instance of the
    `_NumPyAPIWrapper` compatibility wrapper is returned instead.

    Namespace support is not enabled by default. To enabled it
    call:

      sklearn.set_config(array_api_dispatch=True)

    or:

      with sklearn.config_context(array_api_dispatch=True):
          # your code here

    Otherwise an instance of the `_NumPyAPIWrapper`
    compatibility wrapper is always returned irrespective of
    the fact that arrays implement the `__array_namespace__`
    protocol or not.

    Parameters
    ----------
    *arrays : array objects
        Array objects.

    Returns
    -------
    namespace : module
        Namespace shared by array objects. If any of the `arrays` are not arrays,
        the namespace defaults to NumPy.

    is_array_api_compliant : bool
        True if the arrays are containers that implement the Array API spec.
        Always False when array_api_dispatch=False.
    r   Fr   NT>   úcupy.array_apir#   )r   Ú_NUMPY_API_WRAPPER_INSTANCEr   r
   Úget_namespacer$   rT   )r©   r   r
   Ú	namespaceÚis_array_api_compliants        r   r´   r´   !  sƒ   € õV $™œÐ&:Ô;ÐØð 2Ý*¨EÐ1Ð1åÐ0Ñ1Ô1Ð1ð ÐÐÐà(FÐ(8Ô(FÈÐ(OÐQUÐ%€IàÔÐBÐBÐBÝ$ YÑ/Ô/ˆ	àÐ,Ð,Ð,r   c                 óî   — t          | ¦  «        \  }}t          |¦  «        r9|                     t          j        t          j        | ¦  «        ¦  «        ¦  «        S dd|                     |  ¦  «        z   z  S )Ng      ð?)r´   r'   rk   ÚspecialÚexpitr   Úexp)rf   r&   Ú_s      r   Ú_expitr¼   `  se   € Ý˜!ÑÔ�E€BˆÝ˜2ÑÔð ;Ø�zŠz�'œ-­¬°aÑ(8Ô(8Ñ9Ô9Ñ:Ô:Ð:à�#˜Ÿš ˜r™
œ
Ñ"Ñ#Ð#r   r%   c                ó  — |€t          | ¦  «        \  }}t          |¦  «        rH|du rt          j        | ||¬¦  «        } nt          j        | ||¬¦  «        } |                     | ¦  «        S |                     | ||¬¦  «        S )aß  Helper to support the order kwarg only for NumPy-backed arrays

    Memory layout parameter `order` is not exposed in the Array API standard,
    however some input validation code in scikit-learn needs to work both
    for classes and functions that will leverage Array API only operations
    and for code that inherently relies on NumPy backed data containers with
    specific memory layout constraints (e.g. our own Cython code). The
    purpose of this helper is to make it possible to share code for data
    container validation without memory copies for both downstream use cases:
    the `order` parameter is only enforced if the input array implementation
    is NumPy based, otherwise `order` is just silently ignored.
    NT)Úorderr0   )r0   r–   )r´   r'   r   r›   rk   )r›   r0   r¾   r–   r&   r»   s         r   Ú_asarray_with_orderr¿   h  s�   € ð 
€zÝ˜eÑ$Ô$‰ˆˆAÝ˜2ÑÔð 9à�4ˆ<ˆ<Ý”K ¨U¸%Ð@Ñ@Ô@ˆEˆEå”M %¨u¸EÐBÑBÔBˆEð �zŠz˜%Ñ Ô Ð à�zŠz˜% u°4ˆzÑ8Ô8Ð8r   c                 óú   — |j         }|dv r&|                      ¦   «                              ¦   «         S |dk    r| j                             ¦   «         S |dv r|                      ¦   «         S t          j        | ¦  «        S )z*Convert X into a NumPy ndarray on the CPU.>   úarray_api_compat.torchÚtorchr²   >   úarray_api_compat.cupyÚcupy)r$   r   r   Ú_arrayÚgetrk   )r›   r&   Úxp_names      r   Ú_convert_to_numpyrÈ   …  sy   € àŒk€GàÐ5Ð5Ð5Ø�yŠy‰{Œ{× Ò Ñ"Ô"Ð"Ø	Ð$Ò	$Ð	$ØŒ|×ÒÑ!Ô!Ð!Ø	Ð5Ð	5Ð	5Ø�yŠy‰{Œ{ÐåŒ=˜ÑÔÐr   c                 ó  — ddl m}  || ¦  «        }t          | ¦  «                             ¦   «         D ]K\  }}t	          |d¦  «        st          |t          j        ¦  «        r ||¦  «        }t          |||¦  «         ŒL|S )aê  Create new estimator which converting all attributes that are arrays.

    The converter is called on all NumPy arrays and arrays that support the
    `DLPack interface <https://dmlc.github.io/dlpack/latest/>`__.

    Parameters
    ----------
    estimator : Estimator
        Estimator to convert

    converter : callable
        Callable that takes an array attribute and returns the converted array.

    Returns
    -------
    new_estimator : Estimator
        Convert estimator
    r   )ÚcloneÚ
__dlpack__)	Úsklearn.baserÊ   ÚvarsÚitemsrO   r   r   r   Úsetattr)Ú	estimatorÚ	converterrÊ   Únew_estimatorÚkeyÚ	attributes         r   Ú _estimator_with_converted_arraysrÕ   “  s™   € ð& #Ð"Ð"Ð"Ð"Ð"à�E˜)Ñ$Ô$€MÝ˜y™/œ/×/Ò/Ñ1Ô1ð /ð /‰ˆˆYÝ�9˜lÑ+Ô+ð 	-­z¸)ÅUÄ]Ñ/SÔ/Sð 	-Ø!˜	 )Ñ,Ô,ˆIÝ�˜s IÑ.Ô.Ð.Ð.ØÐr   )NNN)rv   r   Ú	functoolsr   r   Úscipy.specialr¸   Ú_configr   Úfixesr   r   r   r    r'   r5   r,   rT   rx   r€   r‚   r³   r´   r¼   r¿   rÈ   rÕ   rc   r   r   ú<module>rÚ      s¶  ðØ !Ð !Ø €€€Ø Ð Ð Ð Ð Ð à €€€Ø Ð Ð Ð Ð Ð à  Ð  Ð  Ð  Ð  Ð  Ø  Ð  Ð  Ð  Ð  Ð  ðð ð ð0ð ð ð$ð ð ð Qð Qð Qð
	3ð 	3ð 	3ð ð  ð  ðF-8ð -8ð -8ð -8ð -8ñ -8ô -8ð -8ð`Fð Fð Fð
ð ð ðc-ð c-ð c-ð c-ð c-ñ c-ô c-ð c-ðL /Ð.Ñ0Ô0Ð ð<-ð <-ð <-ð~$ð $ð $ð9Èð 9ð 9ð 9ð 9ð 9ð: ð  ð  ðð ð ð ð r   