示例#1
0
//-----------------------------------------------------------------------------
void IQDump::process()
{
   complex<float> s;
   int band=1;
   unsigned long N=0;
   typedef map<float, unsigned long> HistMap;
   HistMap hist;
   while (*input >> s)
   {
      if (!stats)
         cout << s.real() << " " << s.imag() << " ";
      else
      {
         if (band==1)
         {
            N++;
            ++hist[s.real()];
            ++hist[s.imag()];
         }
      }
      if (band == bands)
      {
         band=1;
         if (!stats)
            cout << endl;
      }
      else
         band++;
   }

   if (stats)
   {
      N*=2; // I & Q each count as a separate sample
      cout << "# " << N << " samples" << endl
           << "# value  frac" << endl;
      for (HistMap::const_iterator i = hist.begin(); i != hist.end(); i++)
         cout << "# " << setw(4) <<  i->first << " : " << (float)i->second/N << endl;

      unsigned long pos(0),neg(0);
      for (HistMap::const_iterator i = hist.begin(); i != hist.end(); i++)
         if (i->first > 0)
            pos += i->second;
         else
            neg += i->second;

      cout << endl
           << "#   >0 : " << (float)pos/N << endl
           << "#  <=0 : " << (float)neg/N << endl;
   }
}
示例#2
0
//----------------------------------------------------------------//
void MOAILuaRuntime::ReportHistogram ( FILE *f ) {

	if ( !this->mHistogramEnabled ) return;
	
	HistMap histogram;
	this->BuildHistogram ( histogram );
	
	fprintf ( f, "tracking %d of %d allocated MOAIObjects\n", ( int )this->mHistSet.size (), ( int )this->mObjectCount );
	
	size_t totalTracked = this->mHistSet.size ();
	
	HistMap::iterator histogramIt = histogram.begin ();
	for ( ; histogramIt != histogram.end (); ++histogramIt ) {
	
		const STLString& name = histogramIt->first;
		size_t count = histogramIt->second;
		float percent = (( float )count / ( float )totalTracked ) * 100.0f;
	
		fprintf ( f, "%-32.32s %d (%.2f%% of %d)\n", name.str (), ( int )count, percent, ( int )totalTracked );
	}
}
示例#3
0
//----------------------------------------------------------------//
void MOAILuaRuntime::PushHistogram ( MOAILuaState& state ) {
	
	if ( !this->mHistogramEnabled ) {
		lua_pushnil ( state );
		return;
	}
	
	lua_newtable ( state );
	
	HistMap histogram;
	this->BuildHistogram ( histogram );
	
	HistMap::iterator histogramIt = histogram.begin ();
	for ( ; histogramIt != histogram.end (); ++histogramIt ) {
	
		const STLString& name = histogramIt->first;
		size_t count = histogramIt->second;
		
		lua_pushstring ( state, name );
		lua_pushnumber ( state, count );
		lua_settable ( state, -3 );
	}
}
示例#4
0
//----------------------------------------------------------------//
void MOAILuaRuntime::BuildHistogram ( HistMap& histogram ) {

	HistSet::iterator histSetIt = this->mHistSet.begin ();
	for ( ; histSetIt != this->mHistSet.end (); ++histSetIt ) {
	
		MOAILuaObject* obj = *histSetIt;
		cc8* name = obj->TypeName ();
	
		if ( !histogram.contains ( name )) {
			histogram [ name ] = 1;
		}
		else {
			histogram [ name ]++;
		}
	}
}