
    2Vhm(                     r    d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	  ed       G d d             Z
y)    N)backend)keras_export)io_utilszkeras.utils.Progbarc                   >    e Zd ZdZ	 	 	 	 	 ddZd	dZd
dZd Zd Zy)Progbara_  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                 ,   || _         || _        || _        || _        || _        |rt        |      | _        nt               | _        t        t        j                  d      xr t        j                  j                         xs: dt        j                  v xs& dt        j                  v xs dt        j                  v | _        d| _        i | _        g | _        t%        j$                         | _        d| _        | j&                  | _        d | _        d| _        y )Nisatty	ipykernelposixPYCHARM_HOSTEDr   )targetwidthverboseinterval	unit_namesetstateful_metricshasattrsysstdoutr	   modulesosenviron_dynamic_display_seen_so_far_values_values_ordertime_start_last_update_time_at_epoch_start_time_after_first_step_prev_total_width)selfr   r   r   r   r   r   s          G/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/utils/progbar.py__init__zProgbar.__init__   s     
 "$'(8$9D!$'ED! SZZ*Bszz/@/@/B .ckk).#++%.  2::-	 	  iik$(KK!&*#!"    c                 
   || j                   d}n|| j                   k\  }|xs g }|D ]  \  }}|| j                  vr| j                  j                  |       || j                  vrtt	        || j
                  z
  d      }|| j                  vr||z  |g| j                  |<   y| j                  |   dxx   ||z  z  cc<   | j                  |   dxx   |z  cc<   |dg| j                  |<    || _        d}d}t        j                         }	| j                  ||	      }
| j                  dk(  r|	| j                  z
  | j                  k  r|sy| j                  r|d| j                  z  z  }|dz  }n|dz  }| j                   t        t        j                   | j                               dz   }d	t#        |      z   d
z   || j                   fz  }d| d}|dz  }t%        |      | j                   z  }t        | j&                  |z        }|dkD  r|dd|z  z   dz   z  }|dz  }|dd| j&                  |z
  z  z   dz   z  }|dz  }nd|z  }||z  }| j                   M|sK|
| j                   |z
  z  }|dkD  rd|dz  |dz  dz  |dz  fz  }n|dkD  rd|dz  |dz  fz  }nd|z  }d| d}nd|	| j(                  z
  dd}|dz  }|| j+                  |
| j,                        z  }| j                  D ]  }|d| dz  }t/        | j                  |   t0              rt3        j4                  t2        j6                  j9                  | j                  |   d   t	        d| j                  |   d         z              }t%        |      }t;        |      dkD  r
|d|d z  }|d|d!z  }|d| j                  |    z  } ||z  }t=        |      t=        |      z   |z
  }| j                  |kD  r|d| j                  |z
  z  z  }|r|dz  }t?        j@                  |d"       || _        d}|	| _
        y| j                  d#k(  r:|r7t        t        j                   | j                               dz   }d	t#        |      z   d
z   || j                   fz  }| d|	| j(                  z
  dd$}|d%| j+                  |
| j,                        z   z  }| j                  D ]  }|d| dz  }t3        j4                  t2        j6                  j9                  | j                  |   d   t	        d| j                  |   d         z              }|dkD  r
|d|d z  }z|d|d!z  } |dz  }||z  }t?        j@                  |d"       d}|	| _
        y)&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`, defaults to `current >= self.target`.
        NF   r    
%zd/%dz[1mz[0m    z[32mu   ━z[0m	   z[37mz%7d/Unknowni  z%d:%02d:%02d<   z%d:%02dz%dsz [1m.0fzs[0mz - :MbP? z.4fz.4e)
line_break   sz -)!r   r   appendr   maxr   r   r   _estimate_step_durationr   r    r   r   r#   intmathlog10strfloatr   r   _format_timer   
isinstancelistr   convert_to_numpynumpymeanabslenr   	print_msg)r$   currentvaluesfinalizekv
value_basemessagespecial_char_lennowtime_per_unit	numdigitsbarprog
prog_widtheta
eta_formatinfoavgtotal_widthcounts                        r%   updatezProgbar.update>   s    {{" "dkk12 	)DAq***""))!,--- !4+<+<!<a@
DLL('(:~z&BDLLOLLOA&!j.8&LLOA&*4&
 $%a&Q'	)( $iik44WcB<<1T&&&6x$$4$"8"88844{{&

4;; 781<	S^+f4$++8NNuH- A% W~3 d!23
>9uz'99IEEC$)$y5DJJ,C#DDyPP A%  $g-sNG {{&x#t{{W'<=:!/tt*b3 "J
 2X!*cRir-B!BJ!&J!*W5 "#"3C!8A! D%%mT^^DDD '' 2#aS
"dll1ot4!22** LLOA.QQ8J1KKC
  *C3x$!C9-!C9-aQ011D2 tOGc(SY.1AAK%%33$"8"8;"FGG4w59%0D"G0  - \\Q

4;; 781<	s9~-67DKK:PPC$++$5c#:!<t00OOO++ 
.Ac!AJ&D!22** LLOA.QQ8J1KKC
 Tz!C9-!C9-
. 4""7u=r'   c                 B    | j                  | j                  |z   |       y N)r^   r   )r$   nrK   s      r%   addzProgbar.add   s    D%%)62r'   c                     d}|dk\  s|dk(  r|d|dd| z  }|S |dk\  r|d|dz  dd	| z  }|S |d|d
z  dd| z  }|S )a  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
        r*   r)   r   r5   r2   zs/r4   g     @@zms/g    .Azus/ )r$   rS   r   	formatteds       r%   rA   zProgbar._format_time   s     	A!!31]3/r)==I
 	 d"1]V3C8I;GGI  1]Y6s;3ykJJIr'   c                     |rG| j                   |dkD  r|| j                   z
  |dz
  z  }n|| j                  z
  |z  }|dk(  r|| _         |S y)a  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.
        r)   r   )r"   r   )r$   rJ   rR   rS   s       r%   r;   zProgbar._estimate_step_duration   sd       **67Q;!$t'B'B!BaK! "%t{{!2g =!|.1+  r'   )   r)   g?Nstep)NNr`   )	__name__
__module____qualname____doc__r&   r^   rb   rA   r;   rd   r'   r%   r   r      s4      "#HR h3,"r'   r   )r=   r   r   r   	keras.srcr   keras.src.api_exportr   keras.src.utilsr   r   rd   r'   r%   <module>rp      s<     	 
   - $ #$A A %Ar'   