提交 d4feee66 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Fix indexing by slice with python2.4

Also add (disabled by default) debug printing statements.
上级 790c2a77
......@@ -1756,7 +1756,17 @@ class GpuSubtensor(tensor.Subtensor, GpuOp):
def convert(entry):
if isinstance(entry, Type):
return indices.pop()
rval = indices.pop()
if sys.version_info < (2, 5):
# Before Python 2.5, PySlice_GetIndicesEx requires
# Python int to be passed.
rval_ = int(rval)
if rval_ != rval:
raise IndexError((
"Invalid value for indexing: %s. "
"That value may be too big.") % rval)
return rval_
return rval
elif isinstance(entry, slice):
return slice(convert(entry.start),
convert(entry.stop),
......
......@@ -1521,6 +1521,7 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
}
if (PySlice_Check(key)) //INDEXING BY SLICE
{
if (verbose) fprintf(stderr, "by slice\n");
if (self->nd == 0)
{
PyErr_SetString(PyExc_ValueError, "cannot slice a 0-d array");
......@@ -1531,6 +1532,8 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
Py_ssize_t start, stop, step, slen;
if (PySlice_GetIndicesEx((PySliceObject*)key, d_dim, &start, &stop, &step, &slen))
{
if (verbose)
fprintf(stderr, "PySlice_GetIndicesEx failed\n");
return NULL;
}
if (verbose)
......@@ -1569,6 +1572,7 @@ CudaNdarray_Subscript(PyObject * py_self, PyObject * key)
}
if (PyTuple_Check(key)) //INDEXING BY TUPLE
{
if (verbose) fprintf(stderr, "by tuple\n");
//elements of the tuple can be either integers or slices
//the dimensionality of the view we will return is diminished for each slice in the tuple
......
......@@ -4126,7 +4126,17 @@ class IncSubtensor(Op):
def convert(entry):
if isinstance(entry, gof.Type):
return indices.pop()
rval = indices.pop()
if sys.version_info < (2, 5):
# Before Python 2.5, PySlice_GetIndicesEx requires
# Python int to be passed.
rval_ = int(rval)
if rval_ != rval:
raise IndexError((
"Invalid value for indexing: %s. "
"That value may be too big.") % rval)
return rval_
return rval
elif isinstance(entry, slice):
return slice(convert(entry.start),
convert(entry.stop),
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论