[Numpy-discussion] need inverse of PyArray_ITER_GOTO1D
Neal Becker
ndbecker2 at gmail.com
Tue Jan 1 21:49:08 EST 2008
I need a function that is the inverse of PyArray_ITER_GOTO1D. A bit of
guesswork brought me to this, can anyone please tell me if it looks
correct?
inline npy_intp as_linear (PyArrayIterObject const* it) {
if (it->nd_m1 == 0)
return (it->dataptr - it->ao->data)/it->strides[0];
else if (it->contiguous)
return (it->dataptr - it->ao->data)/it->ao->descr->elsize;
else {
npy_intp loc = 0;
npy_intp offset = (it->dataptr - it->ao->data)/it->ao->descr->elsize;
for (int i = 0; i <= it->nd_m1; ++i) {
loc += offset / it->factors[i];
offset %= it->factors[i];
}
return loc;
}
}
More information about the NumPy-Discussion
mailing list