[Matrix-SIG] QUERY: Array indexing

Frank Horowitz frank@ned.dem.csiro.au
Thu, 11 Mar 1999 14:46:01 +0800


At 10:29 AM +0800 11/3/99, Perry Stoll wrote:
>And from the incomparable Tim Peters, here's a lesson on gather/scatter in
>general (sorry if this link gets broken up across two lines):
>
>http://x9.dejanews.com/[ST_rn=ps]/getdoc.xp?AN=227662160&CONTEXT=921108267.1
>22880047&hitnum=3:
>
>which yields the following functions:
>
>def gather(seq, indices):
>    from operator import __getitem__
>    return map(__getitem__, (seq,)*len(indices), indices)
>
>def scatter(seq, indices,vals):
>    from operator import __setitem__
>    return map(__setitem__, (seq,)*len(indices), indices,vals)
>

Thanks for that "incomparable Tim Peters" citation; that's a fascinating
thread (have I sucked up enough yet? :-).

My applications require local references in the array (somewhat akin to
finite difference/convolution templates) but the operations I need to
perform are more general than multiply-and-sum, hence I can't use the
recent n-d convolve routines from Travis Oliphant (or was it someone else;
senility is obviously setting in...)

My approach to date has been to build shifted/rolled versions of the array,
and operate with them (code available upon request, if anyone is silly
enough to want it :-).  Obviously, this comes at a severe cost in memory
(hey! I'm trying to do this in 3d with ~2k X ~2k base images, and a couple
of "+/- Z" steps for the image, computable from theory).  As you might
expect I start thrashing virtual memory PDQ.

It seems to me that something like this gather operation would do the
trick, with one hell of a lot less memory thrashing, but I can't quite
fathom the idiom for generating an indexing sequence that says something
like "one over in the plus X direction at the same time as one over in the
negative Z direction" . I'm sure I'm missing something obvious, but I *am*
missing it.

Wisdom anyone? (Tim? :-)

	TIA,
		Frank Horowitz

--
Frank Horowitz                                      frank@ned.dem.csiro.au
Australian Geodynamics Cooperative Research Centre, and
CSIRO-Exploration & Mining, PO Box 437, Nedlands, WA 6009,       AUSTRALIA
Direct: +61 8 9284 8431;  FAX: +61 8 9389 1906; Reception: +61 8 9389 8421