Changeset 2368


Ignore:
Timestamp:
12/14/11 15:58:43 (13 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-2816

Ready for Test: No

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...

Speed up code.

  • setData: defined. Changed Array access, which was using Slicer, to

direct data access using getStorage.

  • saveData: reference table is created as Plain table instead of Memory

table to save memory usage

  • getWeight: skip weight initialization.


Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STGrid.cpp

    r2365 r2368  
    289289  gwgtArr.putStorage( wdata_p, deleteWgtG ) ;
    290290  Array<Float> gdataArr = real( gdataArrC ) ;
    291   t0 = mathutil::gettimeofday_sec() ;
    292   data_.resize( gdataArr.shape() ) ;
    293   data_ = 0.0 ;
    294   for ( Int ix = 0 ; ix < nx_ ; ix++ ) {
    295     for ( Int iy = 0 ; iy < ny_ ; iy++ ) {
    296       for ( Int ip = 0 ; ip < npol_ ; ip++ ) {
    297         for ( Int ic = 0 ; ic < nchan_ ; ic++ ) {
    298           IPosition pos( 4, ix, iy, ip, ic ) ;
    299           IPosition gpos( 4, ix, iy, ip, ic ) ;
    300 //           IPosition gpos( 4, ix+convSupport_, iy+convSupport_, ip, ic ) ;
    301           if ( gwgtArr( gpos ) > 0.0 )
    302             data_( pos ) = gdataArr( gpos ) / gwgtArr( gpos ) ;
    303         }
    304       }
    305     }
    306   }
    307   t1 = mathutil::gettimeofday_sec() ;
    308   os << "set data: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
     291  setData( data_, gdataArr, gwgtArr ) ;
    309292  //Matrix<Double> sumWeight( IPosition( 2, npol_, nchan_ ), sumw_p, TAKE_OVER ) ;
    310293  delete sumw_p ;
     
    313296//   os << "gwgtArr = " << gwgtArr << LogIO::POST ;
    314297//   os << "data_ " << data_ << LogIO::POST ;
     298}
     299
     300void STGrid::setData( Array<Float> &data,
     301                      Array<Float> &gdata,
     302                      Array<Float> &gwgt )
     303{
     304  LogIO os( LogOrigin("STGrid","setData",WHERE) ) ;
     305  double t0, t1 ;
     306  t0 = mathutil::gettimeofday_sec() ;
     307  data.resize( gdata.shape() ) ;  //data = 0.0 ;
     308  uInt len = data.nelements() ;
     309  Float *w0_p ;
     310  const Float *w1_p, *w2_p ;
     311  Bool b0, b1, b2 ;
     312  Float *data_p = data.getStorage( b0 ) ;
     313  const Float *gdata_p = gdata.getStorage( b1 ) ;
     314  const Float *gwgt_p = gwgt.getStorage( b2 ) ;
     315  w0_p = data_p ;
     316  w1_p = gdata_p ;
     317  w2_p = gwgt_p ;
     318  for ( uInt i = 0 ; i < len ; i++ ) {
     319    *w0_p = (*w2_p > 0.0) ? (*w1_p / *w2_p) : 0.0 ;
     320    w0_p++ ;
     321    w1_p++ ;
     322    w2_p++ ;
     323  }
     324  data.putStorage( data_p, b0 ) ;
     325  gdata.freeStorage( gdata_p, b1 ) ;
     326  gwgt.freeStorage( gwgt_p, b2 ) ;
     327  t1 = mathutil::gettimeofday_sec() ;
     328  os << "setData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    315329}
    316330
     
    419433  Table taborg( infile_ ) ;
    420434  if ( ifno == -1 ) {
    421     LogIO os( LogOrigin("STGrid","getData",WHERE) ) ;
     435    LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ;
    422436//     os << LogIO::SEVERE
    423437//        << "Please set IFNO before actual gridding"
     
    436450  tab = taborg( node ) ;
    437451  if ( tab.nrow() == 0 ) {
    438     LogIO os( LogOrigin("STGrid","getData",WHERE) ) ;
     452    LogIO os( LogOrigin("STGrid","selectData",WHERE) ) ;
    439453    os << LogIO::SEVERE
    440454       << "No corresponding rows for given selection: IFNO " << ifno
     
    523537                        Matrix<Double> &tint )
    524538{
     539  LogIO os( LogOrigin("STGrid","getWeight",WHERE) ) ;
     540  double t0, t1 ;
     541  t0 = mathutil::gettimeofday_sec() ;
    525542  // resize
    526543  w.resize( nchan_, nrow_ ) ;
    527544
    528545  // set weight
    529   w = 1.0 ;
    530546  Bool warn = False ;
    531547  if ( wtype_.compare( "UNIFORM" ) == 0 ) {
    532     // do nothing
     548    w = 1.0 ;
    533549  }
    534550  else if ( wtype_.compare( "TINT" ) == 0 ) {
     
    536552    for ( Int irow = 0 ; irow < nrow_ ; irow++ ) {
    537553      Float val = mean( tint.column( irow ) ) ;
    538       w.column( irow ) = w.column( irow ) *  val ;
     554      w.column( irow ) = val ;
    539555    }
    540556  }
     
    545561      for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
    546562        Float val = mean( arr.column( ichan ) ) ;
    547         w(ichan,irow) = w(ichan,irow) / ( val * val ) ;
     563        w(ichan,irow) = 1.0 / ( val * val ) ;
    548564      }
    549565    }
     
    556572      for ( Int ichan = 0 ; ichan < nchan_ ; ichan++ ) {
    557573        Float temp = mean( arr.column( ichan ) ) ;
    558         w(ichan,irow) = w(ichan,irow) * interval / ( temp * temp ) ;
     574        w(ichan,irow) = interval / ( temp * temp ) ;
    559575      }
    560576    }
    561577  }
    562578  else {
    563     LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
    564     os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ;
     579    //LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
     580    os << LogIO::WARN << "Unsupported weight type '" << wtype_ << "', apply UNIFORM weight" << LogIO::POST ;
     581    w = 1.0 ;
    565582  }
    566583
    567584  if ( npol_ > 1 ) {
    568     LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
     585    //LogIO os( LogOrigin("STGrid", "getWeight", WHERE) ) ;
    569586    os << LogIO::WARN << "STGrid doesn't support assigning polarization-dependent weight. Use averaged weight over polarization." << LogIO::POST ;
    570587  }
     588  t1 = mathutil::gettimeofday_sec() ;
     589  os << "getWeight: elapsed time is " << t1-t0 << " sec" << LogIO::POST ;
    571590}
    572591
     
    720739string STGrid::saveData( string outfile )
    721740{
     741  LogIO os( LogOrigin("STGrid", "saveData", WHERE) ) ;
     742  double t0, t1 ;
     743  t0 = mathutil::gettimeofday_sec() ;
     744
    722745  //Int polno = 0 ;
    723746  string outfile_ ;
     
    734757    outfile_ = outfile ;
    735758  }
    736   CountedPtr<Scantable> ref( new Scantable( infile_, Table::Memory ) ) ;
     759  CountedPtr<Scantable> ref( new Scantable( infile_, Table::Plain ) ) ;
    737760  //cout << "ref->nchan()=" << ref->nchan() << endl ;
    738761  CountedPtr<Scantable> out( new Scantable( *ref, True ) ) ;
     
    768791  //cout << "outfile_=" << outfile_ << endl ;
    769792  out->makePersistent( outfile_ ) ;
     793
     794  t1 = mathutil::gettimeofday_sec() ;
     795  os << "saveData: elapsed time is " << t1-t0 << " sec." << LogIO::POST ;
    770796 
    771797  return outfile_ ;
  • trunk/src/STGrid.h

    r2364 r2368  
    8181                  Double &ymax,
    8282                  String &center ) ;
     83
     84  void setData( Array<Float> &data,
     85                Array<Float> &gdata,
     86                Array<Float> &gwgt ) ;
    8387 
    8488  void getData( Cube<Float> &spectra,
Note: See TracChangeset for help on using the changeset viewer.