[MATRIX-SIG] Change slice object?

Janko Hauser jhauser@ifm.uni-kiel.de
Tue, 18 Nov 1997 00:15:14 +0100 (CET)


Currently I use the slide objects very often to map between different
grids. It's not very elegant to deal with the difference of
__getitem__ and __getsclice__. I must always test for an integer in
the slice expression

sl_tuple = (slice(12,13,None),4)

Is it possible to change the slice object in following way. Whould this
break code?

a=reshape(arange(18),(6,3))

a[0,:] => (slice(0,1,None),slice(None,None,1))
a[0:1,:] => (slice(0,1,1),slice(None,None,1))
a[0:2,:] => (slice(0,2,1),slice(None,None,1))

Currently slice(start,stop,None) is the same as slice(start,stop,1).

This would make it probably more clear why a dimension is preserved if
I use a step of 1 and dropped if I use a step of length None.

Also then there is no need for __getitem__ if one uses indexing. But I
think the method is needed for the for-loop construct, right?

But in every function which deals with slicing, one can be shure to
get only a tuple of slice objects.

I don't see, how big the impact of this change would be to the other
sequence objects in python.

One other idea. What's the way to have a __cmp__ method for slice
objects to test if a slice is completly in another slice or
overlapping at both or only one end.

== slices are equal
>= slice_a is overlapping only at the upper bound and greater or equal
at lower bound
<= slice_a is overlapping only at the lower bound and smaller or equal
at upper bound
< slice_a is completly in slice_b
> slice_a is overlapping at both ends

I think I try first with a shadow_class to implement this :-)
But are there some ideas?

__Janko



_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________