a
    h                     @   sF   d dl Zd dlmZ dd ZddddZdd	d
ZddddZdS )    N)get_namespacec              	   C   sh   t | tjs| S zd| jjv r$| W S W n ttfy<   Y n0 t| }tj| jd|id}| j|dS )zAttach unique values of y to y and return the result.

    The result is a view of y, and the metadata (unique) is not attached to y.
    unique)metadata)dtype)	
isinstancenpZndarrayr   r   AttributeError	TypeErrorr   view)yr   Zunique_dtype r   Q/var/www/html/assistant/venv/lib/python3.9/site-packages/sklearn/utils/_unique.py_attach_unique	   s    

r   F)return_tuplec                 G   s.   t dd |D }t|dkr*| s*|d S |S )a  Attach unique values of ys to ys and return the results.

    The result is a view of y, and the metadata (unique) is not attached to y.

    IMPORTANT: The output of this function should NEVER be returned in functions.
    This is to avoid this pattern:

    .. code:: python

        y = np.array([1, 2, 3])
        y = attach_unique(y)
        y[1] = -1
        # now np.unique(y) will be different from cached_unique(y)

    Parameters
    ----------
    *ys : sequence of array-like
        Input data arrays.

    return_tuple : bool, default=False
        If True, always return a tuple even if there is only one array.

    Returns
    -------
    ys : tuple of array-like or array-like
        Input data with unique values attached.
    c                 s   s   | ]}t |V  qd S )N)r   .0r   r   r   r   	<genexpr>8       z attach_unique.<locals>.<genexpr>   r   tuplelen)r   ysresr   r   r   attach_unique   s    r   c                 C   sX   z*| j jdur(d| j jv r(| j jd W S W n ty<   Y n0 t| |d\}}|| S )zReturn the unique values of y.

    Use the cached values from dtype.metadata if present.

    This function does NOT cache the values in y, i.e. it doesn't change y.

    Call `attach_unique` to attach the unique values to y.
    Nr   xp)r   r   r   r   Zunique_values)r   r   _r   r   r   _cached_unique>   s    	r   r   c                    s.   t  fdd|D }t|dkr*|d S |S )a  Return the unique values of ys.

    Use the cached values from dtype.metadata if present.

    This function does NOT cache the values in y, i.e. it doesn't change y.

    Call `attach_unique` to attach the unique values to y.

    Parameters
    ----------
    *ys : sequence of array-like
        Input data arrays.

    xp : module, default=None
        Precomputed array namespace module. When passed, typically from a caller
        that has already performed inspection of its own inputs, skips array
        namespace inspection.

    Returns
    -------
    res : tuple of array-like or array-like
        Unique values of ys.
    c                 3   s   | ]}t | d V  qdS )r   N)r   r   r   r   r   r   i   r   z cached_unique.<locals>.<genexpr>r   r   r   )r   r   r   r   r   r   cached_uniqueQ   s    r   )N)numpyr   Zsklearn.utils._array_apir   r   r   r   r   r   r   r   r   <module>   s
   "
