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.


File:
1 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,
Note: See TracChangeset for help on using the changeset viewer.