
    1Vh~                     J    d Z ddlZddlZddlmZ ddlmZ  G d d      Z	d Z
y)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                   6    e Zd ZdZd Zd Zd Zd ZddddZy)	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                     t        |t        j                        r|| _        d| _        yt        |t              r"t        j                  |      | _        d| _        yt        d|z        )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outputs     K/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/summary/_writer.py__init__zWriter.__init__&   s\     fgnn-!DL
 	 $"226:DL  :VCDD    c                 2    | j                   rt        d      y )NzWriter is already closed)r   RuntimeErrorr   s    r   _check_not_closedzWriter._check_not_closed7   s    <<9:: r   c                 X    | j                          | j                  j                          y)zFlushes any buffered data.N)r   r   flushr   s    r   r   zWriter.flush;   s     r   c                 f    | j                          | j                  j                          d| _        y)z+Closes the writer and prevents further use.TN)r   r   closer   r   s    r   r   zWriter.close@   s%     r   N)	wall_timedescriptionc                .   | j                          t        t        j                  |      d      }t        t        j                  |      d      }||nt        j
                         }| j                  j                  t        j                  |||||       y)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_datavalidated_steps           r   
add_scalarzWriter.add_scalarF   sz      	 /

40@&I/G!*!6IDIIK	  (44# 	! 	
r   )	__name__
__module____qualname____doc__r   r   r   r   r,    r   r   r   r      s'    ";
 8< 
r   r   c                 F    | j                   dk7  rt        d|d|       | S )Nr   zExpected scalar value for z	 but got )ndim
ValueError)ndarraynames     r   r"   r"   d   s*    ||q9=wG
 	
 Nr   )r0   r&   numpyr#   tensorboard.plugins.scalarr   r(   tensorboard.summaryr   r   r"   r1   r   r   <module>r:      s*      C 'D
 D
Nr   