[Numpy-discussion] need inverse of PyArray_ITER_GOTO1D
Neal Becker
ndbecker2@gmail....
Wed Jan 2 07:45:48 CST 2008
Neal Becker wrote:
> 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;
> }
> }
That didn't work for negative strides. Actually, I think all I need is this:
inline npy_intp as_linear (PyArrayIterObject const* it) {
return it->index;
}
Is this correct?
More information about the Numpy-discussion
mailing list