
    2VhY                     j    d dl Z d dlZd dlZd dlZd dlZd Zd Zd ZddZ	d Z
d Zd Zd	 Zd
 Zd Zy)    Nc                     d| _         | S )z5Decorates a method to detect overrides in subclasses.T)_is_defaultmethods    L/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/utils/python_utils.pydefaultr      s    FM    c                     t        | dd      S )z:Check if a method is decorated with the `default` wrapper.r   F)getattrr   s    r   
is_defaultr      s    6=%00r	   c                    t         j                  dk(  rUt        j                  | j                        j                  dd      }t        j                  |d      j                  d      }nDt        j                  | j                        }t        j                  |d      j                  d      }| j                  }| j                  rt        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              3   4   K   | ]  }|j                     y wN)cell_contents).0cs     r   	<genexpr>zfunc_dump.<locals>.<genexpr>$   s     BABs   N)osnamemarshaldumps__code__replacecodecsencodedecode__defaults____closure__tuple)funcraw_codecodedefaultsclosures        r   	func_dumpr*      s     
ww$==/77tD}}Xx077@==/}}Xx077@  HB1A1ABB7""r	   c                    t        | t        t        f      r!| \  } }}t        |t              rt        |      }d |t        fd|D              }	 t        j                  | j                  d      d      }t        j                  |      } |
t               }t        j                  | || j                  ||      S # t        t        j                  f$ r | j                  d      }Y qw xY w)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                 ^      f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                  
      y r    )values   r   dummy_fnz9func_load.<locals>.ensure_value_to_cell.<locals>.dummy_fnE   s    r	   r   )r#   
isinstancetype)r/   r0   
cell_values   `  r   ensure_value_to_cellz'func_load.<locals>.ensure_value_to_cell;   s4    	 ))!,
%j!12r	   c              3   .   K   | ]  } |        y wr   r.   )r   _r4   s     r   r   zfunc_load.<locals>.<genexpr>N   s     AA,Q/As   r   r   raw_unicode_escape)r   argdefsr)   )r1   r$   listr   r!   r    UnicodeEncodeErrorbinasciiErrorr   loadsglobalspython_typesFunctionTypeco_name)r'   r(   r)   globsr&   r4   s        @r   	func_loadrC   *   s     $&"&hh%XH$ AAA5==W!5x@ =="D}	$$e$,,'  / 5;;345s   %B= =*C*)C*c                 ,    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.
    )r1   r9   )xs    r   to_listrF   [   s     !T3Jr	   c                     g g }}t        ||      D ]6  \  }}t        |      | k  s|j                  |       |j                  |       8 ||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`.
    )ziplenappend)maxlenseqlabelnew_seq	new_labelrE   ys          r   remove_long_seqrQ   l   sX     RYGC  1q6F?NN1Q  Ir	   c                 `    t        |      dkD  r| j                  |      r| t        |      d S | S )z5Backport of `removeprefix` from PEP-616 (Python 3.9+)r   N)rI   
startswith)rE   prefixs     r   removeprefixrU      s0     6{Q1<</Vr	   c                 b    t        |      dkD  r | j                  |      r| dt        |        S | S )z5Backport of `removesuffix` from PEP-616 (Python 3.9+)r   N)rI   endswith)rE   suffixs     r   removesuffixrY      s2     6{Q1::f-CK<  r	   c                 b    t        |       D ]!  \  }}t        |      t        |      k(  s| |=  y y)z!Remove a value from a list by id.N)	enumerateid)lstr/   ivs       r   remove_by_idr`      s3    # 1a5BuIAr	   c                     | xs i } i }t        | j                               D ]A  \  }}t        |t              r|j	                  t        |             1	 t        |      }|||<   C |S #  Y xY w)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itemsr1   dictupdatepythonify_logsfloat)logsresultkeyr/   s       r   rf   rf      su     :2DFTZZ\*  
UeT"MM./0e  F3K  Ms   A((A,)NNN)r;   r   r   r   typesr?   r   r   r*   rC   rF   rQ   rU   rY   r`   rf   r.   r	   r   <module>rl      sG       	 1
#..b"&r	   