Changeset 2547
- Timestamp:
- 05/25/12 19:00:18 (13 years ago)
- Location:
- branches/hpc33/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/hpc33/src/STIdxIter.cpp
r2537 r2547 16 16 prod_m.resize( nfield_m ) ; 17 17 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] ; 22 29 idx_m[i] = 0 ; 23 30 } 24 maxiter_m = prod_m[ nfield_m-1] * shape[nfield_m-1] ;31 maxiter_m = prod_m[0] * shape[0] ; 25 32 // cout << "maxiter_m=" << maxiter_m << endl ; 26 33 } … … 35 42 niter_m++ ; 36 43 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++ ) { 38 46 idx_m[i] = x / prod_m[i] ; 39 47 //cout << "i=" << i << ": prod=" << prod_m[i] … … 121 129 : ArrayIndexIterator( arr, idlist ) 122 130 { 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 // ... 123 137 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() ; 125 140 for ( uInt i = 0 ; i < nrow_m ; i++ ) { 126 141 *p = i ; … … 158 173 Block<uInt> v = iter_m->current() ; 159 174 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++ ; 166 188 // cout << "offset=" << offset << endl ; 167 189 return Vector<uInt>( pos_m, storage_m.storage()+offset*nrow_m, policy ) ; 168 190 } 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 ; 173 199 uInt *base = storage_m.storage() + offset * nrow_m ; 174 200 // cout << "len_m[c+1]=" << len_m[c+1] << endl ; 175 201 // 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 ; 179 207 // cout << "base=" << Vector<uInt>(IPosition(1,len_m[i]),base,SHARE) << endl ; 180 208 } 181 pos_m[0] = len_m[0] ; 209 // pos_m[0] = len_m[0] ; 210 pos_m[0] = len_m[ncol_m] ; 182 211 // cout << "pos_m=" << pos_m << endl ; 212 cout << "ret=" << Vector<uInt>( pos_m, base, policy ) << endl ; 183 213 return Vector<uInt>( pos_m, base, policy ) ; 184 214 } … … 186 216 Int ArrayIndexIteratorAcc::isChanged( Block<uInt> &idx ) 187 217 { 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++ ; 191 224 return i ; 192 225 } … … 197 230 { 198 231 uInt *p ; 199 if ( skip_m[icol] ) { 232 // if ( skip_m[icol] ) { 233 if ( skip_m[icol-1] ) { 200 234 // skip update, just update len_m[icol] and pass appropriate pointer 201 235 // cout << "skip " << icol << endl ; 202 236 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] ; 204 239 } 205 240 else { … … 212 247 long offset = 0 ; 213 248 // 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++ ) { 216 253 // increment warr_p by (*(base)-*(base-1)) 217 254 warr_p += *base - offset ; … … 355 392 356 393 STIdxIterExAcc::STIdxIterExAcc() 357 : STIdxIter() 394 : STIdxIter(), 395 srctypeid_m( -1 ), 396 srcnameid_m( -1 ) 358 397 { 359 398 } … … 361 400 STIdxIterExAcc::STIdxIterExAcc( const string &name, 362 401 const vector<string> &cols ) 363 : STIdxIter( name, cols ) 402 : STIdxIter( name, cols ), 403 srctypeid_m( -1 ), 404 srcnameid_m( -1 ) 364 405 { 365 406 Table t( name, Table::Old ) ; … … 369 410 STIdxIterExAcc::STIdxIterExAcc( const CountedPtr<Scantable> &s, 370 411 const vector<string> &cols ) 371 : STIdxIter( s, cols ) 412 : STIdxIter( s, cols ), 413 srctypeid_m( -1 ), 414 srcnameid_m( -1 ) 372 415 { 373 416 init( s->table(), cols ) ; … … 420 463 Block<Int> &val ) 421 464 { 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] ; 428 472 // 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 // } 439 506 } 440 507 … … 451 518 // cout << "val[" << i << "]=" << val[i] << endl ; 452 519 } 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]] ; 460 544 } 461 545 } … … 464 548 Int STIdxIterExAcc::getSrcType() 465 549 { 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]) ; 468 554 else 469 555 return -999 ; -
branches/hpc33/src/STIdxIter.h
r2537 r2547 151 151 Block<Int> srctype_m ; 152 152 Block<String> srcname_m ; 153 uInt srctypeid_m ;154 uInt srcnameid_m ;153 Int srctypeid_m ; 154 Int srcnameid_m ; 155 155 } ; 156 156
Note:
See TracChangeset
for help on using the changeset viewer.