Changeset 2536 for branches


Ignore:
Timestamp:
05/18/12 17:50:11 (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...

Minor speedup that STIdxIterAcc skips to update internal storage and
just update data length and pointer when specified column has only
one value.


Location:
branches/hpc33/src
Files:
2 edited

Legend:

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

    r2533 r2536  
    1414{
    1515  nfield_m = shape.nelements() ;
    16   prod_m = Block<uInt>( nfield_m, 1 ) ;
    17   idx_m = Block<uInt>( nfield_m, 0 ) ;
     16  prod_m.resize( nfield_m ) ;
     17  idx_m.resize( nfield_m ) ;
     18  prod_m[0] = 1 ;
     19  idx_m[0] = 0 ;
    1820  for ( uInt i = 1 ; i < nfield_m ; i++ ) {
    1921    prod_m[i] = shape[i-1] * prod_m[i-1] ;
     22    idx_m[i] = 0 ;
    2023  }
    2124  maxiter_m = prod_m[nfield_m-1] * shape[nfield_m-1] ;
     
    4346                                        vector< vector<uInt> > idlist )
    4447  : arr_m( arr ),
    45     pos_m( IPosition(1,0) )
     48    pos_m( 1 )
    4649{
    4750  ncol_m = arr_m.ncolumn() ;
     
    6265    shape[i] = idxlist_m[i].size() ;
    6366  }
     67//   cout << "shape=" << shape << endl ;
    6468  iter_m = new IndexIterator( shape ) ;
    6569  current_m.resize( ncol_m ) ;
     
    118122{
    119123  storage_m.resize( arr_m.nelements()+nrow_m ) ;
     124  uInt *p = storage_m.storage() + arr_m.nelements() ;
    120125  for ( uInt i = 0 ; i < nrow_m ; i++ ) {
    121     storage_m[i+arr_m.nelements()] = i ;
     126    *p = i ;
     127    p++ ;
    122128  }
    123129  len_m.resize( ncol_m+1 ) ;
     130  p = len_m.storage() ;
    124131  for ( uInt i = 0 ; i < ncol_m+1 ; i++ ) {
    125     len_m[i] = nrow_m ;
     132    *p = nrow_m ;
     133    p++ ;
    126134//     cout << "len[" << i << "]=" << len_m[i] << endl ;
    127135  }
    128   prev_m = current() - (uInt)1 ;
     136  prev_m = iter_m->current() ;
     137  p = prev_m.storage() ;
     138  for ( uInt i = 0 ; i < ncol_m ; i++ ) {
     139    *p = *p - 1 ;
     140    p++ ;
     141  }
     142//   cout << "prev_m=" << Vector<uInt>(IPosition(1,ncol_m),prev_m.storage()) << endl ;
     143  skip_m.resize( ncol_m ) ;
     144  for ( uInt i = 0 ; i < ncol_m ; i++ ) {
     145    skip_m[i] = (Bool)(idxlist_m[i].size()==1) ;
     146//     cout << "skip_m[" << i << "]=" << skip_m[i] << endl ;
     147  }
    129148}
    130149
    131150void ArrayIndexIteratorAcc::next()
    132151{
    133   prev_m = current() ;
     152  prev_m = iter_m->current() ;
    134153  iter_m->next() ;
    135154}
     
    137156Vector<uInt> ArrayIndexIteratorAcc::getRows( StorageInitPolicy policy )
    138157{
    139   Vector<uInt> v = current() ;
     158  Block<uInt> v = iter_m->current() ;
    140159  Int c = isChanged( v ) ;
    141160//   cout << "c=" << c << endl ;
    142161  if ( c < 0 ) {
    143162    pos_m[0] = len_m[0] ;
    144     return Vector<uInt>( pos_m, storage_m.storage(), policy ) ;
     163    uInt offset = 0 ;
     164    while( offset <= ncol_m && !(skip_m[offset]) )
     165      offset++ ;
     166//     cout << "offset=" << offset << endl ;
     167    return Vector<uInt>( pos_m, storage_m.storage()+offset*nrow_m, policy ) ;
    145168  }
    146169  uInt *base = storage_m.storage() + (c+1) * nrow_m ;
     
    148171//   cout << "base=" << Vector<uInt>(IPosition(1,len_m[c+1]),base,SHARE) << endl ;
    149172  for ( Int i = c ; i >= 0 ; i-- ) {
    150     base = updateStorage( i, base, v[i] ) ;
     173    base = updateStorage( i, base, idxlist_m[i][v[i]] ) ;
    151174//     cout << "len_m[" << i << "]=" << len_m[i] << endl ;
    152175//     cout << "base=" << Vector<uInt>(IPosition(1,len_m[i]),base,SHARE) << endl ;
    153176  }
    154177  pos_m[0] = len_m[0] ;
    155   return Vector<uInt>( pos_m, storage_m.storage(), policy ) ;
    156 }
    157 
    158 Int ArrayIndexIteratorAcc::isChanged( Vector<uInt> &idx )
     178  return Vector<uInt>( pos_m, base, policy ) ;
     179}
     180
     181Int ArrayIndexIteratorAcc::isChanged( Block<uInt> &idx )
    159182{
    160183  Int i = ncol_m - 1 ;
     
    168191                                            uInt &v )
    169192{
    170   uInt len = 0 ;
    171   uInt *p = base - nrow_m ;
    172   uInt *work = p ;
    173   for ( uInt i = 0 ; i < len_m[icol+1] ; i++ ) {
    174     if ( arr_m( *base, icol ) == v ) {
    175 //       cout << "add " << *base << endl ;
    176       *work = *base ;
    177       len++ ;
    178       work++ ;
     193  uInt *p ;
     194  if ( skip_m[icol] ) {
     195    // skip update, just update len_m[icol] and pass appropriate pointer
     196//     cout << "skip " << icol << endl ;
     197    p = base ;
     198    len_m[icol] = len_m[icol+1] ;
     199  }
     200  else {
     201    uInt len = 0 ;
     202    p = storage_m.storage() + icol * nrow_m ;
     203    uInt *work = p ;
     204    Bool b ;
     205    const uInt *arr_p = arr_m.getStorage( b ) ;
     206    long offset = 0 ;
     207    // warr_p points a first element of (icol)-th column
     208    const uInt *warr_p = arr_p + icol * nrow_m ;
     209    for ( uInt i = 0 ; i < len_m[icol+1] ; i++ ) {
     210      // increment warr_p by (*(base)-*(base-1))
     211      warr_p += *base - offset ;
     212      // check if target element is equal to value specified
     213      if ( *warr_p == v ) {
     214        // then, add current index to storage_m
     215        //       cout << "add " << *base << endl ;
     216        *work = *base ;
     217        len++ ;
     218        work++ ;
     219      }
     220      // update offset
     221      offset = *base ;
     222      // next index
     223      base++ ;
    179224    }
    180     base++ ;
    181   }
    182   len_m[icol] = len ;
     225    arr_m.freeStorage( arr_p, b ) ;
     226    len_m[icol] = len ;
     227  }
    183228  return p ;
    184229}
     
    248293  Matrix<uInt> arr( nrow, ncol ) ;
    249294  ROScalarColumn<uInt> col ;
     295  Vector<uInt> v ;
    250296  for ( uInt i = 0 ; i < ncol ; i++ ) {
    251297    col.attach( t, cols[i] ) ;
    252     Vector<uInt> v( arr.column( i ) ) ;
     298    v.reference( arr.column( i ) ) ;
    253299    col.getColumn( v ) ;
    254300  }
     
    285331  uInt ncol = cols.size() ;
    286332  uInt nrow = t.nrow() ;
     333  // array shape here is as follows if cols=["BEAMNO","POLNO","IFNO"]:
     334  // [[B0,B1,B2,...,BN],
     335  //  [P0,P1,P2,...,PN],
     336  //  [I0,I1,I2,...,IN]]
     337  // order of internal storage is
     338  // [B0,B1,B2,..,BN,P0,P1,P2,...,PN,I0,I1,I2,...,IN]
    287339  Matrix<uInt> arr( nrow, ncol ) ;
     340  Vector<uInt> v ;
    288341  ROScalarColumn<uInt> col ;
    289342  for ( uInt i = 0 ; i < ncol ; i++ ) {
    290343    col.attach( t, cols[i] ) ;
    291     Vector<uInt> v( arr.column( i ) ) ;
     344    v.reference( arr.column( i ) ) ;
    292345    col.getColumn( v ) ;
    293346  }
  • branches/hpc33/src/STIdxIter.h

    r2533 r2536  
    5757  void next() ;
    5858  Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
    59 // private:
    60 //   Block<uInt> storage_m ;
    61 //   IPosition pos_m ;
    6259} ;
    6360
     
    7067  Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
    7168private:
    72   Int isChanged( Vector<uInt> &idx ) ;
     69  Int isChanged( Block<uInt> &idx ) ;
    7370  uInt *updateStorage( Int &icol, uInt *base, uInt &v ) ;
    7471
    75   Vector<uInt> prev_m ;
    76 //   Block<uInt> storage_m ;
    77 //   IPosition pos_m ;
     72  Block<uInt> prev_m ;
    7873  Block<uInt> len_m ;
     74  Block<Bool> skip_m ;
    7975} ;
    8076
     
    9389  void next() { iter_m->next() ; } ;
    9490  vector<uInt> getRowsSTL() { return tovector( iter_m->getRows() ) ; } ;
     91  // !!!you should not use policy=TAKE_OVER since it causes problem!!!
    9592  Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ;
    9693protected:
     
    107104  STIdxIterNormal() ;
    108105  STIdxIterNormal( const string &name,
    109                                 const vector<string> &cols ) ;
     106                   const vector<string> &cols ) ;
    110107  STIdxIterNormal( const CountedPtr<Scantable> &s,
    111                                 const vector<string> &cols ) ;
     108                   const vector<string> &cols ) ;
    112109  ~STIdxIterNormal() ;
    113110protected:
     
    121118  STIdxIterAcc() ;
    122119  STIdxIterAcc( const string &name,
    123                              const vector<string> &cols ) ;
     120                const vector<string> &cols ) ;
    124121  STIdxIterAcc( const CountedPtr<Scantable> &s,
    125                              const vector<string> &cols ) ;
     122                const vector<string> &cols ) ;
    126123  ~STIdxIterAcc() ;
    127124protected:
    128   void init( Table &t,
    129              const vector<string> &cols ) ;
     125  virtual void init( Table &t,
     126                     const vector<string> &cols ) ;
    130127} ;
     128
     129// class STIdxIterExAcc : public STIdxIterAcc
     130// {
     131//   STIdxIterExAcc() ;
     132//   STIdxIterExAcc( const string &name,
     133//                   const vector<string> &cols ) ;
     134//   STIdxIterExAcc( const CountedPtr<Scantable> &s,
     135//                   const vector<string> &cols ) ;
     136//   ~STIdxIterExAcc() ;
     137// protected:
     138//   virtual void init( Table &t,
     139//                      const vector<string> &cols ) ;
     140// } ;
    131141
    132142} // namespace
Note: See TracChangeset for help on using the changeset viewer.