Changeset 2542 for branches


Ignore:
Timestamp:
05/22/12 10:17:06 (12 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...

More speedup of STMath::average().

  • Reduced number of call of RowAccumulator::replaceNaN().
  • Performance of RowAccumulator::add() is improved.


Location:
branches/hpc33/src
Files:
3 edited

Legend:

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

    r2141 r2542  
    8181                                 const Double time)
    8282{
    83   doAddSpectrum(v, m, tsys, interval, time, False);
    84   doAddSpectrum(v, m, tsys, interval, time, True);  // CAS-2776
     83//   doAddSpectrum(v, m, tsys, interval, time, False);
     84//   doAddSpectrum(v, m, tsys, interval, time, True);  // CAS-2776
     85  doAddSpectrum2( v, m, tsys, interval, time ) ;
    8586}
    8687
     
    112113}
    113114
     115void RowAccumulator::doAddSpectrum2(const Vector<Float>& v,
     116                                    const Vector<Bool>& m,
     117                                    const Vector<Float>& tsys,
     118                                    const Double interval,
     119                                    const Double time)
     120{
     121  const MaskedArray<Float> vadd(v, m);
     122  const MaskedArray<Float> vaddN(v, !m);
     123  Float totalWeight = getTotalWeight( vadd, tsys, interval, time, False ) ;
     124  Float totalWeightNoMask = getTotalWeight( vaddN, tsys, interval, time, True ) ;
     125  // process spectrum with input mask and spectrum with inverted mask
     126  // together
     127  // prepare pointers
     128  Bool vD, mD ;
     129  const Float *v_p = v.getStorage( vD ) ;
     130  const Float *v_wp = v_p ;
     131  const Bool *m_p = m.getStorage( mD ) ;
     132  const Bool *m_wp = m_p ;
     133
     134  Bool spD, spND, wgtD, wgtND, nD, nND ;
     135  Float *sp_p = spectrum_.getRWArrayStorage( spD ) ;
     136  Float *sp_wp = sp_p ;
     137  Float *wgt_p = weightSum_.getRWArrayStorage( wgtD ) ;
     138  Float *wgt_wp = wgt_p ;
     139  Float *spN_p = spectrumNoMask_.getRWArrayStorage( spND ) ;
     140  Float *spN_wp = spN_p ;
     141  Float *wgtN_p = weightSumNoMask_.getRWArrayStorage( wgtND ) ;
     142  Float *wgtN_wp = wgtN_p ;
     143  uInt *n_p = n_.getRWArrayStorage( nD ) ;
     144  uInt *n_wp = n_p ;
     145  uInt *nN_p = nNoMask_.getRWArrayStorage( nND ) ;
     146  uInt *nN_wp = nN_p ;
     147
     148  // actual processing
     149  uInt len = m.nelements() ;
     150  // loop over channels
     151  for ( uInt i = 0 ; i < len ; i++ ) {
     152    // masks for spectrum_ and spectrumNoMask_ are not needed since
     153    // it is initialized as True for all channels and those are constant
     154    if ( *m_wp ) {
     155      // mask is True
     156      // add v * totalWeight to spectrum_
     157      // add totalWeight to weightSum_
     158      // increment n_
     159      *sp_wp += *v_wp * totalWeight ;
     160      *wgt_wp += totalWeight ;
     161      *n_wp += 1 ;
     162    }
     163    else {
     164      // mask is False
     165      // add v * totalWeightNoMask to spectrumNoMask_
     166      // add totalWeightNoMask to weightSumNoMask_
     167      // increment nNoMask_
     168      *spN_wp += *v_wp * totalWeightNoMask ;
     169      *wgtN_wp += totalWeightNoMask ;
     170      *nN_wp += 1 ;
     171    }
     172    sp_wp++ ;
     173    wgt_wp++ ;
     174    n_wp++ ;
     175    spN_wp++ ;
     176    wgtN_wp++ ;
     177    nN_wp++ ;
     178    v_wp++ ;
     179    m_wp++ ;
     180  }
     181
     182  // free storage
     183  spectrum_.putArrayStorage( sp_p, spD ) ;
     184  weightSum_.putArrayStorage( wgt_p, wgtD ) ;
     185  spectrumNoMask_.putArrayStorage( spN_p, spND ) ;
     186  weightSumNoMask_.putArrayStorage( wgtN_p, wgtND ) ;
     187  n_.putArrayStorage( n_p, nD ) ;
     188  nNoMask_.putArrayStorage( nN_p, nND ) ;
     189
     190  v.freeStorage( v_p, vD ) ;
     191  m.freeStorage( m_p, mD ) ;
     192}
     193
    114194Float RowAccumulator::getTotalWeight(const MaskedArray<Float>& data,
    115195                                     const Vector<Float>& tsys,
  • branches/hpc33/src/RowAccumulator.h

    r2141 r2542  
    109109                     const casa::Double time,
    110110                     const casa::Bool inverseMask);
     111  void doAddSpectrum2(const casa::Vector<casa::Float>& v,
     112                      const casa::Vector<casa::Bool>& m,
     113                      const casa::Vector<casa::Float>& tsys,
     114                      const casa::Double interval,
     115                      const casa::Double time);
    111116  casa::Float getTotalWeight(const casa::MaskedArray<casa::Float>& data,
    112117                             const casa::Vector<casa::Float>& tsys,
  • branches/hpc33/src/STMath.cpp

    r2540 r2542  
    164164  // use STIdxIterExAcc instead of TableIterator
    165165  STIdxIterExAcc iter( in[0], cols ) ;
     166//   double t2 = 0 ;
     167//   double t3 = 0 ;
    166168//   TableIterator iter(baset, cols);
    167169//   int count = 0 ;
     
    229231
    230232    // in[0] is already selected by TableItertor
    231 //     specCol.attach(subt,"SPECTRA");
    232 //     flagCol.attach(subt,"FLAGTRA");
    233 //     tsysCol.attach(subt,"TSYS");
    234 //     intCol.attach(subt,"INTERVAL");
    235 //     mjdCol.attach(subt,"TIME");
    236233    specCol.attach(baset,"SPECTRA");
    237234    flagCol.attach(baset,"FLAGTRA");
     
    258255      mjdCol.get(k, time);
    259256      // spectrum has to be added last to enable weighting by the other values                             
     257//       t2 = mathutil::gettimeofday_sec() ;
    260258      acc.add(spec, !bflag, tsys, inter, time);
    261     }
    262 
    263     // If there exists a channel at which all the input spectra are masked,                               
    264     // spec has 'nan' values for that channel and it may affect the following                             
    265     // processes. To avoid this, replacing 'nan' values in spec with                                       
    266     // weighted-mean of all spectra in the following line.                                                 
    267     // (done for CAS-2776, 2011/04/07 by Wataru Kawasaki)                                                 
    268     acc.replaceNaN();
     259//       t3 += mathutil::gettimeofday_sec() - t2 ;
     260     
     261    }
     262
    269263
    270264    // in[0] is already selected by TableIterator so that index is
     
    337331      intCol.attach(subt,"INTERVAL");
    338332      mjdCol.attach(subt,"TIME");
    339 //       Vector<Float> spec,tsys;
    340 //       Vector<uChar> flag;
    341 //       Double inter,time;
    342333      for (uInt k = 0; k < subt.nrow(); ++k ) {
    343334        flagCol.get(k, flag);
     
    354345        mjdCol.get(k, time);
    355346        // spectrum has to be added last to enable weighting by the other values
     347//         t2 = mathutil::gettimeofday_sec() ;
    356348        acc.add(spec, !bflag, tsys, inter, time);
    357       }
    358 
     349//         t3 += mathutil::gettimeofday_sec() - t2 ;
     350      }
     351
     352    }
     353    const Vector<Bool>& msk = acc.getMask();
     354    if ( allEQ(msk, False) ) {
     355      uint n = rowstodelete.nelements();
     356      rowstodelete.resize(n+1, True);
     357      rowstodelete[n] = i;
     358      continue;
     359    }
     360    //write out
     361    if (acc.state()) {
    359362      // If there exists a channel at which all the input spectra are masked,
    360363      // spec has 'nan' values for that channel and it may affect the following
     
    363366      // (done for CAS-2776, 2011/04/07 by Wataru Kawasaki)
    364367      acc.replaceNaN();
    365     }
    366     const Vector<Bool>& msk = acc.getMask();
    367     if ( allEQ(msk, False) ) {
    368       uint n = rowstodelete.nelements();
    369       rowstodelete.resize(n+1, True);
    370       rowstodelete[n] = i;
    371       continue;
    372     }
    373     //write out
    374     if (acc.state()) {
     368
    375369      Vector<uChar> flg(msk.shape());
    376370      convertArray(flg, !msk);
     
    413407//    t1 = mathutil::gettimeofday_sec() ;
    414408//    cout << "elapsed time for average(): " << t1-t0 << " sec" << endl ;
     409//    cout << "   elapsed time for acc.add(): " << t3 << " sec" << endl ;
    415410
    416411  return out;
Note: See TracChangeset for help on using the changeset viewer.