Changeset 2539 for branches/hpc33


Ignore:
Timestamp:
05/20/12 17:05:33 (13 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Speedup STMath::average(). Duplicated data selection for first input table
is removed by merging TableIterator loop with for loop over the rows for
output table.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/hpc33/src/STMath.cpp

    r2534 r2539  
    8383                 const std::string& avmode)
    8484{
     85  //  double t0, t1 ;
     86  //  t0 = mathutil::gettimeofday_sec() ;
     87
    8588  LogIO os( LogOrigin( "STMath", "average()", WHERE ) ) ;
    8689  if ( avmode == "SCAN" && in.size() != 1 )
     
    131134  const Table& baset = in[0]->table();
    132135
     136  RowAccumulator acc(wtype);
     137  Vector<Bool> cmask(mask);
     138  acc.setUserMask(cmask);
     139  ROTableRow row(tout);
     140  ROArrayColumn<Float> specCol, tsysCol;
     141  ROArrayColumn<uChar> flagCol;
     142  ROScalarColumn<Double> mjdCol, intCol;
     143  ROScalarColumn<Int> scanIDCol;
     144
     145  Vector<uInt> rowstodelete;
     146
    133147  Block<String> cols(3);
    134148  cols[0] = String("BEAMNO");
     
    158172      scanColOut.put(outrowCount, uInt(0));
    159173    }
     174    /*
    160175    ++outrowCount;
     176    */
    161177    // 2012/02/17 TN
    162178    // Since STGrid is implemented, average doesn't consider direction
     
    198214//     }
    199215//     outrowCount += rowNum ;
     216/*
    200217    ++iter;
    201218  }
     
    210227
    211228  Vector<uInt> rowstodelete;
    212 
    213   for (uInt i=0; i < tout.nrow(); ++i) {
    214     for ( int j=0; j < int(in.size()); ++j ) {
     229*/
     230
     231// merge loop
     232    uInt i = outrowCount ;
     233//  for (uInt i=0; i < tout.nrow(); ++i) {
     234
     235    // in[0] is already selected by TableItertor
     236    specCol.attach(subt,"SPECTRA");
     237    flagCol.attach(subt,"FLAGTRA");
     238    tsysCol.attach(subt,"TSYS");
     239    intCol.attach(subt,"INTERVAL");
     240    mjdCol.attach(subt,"TIME");
     241    Vector<Float> spec,tsys;
     242    Vector<uChar> flag;
     243    Double inter,time;
     244    for (uInt k = 0; k < subt.nrow(); ++k ) {
     245      flagCol.get(k, flag);
     246      Vector<Bool> bflag(flag.shape());
     247      convertArray(bflag, flag);
     248      /*                                                                                                   
     249        if ( allEQ(bflag, True) ) {                                                                         
     250        continue;//don't accumulate                                                                         
     251        }                                                                                                   
     252      */
     253      specCol.get(k, spec);
     254      tsysCol.get(k, tsys);
     255      intCol.get(k, inter);
     256      mjdCol.get(k, time);
     257      // spectrum has to be added last to enable weighting by the other values                             
     258      acc.add(spec, !bflag, tsys, inter, time);
     259    }
     260
     261    // If there exists a channel at which all the input spectra are masked,                               
     262    // spec has 'nan' values for that channel and it may affect the following                             
     263    // processes. To avoid this, replacing 'nan' values in spec with                                       
     264    // weighted-mean of all spectra in the following line.                                                 
     265    // (done for CAS-2776, 2011/04/07 by Wataru Kawasaki)                                                 
     266    acc.replaceNaN();
     267
     268    // in[0] is already selected by TableIterator so that it is not necessary to process
     269    // in[0] here
     270    //for ( int j=0; j < int(in.size()); ++j ) {
     271    for ( int j=1; j < int(in.size()); ++j ) {
    215272      const Table& tin = in[j]->table();
    216273      const TableRecord& rec = row.get(i);
     
    231288                         && tin.col("POLNO") == Int(rec.asuInt("POLNO")) );
    232289#endif
    233       Table subt;
     290      //      Table subt;
    234291      if ( avmode == "SOURCE") {
    235292        subt = basesubt( basesubt.col("SRCNAME") == rec.asString("SRCNAME"));
     
    329386    }
    330387    acc.reset();
     388
     389    // merge with while loop for preparing out table
     390    ++outrowCount;
     391    ++iter ;
    331392  }
    332393
     
    338399    }
    339400  }
     401
     402  //  t1 = mathutil::gettimeofday_sec() ;
     403  //  cout << "elapsed time for average(): " << t1-t0 << " sec" << endl ;
     404
    340405  return out;
    341406}
     
    38613926  }
    38623927  else {
    3863 //     double t0, t1 ;
    3864 //     t0 = mathutil::gettimeofday_sec() ;
     3928    //    double t0, t1 ;
     3929    //    t0 = mathutil::gettimeofday_sec() ;
    38653930    vector<bool> masks = s->getMask( 0 ) ;
    38663931   
     
    39193984    soff->scanCol_.putColumn( newscanno ) ;
    39203985//     cout << "new scancol = " << soff->scanCol_.getColumn() << endl ;
    3921 //     double t2 = mathutil::gettimeofday_sec() ;
     3986//    double t2 = mathutil::gettimeofday_sec() ;
    39223987    vector< CountedPtr<Scantable> > tmp( 1, soff ) ;
    39233988    CountedPtr<Scantable> aoff = average( tmp, masks, "TINT", "SCAN" ) ;
    3924 //     double t3 = mathutil::gettimeofday_sec() ;
     3989    //    double t3 = mathutil::gettimeofday_sec() ;
    39253990    //cout << "aoff.nrow = " << aoff->nrow() << endl ;
    39263991    s->unsetSelection() ;
    39273992    sel.reset() ;
    3928 //     t1 = mathutil::gettimeofday_sec() ;
    3929 //     cout << "elapsed time for off averaging: " << t1-t0 << " sec" << endl ;
    3930 //     cout << "   elapsed time for average(): " << t3-t2 << " sec" << endl ;
     3993    //    t1 = mathutil::gettimeofday_sec() ;
     3994    //    cout << "elapsed time for off averaging: " << t1-t0 << " sec" << endl ;
     3995    //    cout << "   elapsed time for average(): " << t3-t2 << " sec" << endl ;
    39313996   
    39323997    // on scan
    3933 //     t0 = mathutil::gettimeofday_sec() ;
     3998    //    t0 = mathutil::gettimeofday_sec() ;
    39343999    bool insitu = insitu_ ;
    39354000    insitu_ = false ;
     
    39424007    s->unsetSelection() ;
    39434008    sel.reset() ;
    3944 //     t1 = mathutil::gettimeofday_sec() ;
    3945 //     cout << "elapsed time for preparing output table: " << t1-t0 << " sec" << endl ;
     4009    //    t1 = mathutil::gettimeofday_sec() ;
     4010    //    cout << "elapsed time for preparing output table: " << t1-t0 << " sec" << endl ;
    39464011
    39474012    // process each on scan
    3948 //     t0 = mathutil::gettimeofday_sec() ;
     4013    //    t0 = mathutil::gettimeofday_sec() ;
    39494014//     for ( int i = 0 ; i < out->nrow() ; i++ ) {
    39504015//       vector<float> sp = getCalibratedSpectra( out, aoff, i ) ;
     
    39754040    delete iter ;
    39764041
    3977 //     t1 = mathutil::gettimeofday_sec() ;
    3978 //     cout << "elapsed time for calibration: " << t1-t0 << " sec" << endl ;
     4042    //    t1 = mathutil::gettimeofday_sec() ;
     4043    //    cout << "elapsed time for calibration: " << t1-t0 << " sec" << endl ;
    39794044
    39804045    // flux unit
Note: See TracChangeset for help on using the changeset viewer.