void Snapshot ( const DistMatrix<Int, VR,STAR>& preimage, const DistMatrix<Real,MR,STAR>& estimates, const DistMatrix<Int, VR,STAR>& itCounts, Int numIts, bool deflate, SnapshotCtrl& snapCtrl ) { EL_DEBUG_CSE auto logMap = []( const Real& alpha ) { return Log(alpha); }; if( snapCtrl.realSize != 0 && snapCtrl.imagSize != 0 ) { const bool numSave = ( snapCtrl.numSaveFreq > 0 && snapCtrl.numSaveCount >= snapCtrl.numSaveFreq ); const bool imgSave = ( snapCtrl.imgSaveFreq > 0 && snapCtrl.imgSaveCount >= snapCtrl.imgSaveFreq ); const bool imgDisp = ( snapCtrl.imgDispFreq > 0 && snapCtrl.imgDispCount >= snapCtrl.imgDispFreq ); DistMatrix<Real,VR,STAR> invNorms(estimates.Grid()); DistMatrix<Real> estMap(estimates.Grid()); DistMatrix<Int, VR,STAR> itCountsReord(itCounts.Grid()); DistMatrix<Int> itCountMap(itCounts.Grid()); if( numSave || imgSave || imgDisp ) { invNorms = estimates; if( deflate ) RestoreOrdering( preimage, invNorms ); ReshapeIntoGrid ( snapCtrl.realSize, snapCtrl.imagSize, invNorms, estMap ); if( snapCtrl.itCounts ) { itCountsReord = itCounts; if( deflate ) RestoreOrdering( preimage, itCountsReord ); ReshapeIntoGrid ( snapCtrl.realSize, snapCtrl.imagSize, itCountsReord, itCountMap ); } } if( numSave ) { auto title = BuildString( snapCtrl.numBase, "_", numIts ); Write( estMap, title, snapCtrl.numFormat ); if( snapCtrl.itCounts ) Write( itCountMap, title+"_counts", snapCtrl.numFormat ); snapCtrl.numSaveCount = 0; } if( imgSave || imgDisp ) EntrywiseMap( estMap, MakeFunction(logMap) ); if( imgSave ) { auto title = BuildString( snapCtrl.imgBase, "_", numIts ); Write( estMap, title, snapCtrl.imgFormat ); if( snapCtrl.itCounts ) Write( itCountMap, title+"_counts", snapCtrl.imgFormat ); auto colorMap = GetColorMap(); SetColorMap( GRAYSCALE_DISCRETE ); Write( estMap, title+"_discrete", snapCtrl.imgFormat ); SetColorMap( colorMap ); snapCtrl.imgSaveCount = 0; } if( imgDisp ) { auto title = BuildString( snapCtrl.imgBase, "_", numIts ); Display( estMap, title ); if( snapCtrl.itCounts ) Display( itCountMap, title+"_counts" ); auto colorMap = GetColorMap(); SetColorMap( GRAYSCALE_DISCRETE ); Display( estMap, title+"_discrete" ); SetColorMap( colorMap ); snapCtrl.imgDispCount = 0; } } }
inline void Snapshot ( const DistMatrix<Int, VR,STAR>& preimage, const DistMatrix<Real,MR,STAR>& estimates, const DistMatrix<Int, VR,STAR>& itCounts, Int numIts, bool deflate, SnapshotCtrl& snapCtrl ) { DEBUG_ONLY(CallStackEntry cse("pspec::Snapshot")); if( snapCtrl.realSize != 0 && snapCtrl.imagSize != 0 ) { const bool numSave = ( snapCtrl.numSaveFreq > 0 && snapCtrl.numSaveCount >= snapCtrl.numSaveFreq ); const bool imgSave = ( snapCtrl.imgSaveFreq > 0 && snapCtrl.imgSaveCount >= snapCtrl.imgSaveFreq ); const bool imgDisp = ( snapCtrl.imgDispFreq > 0 && snapCtrl.imgDispCount >= snapCtrl.imgDispFreq ); DistMatrix<Real,VR,STAR> invNorms(estimates.Grid()); DistMatrix<Real> estMap(estimates.Grid()); DistMatrix<Int, VR,STAR> itCountsReord(itCounts.Grid()); DistMatrix<Int> itCountMap(itCounts.Grid()); if( numSave || imgSave || imgDisp ) { invNorms = estimates; if( deflate ) RestoreOrdering( preimage, invNorms ); ReshapeIntoGrid ( snapCtrl.realSize, snapCtrl.imagSize, invNorms, estMap ); if( snapCtrl.itCounts ) { itCountsReord = itCounts; if( deflate ) RestoreOrdering( preimage, itCountsReord ); ReshapeIntoGrid ( snapCtrl.realSize, snapCtrl.imagSize, itCountsReord, itCountMap ); } } if( numSave ) { std::ostringstream os; os << snapCtrl.numBase << "-" << numIts; Write( estMap, os.str(), snapCtrl.numFormat ); if( snapCtrl.itCounts ) Write( itCountMap, os.str()+"-counts", snapCtrl.numFormat ); snapCtrl.numSaveCount = 0; } if( imgSave || imgDisp ) EntrywiseMap( estMap, []( Real alpha ) { return Log(alpha); } ); if( imgSave ) { std::ostringstream os; os << snapCtrl.imgBase << "-" << numIts; Write( estMap, os.str(), snapCtrl.imgFormat ); if( snapCtrl.itCounts ) Write( itCountMap, os.str()+"-counts", snapCtrl.imgFormat ); auto colorMap = GetColorMap(); SetColorMap( GRAYSCALE_DISCRETE ); Write( estMap, os.str()+"-discrete", snapCtrl.imgFormat ); SetColorMap( colorMap ); snapCtrl.imgSaveCount = 0; } if( imgDisp ) { std::ostringstream os; os << snapCtrl.imgBase << "-" << numIts; Display( estMap, os.str() ); if( snapCtrl.itCounts ) Display( itCountMap, os.str()+"-counts" ); auto colorMap = GetColorMap(); SetColorMap( GRAYSCALE_DISCRETE ); Display( estMap, os.str()+"-discrete" ); SetColorMap( colorMap ); snapCtrl.imgDispCount = 0; } } }