
    &`iR                     n    d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 e
 G d de                      ZdS )    )AnyDictListUnion)	StatsBase)single_value_to_cpu)DeveloperAPIc            
           e Zd ZdZdZ fdZdeeef         f fdZ	deeef         ddf fdZ
defd	Zddedeed f         fdZdeddfdZded          ddfdZ	 ddededeeee         f         fdZdefdZ xZS )	ItemStatsa  A Stats object that tracks a single item.

    Note the follwing limitation: That, when calling `ItemStats.merge()`, we replace the current item.
    This is because there can only be a single item tracked by definition.

    This class will check if the logged item is a GPU tensor.
    If it is, it will be converted to CPU memory.

    Use this if you want to track a single item that should not be reduced.
    An example would be to log the total loss.
    itemc                 H     t                      j        |i | d| _        dS )z!Initializes a ItemStats instance.N)super__init___item)selfargskwargs	__class__s      v/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/utils/metrics/stats/item.pyr   zItemStats.__init__   s*    $)&)))


    returnc                 \    t                                                      }| j        |d<   |S Nr   )r   	get_stater   r   stater   s     r   r   zItemStats.get_state   s(    !!##
fr   r   Nc                 d    t                                          |           |d         | _        d S r   )r   	set_stater   r   s     r   r   zItemStats.set_state"   s*    %   6]


r   c                     dS )N    r   s    r   __len__zItemStats.__len__&   s    qr   Tcompilec                 ~    | j         }d | _         t          |          }|r|S |                                 }||_         |S )N)r   r   clone)r   r$   r   return_statss       r   reducezItemStats.reduce)   sE    z
"4(( 	Kzz||!r   c                 .    t          |          | _        dS )zPushes a value into this Stats object.

        Args:
            item: The value to push. Can be of any type.
                GPU tensors are moved to CPU memory.

        Returns:
            None
        Nr   r   )r   r   s     r   pushzItemStats.push6   s     )..


r   incoming_statsc                 d    t          |          dk    s
J d            |d         j        | _        dS )zMerges ItemStats objects.

        Args:
            incoming_stats: The list of ItemStats objects to merge.

        Returns:
            None. The merge operation modifies self in place.
        r    z_ItemStats should only be merged with one other ItemStats object which replaces the current itemr   N)lenr   )r   r,   s     r   mergezItemStats.mergeC   s=     1$$$l %$$ $A&,


r   Flatest_merged_onlyc                 8    t          | j                  }|r|S |gS )a  Returns the internal item.

        This does not alter the internal item.

        Args:
            compile: If True, return the internal item directly.
                If False, return the internal item as a single-element list.
            latest_merged_only: This parameter is ignored for ItemStats.
                ItemStats tracks a single item, not a series of merged values.
                The current item is always returned regardless of this parameter.

        Returns:
            The internal item.
        r*   )r   r$   r0   r   s       r   peekzItemStats.peekR   s'    ( #4:.. 	Kvr   c                 0    d|                                   S )Nz
ItemStats()r2   r"   s    r   __repr__zItemStats.__repr__k   s    )DIIKK)))r   )T)TF)__name__
__module____qualname____doc__stats_cls_identifierr   r   strr   r   r   intr#   boolr   r(   r+   r   r/   r2   r4   __classcell__)r   s   @r   r   r      s       
 
 "    
4S>      
#tCH~ #$ # # # # # #     d eC4D.E    / / / / / /-D$5 -$ - - - -  @E 8<	sDI~	   2*# * * * * * * * *r   r   N)typingr   r   r   r   "ray.rllib.utils.metrics.stats.baser   #ray.rllib.utils.metrics.stats.utilsr   ray.util.annotationsr	   r   r!   r   r   <module>rB      s    ) ) ) ) ) ) ) ) ) ) ) ) 8 8 8 8 8 8 C C C C C C - - - - - - c* c* c* c* c*	 c* c* c* c* c*r   