o
    2h                     @   s   d dl Z d dlZd dlZd dlZd dlZdd Zdd Zdd Zdd	 Z	dd
dZ
dd Zdd Zdd Zdd Zdd Zdd ZdS )    Nc                 C   s   t | tst| dkrdS d}tt| d D ]}| |d  | |  dkr)d} nqd}tt| d D ]}| |d  | |  dkrFd} nq4|pJ|S )N   TF)
isinstanceintlenrange)axispositive_order_flaginegative_order_flag r   W/var/www/html/chatgem/venv/lib/python3.10/site-packages/keras/src/utils/python_utils.pyis_continuous_axis   s   r   c                 C   s
   d| _ | S )z5Decorates a method to detect overrides in subclasses.T)_is_defaultmethodr   r   r   default   s   r   c                 C   s   t | ddS )z:Check if a method is decorated with the `default` wrapper.r   F)getattrr   r   r   r   
is_default    s   r   c                 C   s   t jdkrt| jdd}t|dd}nt| j}t|dd}| j	}| j
r9tdd | j
D }nd}|||fS )	zSerializes a user-defined function.

    Args:
        func: the function to serialize.

    Returns:
        A tuple `(code, defaults, closure)`.
    nt   \   /base64asciic                 s   s    | ]}|j V  qd S N)cell_contents).0cr   r   r   	<genexpr>6   s    zfunc_dump.<locals>.<genexpr>N)osnamemarshaldumps__code__replacecodecsencodedecode__defaults____closure__tuple)funcraw_codecodedefaultsclosurer   r   r   	func_dump%   s   
	
r/   c              	      s   t | ttfr| \} }}t |trt|}dd  |dur(t fdd|D }zt| dd}W n ttjfyD   | d}Y nw t	
|} |du rQt }tj| || j||d	S )
a	  Deserializes a user defined function.

    Args:
        code: bytecode of the function.
        defaults: defaults of the function.
        closure: closure of the function.
        globs: dictionary of global objects.

    Returns:
        A function object.
    c                    s,    fdd}|j d }t t|s|S  S )zEnsures that a value is converted to a python cell object.

        Args:
            value: Any value that needs to be casted to the cell type

        Returns:
            A value wrapped as a cell object (see function "func_load")
        c                      s     d S r   r   r   valuer   r   dummy_fnW   s   z9func_load.<locals>.ensure_value_to_cell.<locals>.dummy_fnr   )r(   r   type)r1   r2   
cell_valuer   r0   r   ensure_value_to_cellM   s
   

z'func_load.<locals>.ensure_value_to_cellNc                 3   s    | ]} |V  qd S r   r   )r   _r5   r   r   r   `   s    zfunc_load.<locals>.<genexpr>r   r   raw_unicode_escape)r   argdefsr.   )r   r)   listr$   r&   r%   UnicodeEncodeErrorbinasciiErrorr    loadsglobalspython_typesFunctionTypeco_name)r,   r-   r.   globsr+   r   r7   r   	func_load<   s$   


rD   c                 C   s   t | tr| S | gS )zNormalizes a list/tensor into a list.

    If a tensor is passed, we return
    a list of size 1 containing the tensor.

    Args:
        x: target object to be normalized.

    Returns:
        A list.
    )r   r:   )xr   r   r   to_listm   s   
rF   c                 C   sF   g g }}t ||D ]\}}t|| k r|| || q
||fS )aC  Removes sequences that exceed the maximum length.

    Args:
        maxlen: Int, maximum length of the output sequences.
        seq: List of lists, where each sublist is a sequence.
        label: List where each element is an integer.

    Returns:
        new_seq, new_label: shortened lists for `seq` and `label`.
    )zipr   append)maxlenseqlabelnew_seq	new_labelrE   yr   r   r   remove_long_seq~   s   


rO   c                 C   s*   t |dkr| |r| t |d S | S )z5Backport of `removeprefix` from PEP-616 (Python 3.9+)r   N)r   
startswith)rE   prefixr   r   r   removeprefix   s   rR   c                 C   s,   t |dkr| |r| dt |  S | S )z5Backport of `removesuffix` from PEP-616 (Python 3.9+)r   N)r   endswith)rE   suffixr   r   r   removesuffix   s   rU   c                 C   s2   t | D ]\}}t|t|kr| |=  dS qdS )z!Remove a value from a list by id.N)	enumerateid)lstr1   r	   vr   r   r   remove_by_id   s   rZ   c                 C   s^   | pi } i }t |  D ] \}}t|tr|t| qzt|}W n   Y |||< q|S )aI  Flatten and convert log values to Python-native types.

    This function attempts to convert dict value by `float(value)` and skips
    the conversion if it fails.

    Args:
        logs: A dict containing log values.

    Returns:
        A flattened dict with values converted to Python-native types if
        possible.
    )sorteditemsr   dictupdatepythonify_logsfloat)logsresultkeyr1   r   r   r   r_      s   

r_   )NNN)r<   r$   r    r   typesr@   r   r   r   r/   rD   rF   rO   rR   rU   rZ   r_   r   r   r   r   <module>   s     
1		