
    6bi<L                     B   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r
SSKrSSKJs  Jr  SSKJr  SSKJr  SSKJr  S rSS jrSS jr\" S	5       " S
 S5      5       rS rSS jrS rS rS rS r SS jr S r!S r"S r# " S S\
RH                  5      r%g)z&Python utilities required by TF-Keras.    N)io_utils)
tf_inspect)keras_exportc                    [         R                  S:X  aW  [        R                  " U R                  5      R                  SS5      n[        R                  " US5      R                  S5      nOF[        R                  " U R                  5      n[        R                  " US5      R                  S5      nU R                  nU R                  (       a  [        S U R                   5       5      nOSnX#U4$ )zSerializes a user defined function.

Args:
    func: the function to serialize.

Returns:
    A tuple `(code, defaults, closure)`.
nt   \   /base64asciic              3   8   #    U  H  oR                   v   M     g 7fN)cell_contents).0cs     Z/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/utils/generic_utils.py	<genexpr>func_dump.<locals>.<genexpr>6   s     B1AA1As   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""    c                   ^ [        U [        [        45      (       a%  U u  pn[        U[        5      (       a  [        U5      nS mUb  [        U4S jU 5       5      n [        R                  " U R                  S5      S5      n[        R                  " U5      n Uc
  [        5       n[        R                  " XU R                  XS9$ ! [        [        R                  4 a    U R                  S5      n Npf = f)zDeserializes 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                 j   ^  U 4S jnUR                   S   n[        T [        U5      5      (       d  U$ T $ )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                  
   > T   g r    )values   r   dummy_fn9func_load.<locals>.ensure_value_to_cell.<locals>.dummy_fnW   s    r&   r   )r   
isinstancetype)r+   r,   
cell_values   `  r   ensure_value_to_cell'func_load.<locals>.ensure_value_to_cellM   s7    	 ))!,
%j!122r&   c              3   4   >#    U  H  nT" U5      v   M     g 7fr   r*   )r   _r1   s     r   r   func_load.<locals>.<genexpr>`   s     AA,Q//s   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!   r1   s        @r   	func_loadrB   <   s     $&&"&h%%XH$ AAA5==W!5x@ =="D}	$$$,,  / 5;;345s   &C +C54C5c                     [         R                  " U 5      nU(       a  UR                  b  gXR                  ;   =(       d    XR                  ;   $ )ad  Checks if a callable accepts a given keyword argument.

Args:
    fn: Callable to inspect.
    name: Check if `fn` can be called with `name` as a keyword argument.
    accept_all: What to return if there is no parameter called `name` but
      the function accepts a `**kwargs` argument.

Returns:
    bool, whether `fn` accepts a `name` keyword argument.
T)r   getfullargspecvarkwargs
kwonlyargs)fnr   
accept_allarg_specs       r   has_argrK   m   s>     ((,Hhnn0== ?D,?,?$??r&   zkeras.utils.Progbarc                   R    \ rS rSrSr     SS jrSS jrSS jrS rS r	S	 r
S
rg)Progbar   a3  Displays a progress bar.

Args:
    target: Total number of steps expected, None if unknown.
    width: Progress bar width on screen.
    verbose: Verbosity mode, 0 (silent), 1 (verbose), 2 (semi-verbose)
    stateful_metrics: Iterable of string names of metrics that should *not*
      be averaged over time. Metrics in this list will be displayed as-is.
      All others will be averaged by the progbar before display.
    interval: Minimum visual progress update interval (in seconds).
    unit_name: Display name for step counts (usually "step" or "sample").
Nc                 j   Xl         X l        X0l        X@l        X`l        U(       a  [        U5      U l        O[        5       U l        [        [        R                  S5      =(       a    [        R                  R                  5       =(       dG    S[        R                  ;   =(       d-    S[        R                  ;   =(       d    S[        R                  ;   U l        SU l        SU l        0 U l        / U l        [&        R&                  " 5       U l        SU l        U R(                  U l        S U l        S U l        g )Nisatty	ipykernelposixPYCHARM_HOSTEDr   )targetwidthverboseinterval	unit_namesetstateful_metricshasattrsysstdoutrP   modulesr   environ_dynamic_display_total_width_seen_so_far_values_values_ordertime_start_last_update_time_at_epoch_start_time_at_epoch_end_time_after_first_step)selfrT   rU   rV   rW   rZ   rX   s          r   __init__Progbar.__init__   s     
 "$'(8$9D!$'ED! SZZ*Bszz/@/@/B .ckk).#++%.  2::-	 	  iik$(KK!"&&*#r&   c           	         Uc  U R                   c  SnOXR                   :  nU=(       d    / nU H  u  pEX@R                  ;  a  U R                  R                  U5        X@R                  ;  at  [	        XR
                  -
  S5      nX@R                  ;  a  XV-  U/U R                  U'   Mz  U R                  U   S==   XV-  -  ss'   U R                  U   S==   U-  ss'   M  US/U R                  U'   M     Xl        Sn[        R                  " 5       nSXR                  -
  S S3n	XR                   :X  a  Xl	        U R                  S:X  Ga  XR                  -
  U R                  :  a  U(       d  gU R                  n
U R                  (       a  US	U
-  -  nUS
-  nOUS-  nU R                   b  [        [         R"                  " U R                   5      5      S-   nS[%        U5      -   S-   XR                   4-  n['        U5      U R                   -  n[        U R(                  U-  5      nUS:  a%  USUS-
  -  -  nXR                   :  a  US-  nOUS-  nUSU R(                  U-
  -  -  nUS-  nOSU-  n[+        U5      U l        X|-  nU R-                  X5      nU R                   b  U(       a  XR/                  XR0                  5      -  n	OJXR                   U-
  -  nUS:  a  SUS-  US-  S-  US-  4-  nOUS:  a  SUS-  US-  4-  nOSU-  nSU 3n	U R                   H  nU	SU S3-  n	[3        U R                  U   [4        5      (       ah  [         R6                  " U R                  U   S   [	        SU R                  U   S   5      -  5      n[9        U5      S:  a  U	SUS 3-  n	M  U	SUS 3-  n	M  U	SU R                  U    3-  n	M     U =R                  [+        U	5      -  sl        XR                  :  a  U	SXR                  -
  -  -  n	U(       a  U	S-  n	Xy-  n[:        R<                  " USS9  SnGOU R                  S:X  Gaq  U(       Gai  [        [         R"                  " U R                   5      5      S-   nS[%        U5      -   S -   XR                   4-  nUU	-   n	U R                   Hi  nU	SU S3-  n	[         R6                  " U R                  U   S   [	        SU R                  U   S   5      -  5      nUS:  a  U	SUS 3-  n	M`  U	SUS 3-  n	Mk     U R                  (       at  U R                  U R>                  -
  nUU R                   -  nXl        SU l	        U	S!U R/                  US"5      -   -  n	U	S!U R/                  UU R0                  5      -   -  n	U	S-  n	Xy-  n[:        R<                  " USS9  SnXl        g)#a  Updates the progress bar.

Args:
    current: Index of current step.
    values: List of tuples: `(name, value_for_last_step)`. If `name` is
      in `stateful_metrics`, `value_for_last_step` will be displayed
      as-is. Else, an average of the metric over time will be
      displayed.
    finalize: Whether this is the last update for the progress bar. If
      `None`, uses `current >= self.target`. Defaults to `None`.
NF   r    z - .0fs
%zd/%d [=>.]z%7d/Unknowni  z%d:%02d:%02d<   z%d:%02dz%dsz - ETA: :MbP? z.4fz.4e)
line_break   zd/%dz -epoch) rT   rd   appendrZ   maxrb   rc   re   rf   ri   rV   rg   rW   ra   r`   intnplog10strfloatrU   len_estimate_step_duration_format_timerX   r.   r8   meanabsr   	print_msgrh   )rk   currentvaluesfinalizekv
value_basemessagenowinfoprev_total_width	numdigitsbarprog
prog_widthtime_per_uniteta
eta_formatavgcounttime_per_epochavg_time_per_steps                         r   updateProgbar.update   s    {{" "kk12DA***""))!,--- !+<+<!<a@
LL('(~z&BDLLOLLOA&!.8&LLOA&*4&
 $%a&Q' ( $iikS;;&s+1-kk!&)#<<1&&&6x#00$$4"22244{{& 56:	S^+h67KK:PPW~3 d!23
>3*q.11C,s
s
sdjj:566s
#g- #CDNG 88FM{{"h))-HH#{{W'<=:!/tt*b3 "J
 2X!*cRir-B!BJ!&J!*.''#aS
"dll1ot44''Q*SDLLOA4F-GGC 3x$!C9-!C9-aQ011D ( T*"3"33/2C2CCDDOGw59G\\Q 56:	s9~-67KK:PPt|++Ac!AJ&D''Q*SDLLOA4F-GGC Tz!C9-!C9- , **//$2K2KK # )7(D%03-.2D+D4#4#4^W#MMMDD4#4#4)4>>$  D DLD""7u=r&   c                 B    U R                  U R                  U-   U5        g r   )r   rb   )rk   nr   s      r   addProgbar.addJ  s    D%%)62r&   c                     SnUS:  d  US:X  a  USUS SU 3-  nU$ US:  a  USUS-  S S	U 3-  nU$ USUS
-  S SU 3-  nU$ )aP  format a given duration to display to the user.

Given the duration, this function formats it in either milliseconds
or seconds and displays the unit (i.e. ms/step or s/epoch)
Args:
  time_per_unit: the duration to display
  unit_name: the name of the unit to display
Returns:
  a string with the correctly formatted duration and units
rp   ro   r   r~   rq   zs/r}   g     @@zms/g    .Azus/r*   )rk   r   rX   	formatteds       r   r   Progbar._format_timeM  s     	A!!31]3/r)==I
 	 d"1]V3C8I;GGI  1]Y6s;3ykJJIr&   c                     U(       aG  U R                   b  US:  a  X R                   -
  US-
  -  nOX R                  -
  U-  nUS:X  a  X l         U$ g)a3  Estimate the duration of a single step.

Given the step number `current` and the corresponding time `now` this
function returns an estimate for how long a single step takes. If this
is called before one step has been completed (i.e. `current == 0`) then
zero is given as an estimate. The duration estimate ignores the duration
of the (assumed to be non-representative) first step for estimates when
more steps are available (i.e. `current>1`).

Args:
  current: Index of current step.
  now: The current time.

Returns: Estimate of the duration of a single step.
ro   r   )rj   rf   )rk   r   r   r   s       r   r   Progbar._estimate_step_durationa  s^       **67Q;!$'B'B!BaK! "%{{!2g =!|.1+  r&   c                 D    U R                   R                  U5      U l         g r   )rZ   union)rk   rZ   s     r   _update_stateful_metrics Progbar._update_stateful_metrics  s     $ 5 5 ; ;<L Mr&   )r`   rg   rb   rf   rj   ri   rh   ra   rc   rd   rW   rZ   rT   rX   rV   rU   )   ro   g?NstepNNr   )__name__
__module____qualname____firstlineno____doc__rl   r   r   r   r   r   __static_attributes__r*   r&   r   rM   rM      s;      #+JU n3("HNr&   rM   c           	          [        [        R                  " U [        U5      -  5      5      n[	        SU5       Vs/ s H  nX1-  [        XS-   U-  5      4PM     sn$ s  snf )zReturns a list of batch indices (tuples of indices).

