diff options
| author | Travis Oliphant <oliphant@enthought.com> | 2006-01-26 21:42:01 +0000 |
|---|---|---|
| committer | Travis Oliphant <oliphant@enthought.com> | 2006-01-26 21:42:01 +0000 |
| commit | f6d28d03b06dd15c9523a84047d6bec8b987b2d9 (patch) | |
| tree | 5b7f9f2354773006b16d39351829d63d94a3b7c5 /numpy/core/src/arrayobject.c | |
| parent | 5da0b20fd90045f35b2b76e3ddff4f1c6c48908a (diff) | |
| download | numpy-f6d28d03b06dd15c9523a84047d6bec8b987b2d9.tar.gz | |
Simplify the ndenumerate class by exposing coords and index from flat iterator. Simple cosmetic changes to ffts.
Diffstat (limited to 'numpy/core/src/arrayobject.c')
| -rw-r--r-- | numpy/core/src/arrayobject.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 033eef26d..0cc35efc6 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -7017,9 +7017,36 @@ static PyMethodDef iter_methods[] = { static PyMemberDef iter_members[] = { {"base", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL}, + {"index", T_INT, offsetof(PyArrayIterObject, index), RO, NULL}, {NULL}, }; +static PyObject * +iter_coords_get(PyArrayIterObject *self) +{ + int nd; + nd = self->ao->nd; + if (self->contiguous) { /* coordinates not kept track of --- need to generate + from index */ + intp val; + int i; + val = self->index; + for (i=0;i<nd; i++) { + self->coordinates[i] = val / self->factors[i]; + val = val % self->factors[i]; + } + } + return PyArray_IntTupleFromIntp(nd, self->coordinates); +} + +static PyGetSetDef iter_getsets[] = { + {"coords", + (getter)iter_coords_get, + NULL, + "An N-d tuple of current coordinates."}, + {NULL, NULL, NULL, NULL}, +}; + static PyTypeObject PyArrayIter_Type = { PyObject_HEAD_INIT(NULL) 0, /* ob_size */ @@ -7052,7 +7079,7 @@ static PyTypeObject PyArrayIter_Type = { (iternextfunc)arrayiter_next, /* tp_iternext */ iter_methods, /* tp_methods */ iter_members, /* tp_members */ - 0, /* tp_getset */ + iter_getsets, /* tp_getset */ }; |
