From 40162fa0241da6fa61296db6dbb8b60dfe9e4aff Mon Sep 17 00:00:00 2001 From: kkm Date: Sun, 21 Jan 2018 01:06:45 -0800 Subject: [PATCH] [src] Log nnet3 computation to VLOG, not std::cout Use an auxiliary stream inserter class to print the nnet3 Computation instance to the logging stream. Also remove the declaration of undefined 'operator<<()'. --- src/nnet3/decodable-simple-looped.cc | 7 ++----- src/nnet3/nnet-computation.h | 27 ++++++++++++++++----------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/nnet3/decodable-simple-looped.cc b/src/nnet3/decodable-simple-looped.cc index 0452304cf55..71aa7daaa17 100644 --- a/src/nnet3/decodable-simple-looped.cc +++ b/src/nnet3/decodable-simple-looped.cc @@ -52,7 +52,6 @@ DecodableNnetSimpleLoopedInfo::DecodableNnetSimpleLoopedInfo( Init(opts, &(am_nnet->GetNnet())); } - void DecodableNnetSimpleLoopedInfo::Init( const NnetSimpleLoopedComputationOptions &opts, Nnet *nnet) { @@ -86,10 +85,8 @@ void DecodableNnetSimpleLoopedInfo::Init( CompileLooped(*nnet, opts.optimize_config, request1, request2, request3, &computation); computation.ComputeCudaIndexes(); - if (GetVerboseLevel() >= 3) { - KALDI_VLOG(3) << "Computation is:"; - computation.Print(std::cerr, *nnet); - } + KALDI_VLOG(3) << "Computation is:\n" + << NnetComputationPrintInserter{computation, *nnet}; } diff --git a/src/nnet3/nnet-computation.h b/src/nnet3/nnet-computation.h index 97d8b9045ea..a3571eeb532 100644 --- a/src/nnet3/nnet-computation.h +++ b/src/nnet3/nnet-computation.h @@ -514,17 +514,22 @@ struct NnetComputation { NnetComputation(): need_model_derivative(false) { } }; - - - -// This operator is to print out the NnetComputation in a human-readable way, for -// debugging purposes. -// We don't give Read and Write functions to struct NnetComputation, because we -// don't anticipate needing to write it to disk. -std::ostream &operator << (std::ostream &os, - NnetComputation &computation); - - +// A helper class equipped with the stream insertion operator<< to print out +// the NnetComputation in a human-readable way, with NnetComputation::Print(), +// for debugging purposes, e.g.: +// KALDI_VLOG(3) << NnetComputationPrintInserter{mycomputation, mynet}; +struct NnetComputationPrintInserter { + const NnetComputation& computation; + const Nnet& nnet; + void Print(std::ostream& os) const { + computation.Print(os, nnet); + } + friend inline std::ostream &operator <<(std::ostream &os, + NnetComputationPrintInserter xhis) { + xhis.Print(os); + return os; + } +}; } // namespace nnet3 } // namespace kaldi