Args:
    size: Integer, total size of the data to slice into batches.
    batch_size: Integer, batch size.

Returns:
    A list of tuples of array indices.
r   ro   )r   r   ceilr   rangemin)size
batch_sizenum_batchesis       r   make_batchesr     sd     bggdU:%6678K q+&&A 
TEZ#789&  s   Ac                 *   U c  S/$ [        U[        5      (       a  Ub  [        SU SU 35      e[        U [        5      (       ax  [        US5      (       a:  [        US5      (       a  UR	                  5       nU  Vs/ s H  o3c  SOX1   PM     sn$ U  Vs/ s H  nUc  SO[        US5      (       d  SOX1U PM!     sn$ [        US5      (       a%  [        US5      (       a  UR	                  5       nX   $ [        US5      (       a  XU $ S/$ s  snf s  snf )aU  Slice an array or list of arrays.

This takes an array-like, or a list of
array-likes, and outputs:
    - arrays[start:stop] if `arrays` is an array-like
    - [x[start:stop] for x in arrays] if `arrays` is a list

Can also work on list/array of indices: `slice_arrays(x, indices)`

Args:
    arrays: Single array or list of arrays.
    start: can be an integer index (start index) or a list/array of indices
    stop: integer (stop index); should be None if `start` was a list.

Returns:
    A slice of the array(s).

