a
    Sic~                     @   sF   d Z ddlZddlZddlmZ ddlmZ G dd dZ	dd Z
dS )	zImplementation for tensorboard.summary.Writer and related symbols.

This provides a TensorBoard-native summary writing API that only depends
on numpy and not any particular ML framework.
    N)metadata)_outputc                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d
dddZd
S )WriterzWrites summary data for visualization in TensorBoard.

    This class is not thread-safe.

    TODO(#4581): This API should be considered EXPERIMENTAL and subject to
    backwards-incompatible changes without notice.
    c                 C   sB   t |tjr|| _n$t |tr,t|| _ntd| d| _dS )aa  Constructs a Writer.

        Args:
          output: `tensorboard.summary.Output` object, or a string which will be
            interpreted as shorthand for an `Output` of the appropriate type. The
            only currently supported type is `DirectoryOutput`, where the string
            value given here will be used as the directory path.
        zUnsupported output object %rFN)
isinstancer   OutputstrDirectoryOutput	TypeError_closed)selfoutput r   W/var/www/html/django/DPS/env/lib/python3.9/site-packages/tensorboard/summary/_writer.py__init__&   s    	
zWriter.__init__c                 C   s   | j rtdd S )NzWriter is already closed)r
   RuntimeErrorr   r   r   r   _check_not_closed7   s    zWriter._check_not_closedc                 C   s   |    | j  dS )zFlushes any buffered data.N)r   r   flushr   r   r   r   r   ;   s    zWriter.flushc                 C   s   |    | j  d| _dS )z+Closes the writer and prevents further use.TN)r   r   closer
   r   r   r   r   r   @   s    
zWriter.closeN)	wall_timedescriptionc                C   sZ   |    tt|d}tt|d}|dur4|nt }| jjtj	|||||d dS )a  Adds a scalar summary.

        Args:
          tag: string tag used to uniquely identify this time series.
          data: numeric scalar value for this data point. Accepts any value that
            can be converted to a `np.float32` scalar.
          step: integer step value for this data point. Accepts any value that
            can be converted to a `np.int64` scalar.
          wall_time: optional `float` seconds since the Unix epoch, representing
            the real-world timestamp for this data point. Defaults to None in
            which case the current time will be used.
          description: optional string description for this entire time series.
            This should be constant for a given tag; only the first value
            encountered will be used.
        datastepN)plugin_nametagr   r   r   r   )
r   _validate_scalar_shapenpfloat32int64timer   emit_scalarscalars_metadataPLUGIN_NAME)r   r   r   r   r   r   validated_dataZvalidated_stepr   r   r   
add_scalarF   s    zWriter.add_scalar)	__name__
__module____qualname____doc__r   r   r   r   r$   r   r   r   r   r      s   r   c                 C   s   | j dkrtd|| f | S )Nr   z'Expected scalar value for %r but got %r)ndim
ValueError)ndarraynamer   r   r   r   d   s
    

r   )r(   r   numpyr   tensorboard.plugins.scalarr   r!   tensorboard.summaryr   r   r   r   r   r   r   <module>   s   G