Changeset 2547 for branches


Ignore:
Timestamp:
05/25/12 19:00:18 (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...

Changed an order of iteration for STIdxIter. Now the order is same as
TableIterator? (in specified column list for iteration, iterate subsequent
column first).


Location:
branches/hpc33/src
Files:
2 edited

Legend:

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

    r2537 r2547  
    1616  prod_m.resize( nfield_m ) ;
    1717  idx_m.resize( nfield_m ) ;
    18   prod_m[0] = 1 ;
    19   idx_m[0] = 0 ;
    20   for ( uInt i = 1 ; i < nfield_m ; i++ ) {
    21     prod_m[i] = shape[i-1] * prod_m[i-1] ;
     18//   prod_m[0] = 1 ;
     19//   idx_m[0] = 0 ;
     20//   for ( uInt i = 1 ; i < nfield_m ; i++ ) {
     21//     prod_m[i] = shape[i-1] * prod_m[i-1] ;
     22//     idx_m[i] = 0 ;
     23//   }
     24//   maxiter_m = prod_m[nfield_m-1] * shape[nfield_m-1] ;
     25  prod_m[nfield_m-1] = 1 ;
     26  idx_m[nfield_m-1] = 0 ;
     27  for ( Int i = nfield_m-2 ; i >= 0 ; i-- ) {
     28    prod_m[i] = shape[i+1] * prod_m[i+1] ;
    2229    idx_m[i] = 0 ;
    2330  }
    24   maxiter_m = prod_m[nfield_m-1] * shape[nfield_m-1] ;
     31  maxiter_m = prod_m[0] * shape[0] ;
    2532//   cout << "maxiter_m=" << maxiter_m << endl ;
    2633}
     
    3542  niter_m++ ;
    3643  uInt x = niter_m ;
    37   for ( Int i = nfield_m-1 ; i >= 0 ; i-- ) {
     44//   for ( Int i = nfield_m-1 ; i >= 0 ; i-- ) {
     45  for ( Int i = 0 ; i < nfield_m ; i++ ) {
    3846    idx_m[i] = x / prod_m[i] ;
    3947    //cout << "i=" << i << ": prod=" << prod_m[i]
     
    121129  : ArrayIndexIterator( arr, idlist )
    122130{
     131  // storage_m layout
     132  // length: ncol_m * (nrow_m + 1)
     133  // 0~nrow_m-1: constant temporary storage that indicates whole rows
     134  // nrow_m~2*nrow_m-1: temporary storage for column 0
     135  // 2*nrow_m~3*nrow_m-1: temporary storage for column 1
     136  // ...
    123137  storage_m.resize( arr_m.nelements()+nrow_m ) ;
    124   uInt *p = storage_m.storage() + arr_m.nelements() ;
     138//   uInt *p = storage_m.storage() + arr_m.nelements() ;
     139  uInt *p = storage_m.storage() ;
    125140  for ( uInt i = 0 ; i < nrow_m ; i++ ) {
    126141    *p = i ;
     
    158173  Block<uInt> v = iter_m->current() ;
    159174  Int c = isChanged( v ) ;
    160 //   cout << "c=" << c << endl ;
    161   if ( c < 0 ) {
    162     pos_m[0] = len_m[0] ;
    163     uInt offset = 0 ;
    164     while( offset < ncol_m && skip_m[offset] )
    165       offset++ ;
     175  cout << "v=" << Vector<uInt>(IPosition(1,v.nelements()),v.storage(),SHARE) << endl ;
     176  cout << "c=" << c << endl ;
     177//   if ( c < 0 ) {
     178  if ( c > ncol_m-1 ) {
     179//     pos_m[0] = len_m[0] ;
     180//     uInt offset = 0 ;
     181//     while( offset < ncol_m && skip_m[offset] )
     182//       offset++ ;
     183    pos_m[0] = len_m[ncol_m] ;
     184    Int offset = ncol_m - 1 ;
     185    while( offset >= 0 && skip_m[offset] )
     186      offset-- ;
     187    offset++ ;
    166188//     cout << "offset=" << offset << endl ;
    167189    return Vector<uInt>( pos_m, storage_m.storage()+offset*nrow_m, policy ) ;
    168190  }
    169   Int offset = c + 1 ;
    170   while( offset < ncol_m && skip_m[offset] )
    171     offset++ ;
    172 //   cout << "offset = " << offset << endl ;
     191//   Int offset = c + 1 ;
     192//   while( offset < ncol_m && skip_m[offset] )
     193//     offset++ ;
     194  Int offset = c - 1 ;
     195  while( offset >= 0 && skip_m[offset] )
     196    offset-- ;
     197  offset++ ;
     198  cout << "offset = " << offset << endl ;
    173199  uInt *base = storage_m.storage() + offset * nrow_m ;
    174200//   cout << "len_m[c+1]=" << len_m[c+1] << endl ;
    175201//   cout << "base=" << Vector<uInt>(IPosition(1,len_m[c+1]),base,SHARE) << endl ;
    176   for ( Int i = c ; i >= 0 ; i-- ) {
    177     base = updateStorage( i, base, idxlist_m[i][v[i]] ) ;
    178 //     cout << "len_m[" << i << "]=" << len_m[i] << endl ;
     202//   for ( Int i = c ; i >= 0 ; i-- ) {
     203//     base = updateStorage( i, base, idxlist_m[i][v[i]] ) ;
     204  for ( Int i = c+1 ; i <= ncol_m ; i++ ) {
     205    base = updateStorage( i, base, idxlist_m[i-1][v[i-1]] ) ;
     206    cout << "len_m[" << i << "]=" << len_m[i] << endl ;
    179207//     cout << "base=" << Vector<uInt>(IPosition(1,len_m[i]),base,SHARE) << endl ;
    180208  }
    181   pos_m[0] = len_m[0] ;
     209//   pos_m[0] = len_m[0] ;
     210  pos_m[0] = len_m[ncol_m] ;
    182211//   cout << "pos_m=" << pos_m << endl ;
     212  cout << "ret=" << Vector<uInt>( pos_m, base, policy ) << endl ;
    183213  return Vector<uInt>( pos_m, base, policy ) ;
    184214}
     
    186216Int ArrayIndexIteratorAcc::isChanged( Block<uInt> &idx )
    187217{
    188   Int i = ncol_m - 1 ;
    189   while( i >= 0 && idx[i] == prev_m[i] )
    190     i-- ;
     218//   Int i = ncol_m - 1 ;
     219//   while( i >= 0 && idx[i] == prev_m[i] )
     220//     i-- ;
     221  Int i = 0 ;
     222  while( i < ncol_m && idx[i] == prev_m[i] )
     223    i++ ;
    191224  return i ;
    192225}
     
    197230{
    198231  uInt *p ;
    199   if ( skip_m[icol] ) {
     232//   if ( skip_m[icol] ) {
     233  if ( skip_m[icol-1] ) {
    200234    // skip update, just update len_m[icol] and pass appropriate pointer
    201235//     cout << "skip " << icol << endl ;
    202236    p = base ;
    203     len_m[icol] = len_m[icol+1] ;
     237//     len_m[icol] = len_m[icol+1] ;
     238    len_m[icol] = len_m[icol-1] ;
    204239  }
    205240  else {
     
    212247    long offset = 0 ;
    213248    // warr_p points a first element of (icol)-th column
    214     const uInt *warr_p = arr_p + icol * nrow_m ;
    215     for ( uInt i = 0 ; i < len_m[icol+1] ; i++ ) {
     249//     const uInt *warr_p = arr_p + icol * nrow_m ;
     250    const uInt *warr_p = arr_p + (icol-1) * nrow_m ;
     251//     for ( uInt i = 0 ; i < len_m[icol+1] ; i++ ) {
     252    for ( uInt i = 0 ; i < len_m[icol-1] ; i++ ) {
    216253      // increment warr_p by (*(base)-*(base-1))
    217254      warr_p += *base - offset ;
     
    355392
    356393STIdxIterExAcc::STIdxIterExAcc()
    357   : STIdxIter()
     394  : STIdxIter(),
     395    srctypeid_m( -1 ),
     396    srcnameid_m( -1 )
    358397{
    359398}
     
    361400STIdxIterExAcc::STIdxIterExAcc( const string &name,
    362401                                const vector<string> &cols )
    363   : STIdxIter( name, cols )
     402  : STIdxIter( name, cols ),
     403    srctypeid_m( -1 ),
     404    srcnameid_m( -1 )
    364405{
    365406  Table t( name, Table::Old ) ;
     
    369410STIdxIterExAcc::STIdxIterExAcc( const CountedPtr<Scantable> &s,
    370411                                const vector<string> &cols )
    371   : STIdxIter( s, cols )
     412  : STIdxIter( s, cols ),
     413    srctypeid_m( -1 ),
     414    srcnameid_m( -1 )
    372415{
    373416  init( s->table(), cols ) ;
     
    420463                                    Block<Int> &val )
    421464{
    422   uInt len = in.nelements() ;
    423   Vector<Int> tmp = in.copy() ;
    424   uInt n = genSort( tmp, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates ) ;
    425   val.resize( n ) ;
    426   for ( uInt i = 0 ; i < n ; i++ ) {
    427     val[i] = tmp[i] ;
     465  convertArray( out, in ) ;
     466  //uInt len = in.nelements() ;
     467  //Vector<Int> tmp = in.copy() ;
     468  //uInt n = genSort( tmp, Sort::Ascending, Sort::QuickSort|Sort::NoDuplicates ) ;
     469  //val.resize( n ) ;
     470  //for ( uInt i = 0 ; i < n ; i++ ) {
     471  //  val[i] = tmp[i] ;
    428472//     cout << "val[" << i << "]=" << val[i] << endl ;
    429   }
    430   out.resize( len ) ;
    431   for ( uInt i = 0 ; i < len ; i++ ) {
    432     for ( uInt j = 0 ; j < n ; j++ ) {
    433       if ( in[i] == val[j] ) {
    434         out[i] = j ;
    435         break ;
    436       }
    437     }
    438   }
     473  //}
     474  //out.resize( len ) ;
     475  //uInt idx = -1 ;
     476  //cout << "idx=" << idx << endl ;
     477  //int idx2 = (Int)idx ;
     478  //cout << "idx2=" << idx2 << endl ;
     479  //idx = (uInt) idx2 ;
     480  //cout << "idx=" << idx << endl ;
     481  //if ( n == 1 ) {
     482  //  cout << "n=1" << endl ;
     483  //  out = 0 ;
     484  //}
     485  //else if ( n == 2 ) {
     486  //  cout << "n=2" << endl ;
     487  //  for ( uInt i = 0 ; i < len ; i++ ) {
     488  //    out[i] = (in[i] == val[0]) ? 0 : 1 ;
     489  //  }
     490  //}
     491  //else {
     492  //  cout << "n=" << n << endl ;
     493  //  map<Int,uInt> m ;
     494  // for( uInt i = 0 ; i < n ; i++ )
     495  //    m[val[i]] = i ;
     496  // for ( uInt i = 0 ; i < len ; i++ ) {
     497     //for ( uInt j = 0 ; j < n ; j++ ) {
     498      //  if ( in[i] == val[j] ) {
     499      //    out[i] = j ;
     500      //    break ;
     501      //  }
     502      //}
     503  //    out[i] = m[in[i]] ;
     504  //  }
     505  // }
    439506}
    440507
     
    451518//     cout << "val[" << i << "]=" << val[i] << endl ;
    452519  }
    453   out.resize( len ) ;
    454   for ( uInt i = 0 ; i < len ; i++ ) {
    455     for ( uInt j = 0 ; j < n ; j++ ) {
    456       if ( in[i] == val[j] ) {
    457         out[i] = j ;
    458         break ;
    459       }
     520  //out.resize( len ) ;
     521  if ( n == 1 ) {
     522    //cout << "n=1" << endl ;
     523    out = 0 ;
     524  }
     525  else if ( n == 2 ) {
     526    //cout << "n=2" << endl ;
     527    for ( uInt i = 0 ; i < len ; i++ ) {
     528      out[i] = (in[i] == val[0]) ? 0 : 1 ;
     529    }
     530  }
     531  else {
     532    //cout << "n=" << n << endl ;
     533    map<String,uInt> m ;
     534    for ( uInt i = 0 ; i < n ; i++ )
     535      m[val[i]] = i ;
     536    for ( uInt i = 0 ; i < len ; i++ ) {
     537      //for ( uInt j = 0 ; j < n ; j++ ) {
     538      //  if ( in[i] == val[j] ) {
     539      //    out[i] = j ;
     540      //    break ;
     541      //  }
     542      //}
     543      out[i] = m[in[i]] ;
    460544    }
    461545  }
     
    464548Int STIdxIterExAcc::getSrcType()
    465549{
    466   if ( srctype_m.nelements() > 0 )
    467     return srctype_m[iter_m->current()[srctypeid_m]] ;
     550  //if ( srctype_m.nelements() > 0 )
     551  if ( srctypeid_m >= 0 )
     552    //return srctype_m[iter_m->current()[srctypeid_m]] ;
     553    return (Int)(iter_m->current()[srctypeid_m]) ;
    468554  else
    469555    return -999 ;
  • branches/hpc33/src/STIdxIter.h

    r2537 r2547  
    151151  Block<Int> srctype_m ;
    152152  Block<String> srcname_m ;
    153   uInt srctypeid_m ;
    154   uInt srcnameid_m ;
     153  Int srctypeid_m ;
     154  Int srcnameid_m ;
    155155} ;
    156156
Note: See TracChangeset for help on using the changeset viewer.