Raises:
    ValueError: If the value of start is a list and stop is not None.
NzQThe stop argument has to be None if the value of start is a list. Received start=z, stop=__len__shape__getitem__)r.   r8   
ValueErrorr[   tolist)arraysstartstopxs       r   slice_arraysr     s<   * ~v%4#3)).wtf>
 	
 
FD	!	!5)$$ug&&=CDVID183VDD 
 	 y  1m,, 	
 
 	
 5)$$ug&&= 5-((%%v! E
s   ;D&Dc                 6    [        U [        5      (       a  U $ U /$ )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.   r8   )r   s    r   to_listr     s     !T3Jr&   c                     [         R                  " SSU 5      n[         R                  " SSU5      R                  5       nUS   S:w  a  U$ SU-   $ )Nz(.)([A-Z][a-z]+)z\1_\2z([a-z])([A-Z])r   r4   private)resublower)r   intermediateinsecures      r   to_snake_caser     sO    66,h=Lvv&,?EEGH {cxr&   c                 ^    [         R                  R                  U 5      nU H  nUc  M    g   g)NFT)tfnestflatten)	structureiterableelements      r   is_all_noner     s,    wwy)H  r&   c                     [        UR                  5       5      R                  U5      nU(       a  [        SU  S[	        U5       SU 35      eg )NzUnknown entries in z dictionary: z . Only expected following keys: )rY   keys
differencer   r8   )r   
input_dictexpected_valuesunknowns       r   check_for_unexpected_keysr     sU    *//#$//@G!$}T']O D--<,=?
 	
 r&   c                 6    U  H  nX1;  d  M
  [        X#5      e   g)zAChecks that all keyword arguments are in the set of allowed keys.N)	TypeError)kwargsallowed_kwargserror_messagekwargs       r   validate_kwargsr     s     &M11 r&   c                     SU l         U $ )z5Decorates a method to detect overrides in subclasses.T)_is_defaultmethods    r   defaultr     s    FMr&   c                     [        U SS5      $ )z:Check if a method is decorated with the `default` wrapper.r   F)getattrr   s    r   
is_defaultr   
  s    6=%00r&   c                 v    U H3  n[        U5       H!  n[        X45      nU" U5      (       d  M  XPU'   M#     M5     g r   )dirr   )target_dictr^   
obj_filtermoduler   objs         r   !populate_dict_with_module_objectsr     s5    KD&'C#$'D!   r&   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )
LazyLoaderi  zFLazily import a module, mainly to avoid pulling in large dependencies.c                 <   > Xl         X l        [        TU ]  U5        g r   )_local_name_parent_module_globalssuperrl   )rk   
local_nameparent_module_globalsr   	__class__s       r   rl   LazyLoader.__init__  s    %&;#r&   c                     [         R                  " U R                  5      nXR                  U R                  '   U R
                  R                  UR
                  5        U$ )z8Load the module and insert it into the parent's globals.)	importlibimport_moduler   r  r  __dict__r   )rk   r   s     r   _loadLazyLoader._load  sI     ((78>##D$4$45 	V__-r&   c                 8    U R                  5       n[        X!5      $ r   )r  r   )rk   itemr   s      r   __getattr__LazyLoader.__getattr__*  s    v$$r&   )r  r  )
r   r   r   r   r   rl   r  r  r   __classcell__)r  s   @r   r   r     s    P
	% %r&   r   )NNN)Fr   )z Keyword argument not understood:)&r   r:   r   r
  r   r   r   r\   re   typesr>   numpyr   tensorflow.compat.v2compatv2r   tf_keras.src.utilsr   r    tensorflow.python.util.tf_exportr   r%   rB   rK   rM   r   r   r   r   r   r   r   r   r   r   
ModuleTyper   r*   r&   r   <module>r     s    -     	 	 
    ! ! ' ) :#..b@$ #$FN FN %FNR"1h" 
 +M21
(%(( %r&   