license import { Scalar , Tensor , util } from '@tensorflow/tfjs' ; import { NodeJSKernelBackend } from './nodejs_kernel_backend' ; import { ensureTensorflowBackend , nodeBackend } from './ops/op_utils' ; export class SummaryFileWriter { backend : NodeJSKernelBackend ; constructor ( private readonly resourceHandle ) { ensureTensorflowBackend ( ) ; this . backend = nodeBackend ( ) ; } param name param value param step param description scalar ( name , value , step , description ? ) { if ( description != null ) { throw new Error ( 'scalar() does not support description yet' ) ; } this . backend . writeScalarSummary ( this . resourceHandle , step , name , value ) ; } /**
     * Force summary writer to send all buffered data to storage.
     */ flush ( ) { this . backend . flushSummaryWriter ( this . resourceHandle ) ; } } /**
 * Use a cache for `SummaryFileWriter` instance.
 *
 * Using multiple instances of `SummaryFileWriter` pointing to the same
 * logdir has potential problems. Using this cache avoids those problems.
 */ const summaryFileWriterCache = { } ; param logdir param maxQueue param flushMillis param filenameSuffix returns doc export function summaryFileWriter ( logdir , maxQueue = 10 , flushMillis = 120000 , filenameSuffix = '.v2' ) { util . assert ( logdir != null && typeof logdir === 'string' && logdir . length > 0 , ( ) => `Invalid logdir: ${ logdir }. Expected a non-empty string for logdir.` ) ; if ( ! ( logdir in summaryFileWriterCache ) ) { ensureTensorflowBackend ( ) ; const backend = nodeBackend ( ) ; const writerResource = backend . summaryWriter ( logdir ) ; backend . createSummaryFileWriter ( writerResource , logdir , maxQueue , flushMillis , filenameSuffix ) ; summaryFileWriterCache [ logdir ] = new SummaryFileWriter ( writerResource ) ; } return summaryFileWriterCache [ logdir ] ; }