Changeset 114 for trunk/SRC/ToBeReviewed/MATRICE/cmset_op.pro
- Timestamp:
- 06/19/06 16:14:56 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/ToBeReviewed/MATRICE/cmset_op.pro
r84 r114 154 154 ; if keyword_set(sortit) then begin 155 155 ; ;; Sort it manually 156 ; ii = sort(a) & b = a (ii)156 ; ii = sort(a) & b = a[ii] 157 157 ; if keyword_set(non) then wh = where(b EQ shift(b, sh), ct) $ 158 158 ; else wh = where(b NE shift(b, sh), ct) 159 ; if ct GT 0 then return, ii (wh)159 ; if ct GT 0 then return, ii[wh] 160 160 ; endif else begin 161 161 ; ;; Use the user's values directly … … 171 171 ;; "first" value, whatever that may mean. 172 172 function cmset_op_uniq, a 173 ; 174 compile_opt idl2, strictarrsubs 175 ; 173 176 if n_elements(a) LE 1 then return, 0L 174 177 175 ii = sort(a) & b = a (ii)178 ii = sort(a) & b = a[ii] 176 179 wh = where(b NE shift(b, +1L), ct) 177 if ct GT 0 then return, ii (wh)180 if ct GT 0 then return, ii[wh] 178 181 179 182 return, 0L … … 182 185 function cmset_op, a, op0, b, not1=not1, not2=not2, count=count, $ 183 186 empty1=empty1, empty2=empty2, maxarray=ma, index=index 187 ; 188 compile_opt idl2, strictarrsubs 189 ; 184 190 185 191 on_error, 2 ;; return on error … … 204 210 ;; Check the operation 205 211 sz = size(op0) 206 if sz (sz(0)+1)NE 7 then begin212 if sz[sz[0]+1] NE 7 then begin 207 213 OP_ERR: 208 214 message, "ERROR: OP must be 'AND', 'OR' or 'XOR'" … … 247 253 if count GT 0 then return, a1 else return, -1L 248 254 endif 249 if count GT 0 then return, a (a1)else return, -1L255 if count GT 0 then return, a[a1] else return, -1L 250 256 RET_B1: 251 257 count = n2 … … 253 259 if count GT 0 then return, b1+n1 else return, -1L 254 260 endif 255 if count GT 0 then return, b (b1)else return, -1L261 if count GT 0 then return, b[b1] else return, -1L 256 262 endif 257 263 … … 266 272 267 273 ;; Check types of operands 268 sz1 = size(a) & tp1 = sz1 (sz1(0)+1)269 sz2 = size(b) & tp2 = sz2 (sz2(0)+1)274 sz1 = size(a) & tp1 = sz1[sz1[0]+1] 275 sz2 = size(b) & tp2 = sz2[sz2[0]+1] 270 276 if tp1 LT 0 OR tp1 GE 16 OR tp2 LT 0 OR tp2 GE 16 then begin 271 277 message, 'ERROR: unrecognized data types for operands' 272 278 return, -1 273 279 endif 274 if basetype (tp1) NE basetype(tp2)then begin280 if basetype[tp1] NE basetype[tp2] then begin 275 281 TYPE1_ERR: 276 282 message, 'ERROR: both A and B must be of the same type' … … 297 303 count = n_elements(index0) 298 304 if kind then return, index0 299 return, uu (index0)305 return, uu[index0] 300 306 end 301 307 … … 305 311 bi = cmset_op_uniq(b) & nb = n_elements(bi) 306 312 ui = [ai, bi+n1] 307 uu = [a,b] & uu = uu (ui);; Raw union...308 us = sort(uu) & uu = uu (us);; ...and sort309 if kind then ui = ui (temporary(us))else ui = 0313 uu = [a,b] & uu = uu[ui] ;; Raw union... 314 us = sort(uu) & uu = uu[us] ;; ...and sort 315 if kind then ui = ui[temporary(us)] else ui = 0 310 316 311 317 ;; Values in one set only will not have duplicates 312 318 wh1 = where(uu NE shift(uu, -1), count1) 313 319 if count1 EQ 0 then return, -1L 314 wh = where(wh1 (1:*)-wh1 EQ 1, count)315 if wh1 (0)EQ 0 then begin320 wh = where(wh1[1:*]-wh1 EQ 1, count) 321 if wh1[0] EQ 0 then begin 316 322 if count GT 0 then wh = [-1L, wh] else wh = [-1L] 317 323 count = n_elements(wh) 318 324 endif 319 325 if count EQ 0 then return, -1 320 if kind then return, ui (wh1(wh+1))321 return, uu (wh1(wh+1))326 if kind then return, ui[wh1[wh+1]] 327 return, uu[wh1[wh+1]] 322 328 end 323 329 … … 327 333 bi = cmset_op_uniq(b) & nb = n_elements(bi) 328 334 ui = [ai, bi+n1] 329 uu = [a,b] & uu = uu (ui);; Raw union...330 us = sort(uu) & uu = uu (us);; ...and sort331 if kind then ui = ui (us)else ui = 0335 uu = [a,b] & uu = uu[ui] ;; Raw union... 336 us = sort(uu) & uu = uu[us] ;; ...and sort 337 if kind then ui = ui[us] else ui = 0 332 338 333 339 if NOT keyword_set(not1) AND NOT keyword_set(not2) then begin … … 336 342 ;; they are equal, then the SHIFT() technique below 337 343 ;; fails. Do this one by hand. 338 if na EQ 1 AND nb EQ 1 AND uu (0) EQ uu(1)then begin344 if na EQ 1 AND nb EQ 1 AND uu[0] EQ uu[1] then begin 339 345 count = 1L 340 346 if kind then return, 0L 341 return, [uu (0)]347 return, [uu[0]] 342 348 endif 343 349 … … 348 354 ;; This should always select the element from A 349 355 ;; rather than B (the smaller of the two) 350 if kind then return, (ui (wh) < ui(wh+1))351 return, uu (wh)356 if kind then return, (ui[wh] < ui[wh+1]) 357 return, uu[wh] 352 358 endif 353 359 354 360 ;; For "NOT" cases, we need to identify by set 355 361 ii = make_array(na+nb, value=1b) 356 if keyword_set(not1) then ii (0:na-1)= 0357 if keyword_set(not2) then ii (na:*)= 0358 ii = ii (temporary(us))362 if keyword_set(not1) then ii[0:na-1] = 0 363 if keyword_set(not2) then ii[na:*] = 0 364 ii = ii[temporary(us)] 359 365 360 366 ;; Remove any duplicates 361 367 wh1 = where(uu EQ shift(uu, -1L), count1) ;; Find non-unique 362 if count1 GT 0 then ii ([wh1, wh1+1])= 0368 if count1 GT 0 then ii[wh1, wh1+1] = 0 363 369 ;; Remainder is the desired set 364 370 wh = where(ii, count) 365 371 if count EQ 0 then return, -1L 366 if kind then return, ui (wh)367 return, uu (wh)372 if kind then return, ui[wh] 373 return, uu[wh] 368 374 end 369 375 … … 380 386 minn = min1 < min2 & maxx = max1 > max2 381 387 nbins = maxx-minn+1 382 if (maxx-minn) GT floor(ma (0)) then goto, SLOW_SET_OP388 if (maxx-minn) GT floor(ma[0]) then goto, SLOW_SET_OP 383 389 384 390 ;; Work around a stupidity in the built-in IDL HISTOGRAM routine … … 405 411 result = temporary(wh+minn) 406 412 if tp1 NE tp2 then return, result 407 szr = size(result) & tpr = szr (szr(0)+1)413 szr = size(result) & tpr = szr[szr[0]+1] 408 414 409 415 ;; Cast to the original type if necessary 410 416 if tpr NE tp1 then begin 411 417 fresult = make_array(n_elements(result), type=tp1) 412 fresult (0)= temporary(result)418 fresult[0] = temporary(result) 413 419 result = temporary(fresult) 414 420 endif … … 424 430 ; works, but is complicated, so I forced it to go to SLOW_SET_OP. 425 431 ; ha = histogram(a, min=minn, max=maxx, reverse=ra) < 1 426 ; rr = ra (0:nbins) & mask = rr NE rr(1:*) & ra = ra(rr)*mask-1L+mask432 ; rr = ra[0:nbins] & mask = rr NE rr[1:*] & ra = ra[rr]*mask-1L+mask 427 433 ; hb = histogram(b, min=minn, max=maxx, reverse=rb) < 1 428 ; rr = rb (0:nbins) & mask = rr NE rr(1:*) & rb = rb(rr)*mask-1L+mask434 ; rr = rb[0:nbins] & mask = rr NE rr[1:*] & rb = rb[rr]*mask-1L+mask 429 435 ; ... AND/OR/XOR NOT masking here ... 430 ; ra = ra (wh) & rb = rb(wh)436 ; ra = ra[wh] & rb = rb[wh] 431 437 ; return, ra*(ra GE 0) + (rb+n1)*(ra LT 0) ;; is last 'ra' right? 432 438
Note: See TracChangeset
for help on using the changeset viewer.