Slice implementation bug

Tambet qtvali at gmail.com
Thu May 12 07:06:52 EDT 2011


Hello!

Let's say slice is multidimensional now - how to interpret it?

I excpect these to work:

   - m[0, 3] - get one element from matrix
   - m[0:2, 0:2] - get four elements from matrix, iterate over them (I have
   actually an rtree if it doesn't make sense to you)

But it won't, because if m[0, 3] returns something, then m[0:2, 0:2] cannot
yield anymore. Ofcourse I could return an iterator, but this would not be so
simple.

So, maybe we need these:

   - __isslice__(key) - return true, false
   - __getitem__(key) - return a value
   - __getslice__(key) - yield a lots of values

So that if isslice returns true, getslice will be called. Would be much more
beauty! Right now it's ugly. I love Python, but I also love n-dimensional
spaces and those are ugly in Python - last time I did Matrix multiplication
I could not implement m[0, 3] (stupid errors), could not m[0j + 3], could
not use tuple. Now I was happy that it's implemented and just ran into
another problem that I have to choose, if getter returns one or many :)
Ofcourse I could return list or other iterable, but I want to be able to do
it with three-liner, because the rest of my code mostly consists of those.
Except the few masterfunctions, which do some complex manipulations with
data.

I also need to implement things like that, which also return true for
__isslice__:
m[Circle(0, 0, 10)] - for RTree, any shape object implementing getExtent and
doesOverlap can be used as slice index.

Because I do complex map transformations and all this trivial stuff must be
*hidden*!

Tambet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110512/7b600a8f/attachment.html>


More information about the Python-list mailing list