[MATRIX-SIG] Seg fault with slice
Janko Hauser
jhauser@ifm.uni-kiel.de
Mon, 24 Nov 1997 12:44:03 +0100 (CET)
In the attempt to make the nslice object more like a slice I tried a
similar approach like Konrad Hinsen in his indexing.py but get a
seg. fault if len returns sys.maxint. This happens only on Linux not on
an alpha box. There the error is:
[0 1 2]
Traceback (innermost last):
File "nslice.py", line 46, in ?
main()
File "nslice.py", line 23, in main
print a[n_sl]
ValueError: __len__() should return >= 0
Wich I also don't understand, because maxint is clearly greater than
zero.
But this happens on Linux with python1.4 and 1.5a.
Any ideas? seg faults are real show stopper in python.
__Janko
#!/usr/local/bin/python
import Numeric
import sys
N=Numeric
maxint = sys.maxint
def test():
a = N.arange(12)
sl = slice(0,3,None)
n_sl = nslice(sl)
print a[sl]
print a[n_sl]
return
class nslice:
def __init__(self, index, shape=None):
self.index = index
self.maxint = maxint
return
def __getslice__(self):
start = self.index.start
stop = self.index.stop
step = None
return self[start:stop:step]
def __len__(self):
return self.maxint # No seg fault if I return 0
if __name__ == "__main__":
test()
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________