Changeset 2536 for branches/hpc33/src/STIdxIter.cpp
- Timestamp:
- 05/18/12 17:50:11 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/hpc33/src/STIdxIter.cpp
r2533 r2536 14 14 { 15 15 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 ; 18 20 for ( uInt i = 1 ; i < nfield_m ; i++ ) { 19 21 prod_m[i] = shape[i-1] * prod_m[i-1] ; 22 idx_m[i] = 0 ; 20 23 } 21 24 maxiter_m = prod_m[nfield_m-1] * shape[nfield_m-1] ; … … 43 46 vector< vector<uInt> > idlist ) 44 47 : arr_m( arr ), 45 pos_m( IPosition(1,0))48 pos_m( 1 ) 46 49 { 47 50 ncol_m = arr_m.ncolumn() ; … … 62 65 shape[i] = idxlist_m[i].size() ; 63 66 } 67 // cout << "shape=" << shape << endl ; 64 68 iter_m = new IndexIterator( shape ) ; 65 69 current_m.resize( ncol_m ) ; … … 118 122 { 119 123 storage_m.resize( arr_m.nelements()+nrow_m ) ; 124 uInt *p = storage_m.storage() + arr_m.nelements() ; 120 125 for ( uInt i = 0 ; i < nrow_m ; i++ ) { 121 storage_m[i+arr_m.nelements()] = i ; 126 *p = i ; 127 p++ ; 122 128 } 123 129 len_m.resize( ncol_m+1 ) ; 130 p = len_m.storage() ; 124 131 for ( uInt i = 0 ; i < ncol_m+1 ; i++ ) { 125 len_m[i] = nrow_m ; 132 *p = nrow_m ; 133 p++ ; 126 134 // cout << "len[" << i << "]=" << len_m[i] << endl ; 127 135 } 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 } 129 148 } 130 149 131 150 void ArrayIndexIteratorAcc::next() 132 151 { 133 prev_m = current() ;152 prev_m = iter_m->current() ; 134 153 iter_m->next() ; 135 154 } … … 137 156 Vector<uInt> ArrayIndexIteratorAcc::getRows( StorageInitPolicy policy ) 138 157 { 139 Vector<uInt> v =current() ;158 Block<uInt> v = iter_m->current() ; 140 159 Int c = isChanged( v ) ; 141 160 // cout << "c=" << c << endl ; 142 161 if ( c < 0 ) { 143 162 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 ) ; 145 168 } 146 169 uInt *base = storage_m.storage() + (c+1) * nrow_m ; … … 148 171 // cout << "base=" << Vector<uInt>(IPosition(1,len_m[c+1]),base,SHARE) << endl ; 149 172 for ( Int i = c ; i >= 0 ; i-- ) { 150 base = updateStorage( i, base, v[i] ) ;173 base = updateStorage( i, base, idxlist_m[i][v[i]] ) ; 151 174 // cout << "len_m[" << i << "]=" << len_m[i] << endl ; 152 175 // cout << "base=" << Vector<uInt>(IPosition(1,len_m[i]),base,SHARE) << endl ; 153 176 } 154 177 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 181 Int ArrayIndexIteratorAcc::isChanged( Block<uInt> &idx ) 159 182 { 160 183 Int i = ncol_m - 1 ; … … 168 191 uInt &v ) 169 192 { 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++ ; 179 224 } 180 base++;181 }182 len_m[icol] = len ;225 arr_m.freeStorage( arr_p, b ) ; 226 len_m[icol] = len ; 227 } 183 228 return p ; 184 229 } … … 248 293 Matrix<uInt> arr( nrow, ncol ) ; 249 294 ROScalarColumn<uInt> col ; 295 Vector<uInt> v ; 250 296 for ( uInt i = 0 ; i < ncol ; i++ ) { 251 297 col.attach( t, cols[i] ) ; 252 Vector<uInt> v( arr.column( i ) ) ;298 v.reference( arr.column( i ) ) ; 253 299 col.getColumn( v ) ; 254 300 } … … 285 331 uInt ncol = cols.size() ; 286 332 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] 287 339 Matrix<uInt> arr( nrow, ncol ) ; 340 Vector<uInt> v ; 288 341 ROScalarColumn<uInt> col ; 289 342 for ( uInt i = 0 ; i < ncol ; i++ ) { 290 343 col.attach( t, cols[i] ) ; 291 Vector<uInt> v( arr.column( i ) ) ;344 v.reference( arr.column( i ) ) ; 292 345 col.getColumn( v ) ; 293 346 }
Note: See TracChangeset
for help on using the changeset viewer.