Changeset 2536
- Timestamp:
- 05/18/12 17:50:11 (13 years ago)
- Location:
- branches/hpc33/src
- Files:
-
- 2 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 } -
branches/hpc33/src/STIdxIter.h
r2533 r2536 57 57 void next() ; 58 58 Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ; 59 // private:60 // Block<uInt> storage_m ;61 // IPosition pos_m ;62 59 } ; 63 60 … … 70 67 Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ; 71 68 private: 72 Int isChanged( Vector<uInt> &idx ) ;69 Int isChanged( Block<uInt> &idx ) ; 73 70 uInt *updateStorage( Int &icol, uInt *base, uInt &v ) ; 74 71 75 Vector<uInt> prev_m ; 76 // Block<uInt> storage_m ; 77 // IPosition pos_m ; 72 Block<uInt> prev_m ; 78 73 Block<uInt> len_m ; 74 Block<Bool> skip_m ; 79 75 } ; 80 76 … … 93 89 void next() { iter_m->next() ; } ; 94 90 vector<uInt> getRowsSTL() { return tovector( iter_m->getRows() ) ; } ; 91 // !!!you should not use policy=TAKE_OVER since it causes problem!!! 95 92 Vector<uInt> getRows( StorageInitPolicy policy=COPY ) ; 96 93 protected: … … 107 104 STIdxIterNormal() ; 108 105 STIdxIterNormal( const string &name, 109 106 const vector<string> &cols ) ; 110 107 STIdxIterNormal( const CountedPtr<Scantable> &s, 111 108 const vector<string> &cols ) ; 112 109 ~STIdxIterNormal() ; 113 110 protected: … … 121 118 STIdxIterAcc() ; 122 119 STIdxIterAcc( const string &name, 123 120 const vector<string> &cols ) ; 124 121 STIdxIterAcc( const CountedPtr<Scantable> &s, 125 122 const vector<string> &cols ) ; 126 123 ~STIdxIterAcc() ; 127 124 protected: 128 v oid init( Table &t,129 const vector<string> &cols ) ;125 virtual void init( Table &t, 126 const vector<string> &cols ) ; 130 127 } ; 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 // } ; 131 141 132 142 } // namespace
Note:
See TracChangeset
for help on using the changeset viewer.