@@ -282,11 +282,9 @@ void GCell::print(utl::Logger* logger, bool print_only_name = true) const
282282 }
283283}
284284
285- void GCell::printToFile (const std::string& filename,
286- bool print_only_name = true ) const
285+ void GCell::printToFile (std::ostream& out, bool print_only_name) const
287286{
288- std::ofstream out (filename, std::ios::app);
289- if (!out.is_open ()) {
287+ if (!out) {
290288 return ;
291289 }
292290
@@ -307,8 +305,6 @@ void GCell::printToFile(const std::string& filename,
307305 gradientX_,
308306 gradientY_);
309307 }
310-
311- out.close ();
312308}
313309
314310// //////////////////////////////////////////////
@@ -3367,21 +3363,44 @@ void NesterovBaseCommon::printGCells()
33673363 }
33683364}
33693365
3370- void NesterovBaseCommon::printGCellsToFile (const std::string& filename)
3366+ void NesterovBaseCommon::printGCellsToFile (const std::string& filename,
3367+ bool print_only_name,
3368+ bool also_print_minRc)
33713369{
33723370 std::ofstream out (filename);
33733371 if (!out.is_open ()) {
33743372 return ;
33753373 }
33763374
33773375 out << " gCellStor_.size(): " << gCellStor_ .size () << " \n " ;
3378- out.close (); // reuse printToFile which appends
3376+ out.close ();
3377+
3378+ std::ofstream out_append (filename, std::ios::app);
3379+ if (!out_append.is_open ()) {
3380+ return ;
3381+ }
33793382
33803383 for (size_t i = 0 ; i < gCellStor_ .size (); ++i) {
3381- std::ofstream out_idx (filename, std::ios::app);
3382- out_idx << fmt::format (" idx:{}\n " , i);
3383- out_idx.close ();
3384- gCellStor_ [i].printToFile (filename);
3384+ out_append << fmt::format (" idx:{}\n " , i);
3385+ gCellStor_ [i].printToFile (out_append, print_only_name);
3386+ }
3387+
3388+ out_append.close ();
3389+
3390+ if (also_print_minRc) {
3391+ std::string minrc_filename = filename + " .minrc" ;
3392+ std::ofstream minrc_out (minrc_filename);
3393+ if (!minrc_out.is_open ()) {
3394+ return ;
3395+ }
3396+
3397+ for (size_t i = 0 ; i < minRcCellSize_.size (); ++i) {
3398+ const auto & min_rc = minRcCellSize_[i];
3399+ minrc_out << fmt::format (
3400+ " idx:{} minRc: {} {}\n " , i, min_rc.first , min_rc.second );
3401+ }
3402+
3403+ minrc_out.close ();
33853404 }
33863405}
33873406
0 commit comments