[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: subscript array question





Tom McGlynn <tam@silk.gsfc.nasa.gov> writes:
> 
> This kind of thing comes up in a number of contexts, e.g., the
> thread a couple of months ago for calculating cumulative totals
> in arrays.  The solution I've suggested to RSI is a new equality
> operator (e.g., :=) which does not implicitly parallelize
> array operations.
> 
> In this case one could just write
> 
>     array[subs] := array[subs]+1
> 
> in a very natural way rather than use devious if clever subterfuges.
> 

Yorick, which is very IDL-like, has some pretty handy ideas in it.
While it doesn't consider your "anti-parallel" equality operator, it
does have operators that *attach* to array subscripts and do most of
the things you might want.  Consider that there is no nicely
vectorized function in IDL which computes the cumulative total of "x"
in IDL.  In Yorick, you would say:

y = x(cum)

Here "cum" is a special function which operates on a dimension of the
array, and cranks out the cumulative total for you.  Thus for example,

y = x(dif)   is the finite difference between elements of x
             (this is something I wish I had all the time!)

There are also "rank-reducing" functions which remove one dimension of
the array.  Thus,

y = x(sum)   is the same as y = total(x) in IDL,
y = x(max)   is the same as y = max(x), etc.

Whis is this nice?  Sometimes you want to get the maximum along only a
certain dimension.  To get the maximum in each row of an array, you
might try:

y = x(max,*)  which has no equivalent in IDL

As I say, I find myself wishing for a lot of these features almost
daily.  IDL could become a whole lot more vector-friendly with
them. The RSI people could take some lessons from Yorick.

Craig

-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL: craigmnet@astrog.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------