[MATRIX-SIG] reverse of take?
Andrew P. Mullhaupt
Fri, 27 Jun 1997 20:20:53 -0400
At 11:18 AM 6/27/97 +0200, Konrad Hinsen wrote:
>> existing method, it's better to use that syntax. I think you can get this
>> pretty easily with __setitem__ or __setslice__, so the syntax shouldn't
>> really be an issue.
>Indeed. A single subscript of any type is passed to __getitem__:
> x[[1, 3, 5]] --> x.__getitem__([1, 3, 5])
>Several subscripts are passed as a tuple:
> x[[1, 3, 5], [3, 2, 5]] --> x.__getitem__(([1, 3, 5], [3, 2, 5]))
>Of course __setitem__ works in the same way. For C types it's a bit
>more complicated since integers are passed via the sequence interface
>whereas everything else gets passed via the mapping interface, but
>it's not a real problem either.
Yes. It looks pretty good. The questions that spring to mind are related
to problems which might arise in implementing a python class which gives
S vector and data.frame functionality. You can provide a vector in S with
a vector of character strings and then use the strings to index the original
vector. Higher dimensional S arrays inherit this property. The cool thing
about S data.frame objects is that they inherit from both S arrays and S
lists, (S lists being pretty much like python dictionaries with the column
names being the keys and the columns being the values). It is a surprisingly
cool object to have around, and so it is something you would want in python.
The reservations about expanding python indexing are related to how much of
this picture can be achieved with various choices for python indexing.
>So the difficult part is not syntax, but implementing the indexing
>operations in a general and efficient way.
That's not really the hard part at all, since it's been done to death in the
APL family of languages. See, for example, Budd's book _An APL Compiler_ for
a taste of what's possible. If you really want to get out the hammer and
you can actually implement indexing well enough to beat all but impractically
complicated compiled code - the interpreter gives you a very nice way of
memory bandwidth strategies which are too difficult for general application in
C or Fortran. This is one of the opportunities for interpreters to be
some well written compiled code, although this doesn't seem to be generally
appreciated outside the post-APL community.
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: email@example.com
administrivia to: firstname.lastname@example.org